From 0953c8c28575527b1825e6a5a2c0afca3dab90ea Mon Sep 17 00:00:00 2001 From: lucasmerlin Date: Tue, 24 Mar 2026 14:10:06 +0100 Subject: [PATCH] Use IdSalt everywhere --- crates/egui/src/containers/collapsing_header.rs | 10 +++++----- crates/egui/src/containers/combo_box.rs | 10 +++++----- crates/egui/src/containers/resize.rs | 10 +++++----- crates/egui/src/containers/scroll_area.rs | 8 ++++---- crates/egui/src/grid.rs | 6 +++--- crates/egui/src/id.rs | 2 +- crates/egui/src/ui.rs | 4 ++-- crates/egui/src/ui_builder.rs | 6 +++--- crates/egui/src/widgets/text_edit/builder.rs | 7 ++++--- crates/egui_demo_app/src/accessibility_inspector.rs | 4 ++-- crates/egui_extras/src/layout.rs | 6 +++--- crates/egui_extras/src/strip.rs | 2 +- crates/egui_extras/src/table.rs | 10 +++++----- 13 files changed, 43 insertions(+), 42 deletions(-) diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index 794a8c820..27f70c810 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -1,5 +1,5 @@ use crate::{ - Context, Id, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle, + Context, Id, IdSalt, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, WidgetInfo, WidgetText, WidgetType, emath, epaint, pos2, remap, remap_clamp, vec2, }; @@ -391,7 +391,7 @@ pub struct CollapsingHeader { text: WidgetText, default_open: bool, open: Option, - id_salt: Id, + id_salt: IdSalt, enabled: bool, selectable: bool, selected: bool, @@ -408,7 +408,7 @@ impl CollapsingHeader { /// you need to provide a unique id source with [`Self::id_salt`]. pub fn new(text: impl Into) -> Self { let text = text.into(); - let id_salt = Id::new_salt(text.text()); + let id_salt = IdSalt::new(text.text()); Self { text, default_open: false, @@ -445,7 +445,7 @@ impl CollapsingHeader { /// This is useful if the title label is dynamic or not unique. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = id_salt.into().id(); + self.id_salt = id_salt.into(); self } @@ -454,7 +454,7 @@ impl CollapsingHeader { #[deprecated = "Renamed id_salt"] #[inline] pub fn id_source(mut self, id_salt: impl Into) -> Self { - self.id_salt = id_salt.into().id(); + self.id_salt = id_salt.into(); self } diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index fea639740..150661e02 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -1,7 +1,7 @@ use epaint::Shape; use crate::{ - Align2, Context, Id, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior, Rect, + Align2, Context, Id, IdSalt, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior, Rect, Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, Vec2, WidgetInfo, WidgetText, WidgetType, epaint, style::StyleModifier, style::WidgetVisuals, vec2, }; @@ -36,7 +36,7 @@ pub type IconPainter = Box; /// ``` #[must_use = "You should call .show*"] pub struct ComboBox { - id_salt: Id, + id_salt: IdSalt, label: Option, selected_text: WidgetText, width: Option, @@ -51,7 +51,7 @@ impl ComboBox { /// Create new [`ComboBox`] with id and label pub fn new(id_salt: impl Into, label: impl Into) -> Self { Self { - id_salt: id_salt.into().id(), + id_salt: id_salt.into(), label: Some(label.into()), selected_text: Default::default(), width: None, @@ -67,7 +67,7 @@ impl ComboBox { pub fn from_label(label: impl Into) -> Self { let label = label.into(); Self { - id_salt: Id::new_salt(label.text()), + id_salt: IdSalt::new(label.text()), label: Some(label), selected_text: Default::default(), width: None, @@ -82,7 +82,7 @@ impl ComboBox { /// Without label. pub fn from_id_salt(id_salt: impl Into) -> Self { Self { - id_salt: id_salt.into().id(), + id_salt: id_salt.into(), label: Default::default(), selected_text: Default::default(), width: None, diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 4311c05f0..858046382 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -1,6 +1,6 @@ use crate::{ - Align2, Color32, Context, CursorIcon, Id, NumExt as _, Rect, Response, Sense, Shape, Ui, - UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2, + Align2, Color32, Context, CursorIcon, Id, IdSalt, NumExt as _, Rect, Response, Sense, Shape, + Ui, UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2, }; #[derive(Clone, Copy, Debug)] @@ -34,7 +34,7 @@ impl State { #[must_use = "You should call .show()"] pub struct Resize { id: Option, - id_salt: Option, + id_salt: Option, /// If false, we are no enabled resizable: Vec2b, @@ -79,7 +79,7 @@ impl Resize { /// A source for the unique [`Id`], e.g. `.id_salt("second_resize_area")` or `.id_salt(loop_index)`. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = Some(id_salt.into().id()); + self.id_salt = Some(id_salt.into()); self } @@ -208,7 +208,7 @@ impl Resize { fn begin(&self, ui: &mut Ui) -> Prepared { let position = ui.available_rect_before_wrap().min; let id = self.id.unwrap_or_else(|| { - let id_salt = self.id_salt.unwrap_or_else(|| Id::new("resize")); + let id_salt = self.id_salt.unwrap_or_else(|| IdSalt::from("resize")); ui.make_persistent_id(id_salt) }); diff --git a/crates/egui/src/containers/scroll_area.rs b/crates/egui/src/containers/scroll_area.rs index e297b078a..2d15eb719 100644 --- a/crates/egui/src/containers/scroll_area.rs +++ b/crates/egui/src/containers/scroll_area.rs @@ -8,7 +8,7 @@ use emath::GuiRounding as _; use epaint::Margin; use crate::{ - Context, CursorIcon, Id, NumExt as _, Pos2, Rangef, Rect, Response, Sense, Ui, UiBuilder, + Context, CursorIcon, Id, IdSalt, NumExt as _, Pos2, Rangef, Rect, Response, Sense, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, WidgetInfo, emath, epaint, lerp, pass_state, pos2, remap, remap_clamp, }; @@ -290,7 +290,7 @@ pub struct ScrollArea { min_scrolled_size: Vec2, scroll_bar_visibility: ScrollBarVisibility, scroll_bar_rect: Option, - id_salt: Option, + id_salt: Option, offset_x: Option, offset_y: Option, on_hover_cursor: Option, @@ -433,7 +433,7 @@ impl ScrollArea { /// A source for the unique [`Id`], e.g. `.id_salt("second_scroll_area")` or `.id_salt(loop_index)`. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = Some(id_salt.into().id()); + self.id_salt = Some(id_salt.into()); self } @@ -709,7 +709,7 @@ impl ScrollArea { let ctx = ui.ctx().clone(); - let id_salt = id_salt.unwrap_or_else(|| Id::new("scroll_area")); + let id_salt = id_salt.unwrap_or_else(|| IdSalt::from("scroll_area")); let id = ui.make_persistent_id(id_salt); ctx.check_for_id_clash( id, diff --git a/crates/egui/src/grid.rs b/crates/egui/src/grid.rs index 63727295e..c9362992f 100644 --- a/crates/egui/src/grid.rs +++ b/crates/egui/src/grid.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use emath::GuiRounding as _; use crate::{ - Align2, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui, + Align2, Color32, Context, Id, IdSalt, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui, UiBuilder, Vec2, vec2, }; @@ -312,7 +312,7 @@ impl GridLayout { /// ``` #[must_use = "You should call .show()"] pub struct Grid { - id_salt: Id, + id_salt: IdSalt, num_columns: Option, min_col_width: Option, min_row_height: Option, @@ -326,7 +326,7 @@ impl Grid { /// Create a new [`Grid`] with a locally unique identifier. pub fn new(id_salt: impl Into) -> Self { Self { - id_salt: id_salt.into().id(), + id_salt: id_salt.into(), num_columns: None, min_col_width: None, min_row_height: None, diff --git a/crates/egui/src/id.rs b/crates/egui/src/id.rs index c71e0c507..f1efc2b96 100644 --- a/crates/egui/src/id.rs +++ b/crates/egui/src/id.rs @@ -171,7 +171,7 @@ fn test_id_new_rejects_id() { /// let id = Id::new("parent"); /// let salt: IdSalt = id.into(); /// ``` -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug, Hash)] pub struct IdSalt(Id); impl IdSalt { diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 738cf680b..f50280cb4 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -265,7 +265,7 @@ impl Ui { let mut painter = self.painter.clone(); - let id_salt = id_salt.unwrap_or_else(|| Id::from("child")); + let id_salt = id_salt.unwrap_or_else(|| IdSalt::from("child")); let max_rect = max_rect.unwrap_or_else(|| self.available_rect_before_wrap()); let mut layout = layout.unwrap_or_else(|| *self.layout()); let enabled = self.enabled && !disabled && !invisible; @@ -290,7 +290,7 @@ impl Ui { debug_assert!(!max_rect.any_nan(), "max_rect is NaN: {max_rect:?}"); let (stable_id, unique_id) = if global_scope { - (id_salt, id_salt) + (id_salt.id(), id_salt.id()) } else { let stable_id = self.id.with(id_salt); let unique_id = stable_id.with(self.next_auto_id_salt); diff --git a/crates/egui/src/ui_builder.rs b/crates/egui/src/ui_builder.rs index 9353feb1d..5828d4a8f 100644 --- a/crates/egui/src/ui_builder.rs +++ b/crates/egui/src/ui_builder.rs @@ -13,7 +13,7 @@ use crate::{Id, IdSalt, LayerId, Layout, Rect, Sense, Style, UiStackInfo}; #[must_use] #[derive(Clone, Default)] pub struct UiBuilder { - pub id_salt: Option, + pub id_salt: Option, pub global_scope: bool, pub ui_stack_info: UiStackInfo, pub layer_id: Option, @@ -40,7 +40,7 @@ impl UiBuilder { /// within the parent, or give it none at all. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = Some(id_salt.into().id()); + self.id_salt = Some(id_salt.into()); self } @@ -55,7 +55,7 @@ impl UiBuilder { /// This is a shortcut for `.id_salt(my_id).global_scope(true)`. #[inline] pub fn id(mut self, id: Id) -> Self { - self.id_salt = Some(id); + self.id_salt = Some(id.into()); self.global_scope = true; self } diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index 79e24f699..eee894a77 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/crates/egui/src/widgets/text_edit/builder.rs @@ -7,7 +7,8 @@ use epaint::{ }; use crate::{ - Align, Align2, Color32, Context, CursorIcon, Event, EventFilter, FontSelection, Id, ImeEvent, + Align, Align2, Color32, Context, CursorIcon, Event, EventFilter, FontSelection, Id, IdSalt, + ImeEvent, Key, KeyboardShortcut, Margin, Modifiers, NumExt as _, Response, Sense, Shape, TextBuffer, TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetWithState, epaint, os::OperatingSystem, @@ -70,7 +71,7 @@ pub struct TextEdit<'t> { hint_text: WidgetText, hint_text_font: Option, id: Option, - id_salt: Option, + id_salt: Option, font_selection: FontSelection, text_color: Option, layouter: Option>, @@ -175,7 +176,7 @@ impl<'t> TextEdit<'t> { /// A source for the unique [`Id`], e.g. `.id_salt("second_text_edit_field")` or `.id_salt(loop_index)`. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = Some(id_salt.into().id()); + self.id_salt = Some(id_salt.into()); self } diff --git a/crates/egui_demo_app/src/accessibility_inspector.rs b/crates/egui_demo_app/src/accessibility_inspector.rs index db34c85ac..ff91d3c02 100644 --- a/crates/egui_demo_app/src/accessibility_inspector.rs +++ b/crates/egui_demo_app/src/accessibility_inspector.rs @@ -5,7 +5,7 @@ use accesskit_consumer::{FilterResult, Node, NodeId, Tree, TreeChangeHandler}; use eframe::epaint::text::TextWrapMode; use egui::{ - Button, Color32, Event, Frame, FullOutput, Id, Key, KeyboardShortcut, Label, Modifiers, Panel, + Button, Color32, Event, Frame, FullOutput, Id, IdSalt, Key, KeyboardShortcut, Label, Modifiers, Panel, RawInput, RichText, ScrollArea, Ui, collapsing_header::CollapsingState, }; @@ -213,7 +213,7 @@ impl AccessibilityInspectorPlugin { #[expect(unsafe_code)] let egui_node_id = unsafe { Id::from_high_entropy_bits(node.locate().0.0) }; - ui.push_id(node.id(), |ui| { + ui.push_id(IdSalt::new(node.id()), |ui| { let child_count = node.children().len(); let has_children = child_count > 0; let default_open = child_count == 1 && node.role() != accesskit::Role::Label; diff --git a/crates/egui_extras/src/layout.rs b/crates/egui_extras/src/layout.rs index 594763daf..0d47969cd 100644 --- a/crates/egui_extras/src/layout.rs +++ b/crates/egui_extras/src/layout.rs @@ -1,4 +1,4 @@ -use egui::{Id, Pos2, Rect, Response, Sense, Ui, UiBuilder, emath::GuiRounding as _}; +use egui::{Pos2, Rect, Response, Sense, Ui, UiBuilder, emath::GuiRounding as _}; #[derive(Clone, Copy)] pub(crate) enum CellSize { @@ -117,7 +117,7 @@ impl<'l> StripLayout<'l> { flags: StripLayoutFlags, width: CellSize, height: CellSize, - child_ui_id_salt: Id, + child_ui_id_salt: egui::IdSalt, add_cell_contents: impl FnOnce(&mut Ui), ) -> (Rect, Response) { let max_rect = self.cell_rect(&width, &height); @@ -201,7 +201,7 @@ impl<'l> StripLayout<'l> { &mut self, flags: StripLayoutFlags, max_rect: Rect, - child_ui_id_salt: egui::Id, + child_ui_id_salt: egui::IdSalt, add_cell_contents: impl FnOnce(&mut Ui), ) -> Ui { let mut ui_builder = UiBuilder::new() diff --git a/crates/egui_extras/src/strip.rs b/crates/egui_extras/src/strip.rs index da64b4f9e..dc5f03c90 100644 --- a/crates/egui_extras/src/strip.rs +++ b/crates/egui_extras/src/strip.rs @@ -198,7 +198,7 @@ impl Strip<'_, '_> { flags, width, height, - egui::Id::new(self.size_index), + egui::IdSalt::new(self.size_index), add_contents, ); } diff --git a/crates/egui_extras/src/table.rs b/crates/egui_extras/src/table.rs index 0884dd87b..6d47e3e13 100644 --- a/crates/egui_extras/src/table.rs +++ b/crates/egui_extras/src/table.rs @@ -4,7 +4,7 @@ //! Takes all available height, so if you want something below the table, put it in a strip. use egui::{ - Align, Id, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b, + Align, NumExt as _, Rangef, Rect, Response, ScrollArea, Ui, Vec2, Vec2b, scroll_area::{ScrollAreaOutput, ScrollBarVisibility, ScrollSource}, }; @@ -246,7 +246,7 @@ impl Default for TableScrollOptions { /// ``` pub struct TableBuilder<'a> { ui: &'a mut Ui, - id_salt: Id, + id_salt: egui::IdSalt, columns: Vec, striped: Option, resizable: bool, @@ -260,7 +260,7 @@ impl<'a> TableBuilder<'a> { let cell_layout = *ui.layout(); Self { ui, - id_salt: Id::new("__table_state"), + id_salt: egui::IdSalt::from("__table_state"), columns: Default::default(), striped: None, resizable: false, @@ -284,7 +284,7 @@ impl<'a> TableBuilder<'a> { /// This is required if you have multiple tables in the same [`Ui`]. #[inline] pub fn id_salt(mut self, id_salt: impl Into) -> Self { - self.id_salt = id_salt.into().id(); + self.id_salt = id_salt.into(); self } @@ -1314,7 +1314,7 @@ impl TableRow<'_, '_> { flags, width, height, - egui::Id::new((self.row_index, col_index)), + egui::IdSalt::new((self.row_index, col_index)), add_cell_contents, );