1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Allow customizing id

This commit is contained in:
lucasmerlin
2025-04-17 00:41:11 +02:00
parent d468565e56
commit d6c813e9ba
2 changed files with 15 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ impl SizedAtomicKind<'_> {
/// AtomicLayout /// AtomicLayout
pub struct WidgetLayout<'a> { pub struct WidgetLayout<'a> {
id: Option<Id>,
pub atomics: Atomics<'a>, pub atomics: Atomics<'a>,
gap: Option<f32>, gap: Option<f32>,
pub(crate) frame: Frame, pub(crate) frame: Frame,
@@ -37,6 +38,7 @@ pub struct WidgetLayout<'a> {
impl<'a> WidgetLayout<'a> { impl<'a> WidgetLayout<'a> {
pub fn new(atomics: impl IntoAtomics<'a>) -> Self { pub fn new(atomics: impl IntoAtomics<'a>) -> Self {
Self { Self {
id: None,
atomics: atomics.into_atomics(), atomics: atomics.into_atomics(),
gap: None, gap: None,
frame: Frame::default(), frame: Frame::default(),
@@ -77,8 +79,14 @@ impl<'a> WidgetLayout<'a> {
self self
} }
pub fn id(mut self, id: Id) -> Self {
self.id = Some(id);
self
}
pub fn show(self, ui: &mut Ui) -> AtomicLayoutResponse { pub fn show(self, ui: &mut Ui) -> AtomicLayoutResponse {
let Self { let Self {
id,
atomics, atomics,
gap, gap,
frame, frame,
@@ -87,6 +95,8 @@ impl<'a> WidgetLayout<'a> {
min_size, min_size,
} = self; } = self;
let id = id.unwrap_or_else(|| ui.next_auto_id());
let fallback_text_color = self let fallback_text_color = self
.fallback_text_color .fallback_text_color
.unwrap_or_else(|| ui.style().visuals.text_color()); .unwrap_or_else(|| ui.style().visuals.text_color());
@@ -178,7 +188,8 @@ impl<'a> WidgetLayout<'a> {
let content_size = Vec2::new(desired_width, height); let content_size = Vec2::new(desired_width, height);
let frame_size = (content_size + margin.sum()).at_least(min_size); let frame_size = (content_size + margin.sum()).at_least(min_size);
let (rect, response) = ui.allocate_at_least(frame_size, sense); let (_, rect) = ui.allocate_space(frame_size);
let response = ui.interact(rect, id, sense);
let mut response = AtomicLayoutResponse { let mut response = AtomicLayoutResponse {
response, response,

View File

@@ -259,7 +259,9 @@ impl<'a> Button<'a> {
} }
} }
let response = ui.ctx().read_response(ui.next_auto_id()); let id = ui.next_auto_id().with("egui::button");
wl = wl.id(id);
let response = ui.ctx().read_response(id);
let visuals = response.map_or(&ui.style().visuals.widgets.inactive, |response| { let visuals = response.map_or(&ui.style().visuals.widgets.inactive, |response| {
ui.style().interact(&response) ui.style().interact(&response)