From bbf5e2d7287c40b6c834143c07ddaa318a450cc7 Mon Sep 17 00:00:00 2001 From: lucasmerlin Date: Wed, 18 Mar 2026 16:03:12 +0100 Subject: [PATCH] Use AsId everywhere --- crates/egui/src/containers/collapsing_header.rs | 9 +++------ crates/egui/src/containers/combo_box.rs | 13 ++++++------- crates/egui/src/containers/resize.rs | 7 +++---- crates/egui/src/grid.rs | 7 +++---- crates/egui/src/ui.rs | 15 +++++++-------- crates/egui/src/ui_builder.rs | 9 ++++----- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/crates/egui/src/containers/collapsing_header.rs b/crates/egui/src/containers/collapsing_header.rs index e50bd68e4..22df2ed04 100644 --- a/crates/egui/src/containers/collapsing_header.rs +++ b/crates/egui/src/containers/collapsing_header.rs @@ -1,8 +1,5 @@ -use std::fmt::Debug; -use std::hash::Hash; - use crate::{ - Context, Id, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle, + AsId, Context, Id, InnerResponse, NumExt as _, Rect, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, WidgetInfo, WidgetText, WidgetType, emath, epaint, pos2, remap, remap_clamp, vec2, }; @@ -447,7 +444,7 @@ impl CollapsingHeader { /// Explicitly set the source of the [`Id`] of this widget, instead of using title label. /// This is useful if the title label is dynamic or not unique. #[inline] - pub fn id_salt(mut self, id_salt: impl Hash + Debug) -> Self { + pub fn id_salt(mut self, id_salt: impl AsId) -> Self { self.id_salt = Id::new(id_salt); self } @@ -456,7 +453,7 @@ impl CollapsingHeader { /// This is useful if the title label is dynamic or not unique. #[deprecated = "Renamed id_salt"] #[inline] - pub fn id_source(mut self, id_salt: impl Hash + Debug) -> Self { + pub fn id_source(mut self, id_salt: impl AsId) -> Self { self.id_salt = Id::new(id_salt); self } diff --git a/crates/egui/src/containers/combo_box.rs b/crates/egui/src/containers/combo_box.rs index f37210adb..260c8e927 100644 --- a/crates/egui/src/containers/combo_box.rs +++ b/crates/egui/src/containers/combo_box.rs @@ -1,10 +1,9 @@ use epaint::Shape; -use std::fmt::Debug; use crate::{ - Align2, Context, Id, 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, + Align2, AsId, Context, Id, 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, }; #[expect(unused_imports)] // Documentation @@ -50,7 +49,7 @@ pub struct ComboBox { impl ComboBox { /// Create new [`ComboBox`] with id and label - pub fn new(id_salt: impl std::hash::Hash + Debug, label: impl Into) -> Self { + pub fn new(id_salt: impl AsId, label: impl Into) -> Self { Self { id_salt: Id::new(id_salt), label: Some(label.into()), @@ -81,7 +80,7 @@ impl ComboBox { } /// Without label. - pub fn from_id_salt(id_salt: impl std::hash::Hash + Debug) -> Self { + pub fn from_id_salt(id_salt: impl AsId) -> Self { Self { id_salt: Id::new(id_salt), label: Default::default(), @@ -97,7 +96,7 @@ impl ComboBox { /// Without label. #[deprecated = "Renamed from_id_salt"] - pub fn from_id_source(id_salt: impl std::hash::Hash + Debug) -> Self { + pub fn from_id_source(id_salt: impl AsId) -> Self { Self::from_id_salt(id_salt) } diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 7c5e3b33c..79c710af5 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -1,8 +1,7 @@ use crate::{ - Align2, Color32, Context, CursorIcon, Id, NumExt as _, Rect, Response, Sense, Shape, Ui, + Align2, AsId, Color32, Context, CursorIcon, Id, NumExt as _, Rect, Response, Sense, Shape, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2, }; -use std::fmt::Debug; #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] @@ -73,13 +72,13 @@ impl Resize { /// A source for the unique [`Id`], e.g. `.id_source("second_resize_area")` or `.id_source(loop_index)`. #[inline] #[deprecated = "Renamed id_salt"] - pub fn id_source(self, id_salt: impl std::hash::Hash + Debug) -> Self { + pub fn id_source(self, id_salt: impl AsId) -> Self { self.id_salt(id_salt) } /// 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 std::hash::Hash + Debug) -> Self { + pub fn id_salt(mut self, id_salt: impl AsId) -> Self { self.id_salt = Some(Id::new(id_salt)); self } diff --git a/crates/egui/src/grid.rs b/crates/egui/src/grid.rs index f1cf20e79..e815a7efb 100644 --- a/crates/egui/src/grid.rs +++ b/crates/egui/src/grid.rs @@ -1,11 +1,10 @@ use std::sync::Arc; use emath::GuiRounding as _; -use std::fmt::Debug; use crate::{ - Align2, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui, - UiBuilder, Vec2, vec2, + Align2, AsId, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style, + Ui, UiBuilder, Vec2, vec2, }; #[cfg(debug_assertions)] @@ -325,7 +324,7 @@ pub struct Grid { impl Grid { /// Create a new [`Grid`] with a locally unique identifier. - pub fn new(id_salt: impl std::hash::Hash + Debug) -> Self { + pub fn new(id_salt: impl AsId) -> Self { Self { id_salt: Id::new(id_salt), num_columns: None, diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 42cc5c949..8ff59350d 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1,8 +1,7 @@ #![warn(missing_docs)] // Let's keep `Ui` well-documented. #![expect(clippy::use_self)] -use std::fmt::Debug; -use std::{any::Any, hash::Hash, ops::Deref, sync::Arc}; +use std::{any::Any, ops::Deref, sync::Arc}; use emath::GuiRounding as _; use epaint::mutex::RwLock; @@ -229,7 +228,7 @@ impl Ui { &mut self, max_rect: Rect, layout: Layout, - id_salt: impl Hash + Debug, + id_salt: impl AsId, ui_stack_info: Option, ) -> Self { self.new_child( @@ -1002,7 +1001,7 @@ impl Ui { /// Use this to generate widget ids for widgets that have persistent state in [`Memory`]. pub fn make_persistent_id(&self, id_salt: IdSource) -> Id where - IdSource: Hash + Debug, + IdSource: AsId, { self.id.with(&id_salt) } @@ -1015,7 +1014,7 @@ impl Ui { /// Same as `ui.next_auto_id().with(id_salt)` pub fn auto_id_with(&self, id_salt: IdSource) -> Id where - IdSource: Hash + Debug, + IdSource: AsId, { Id::new(self.next_auto_id_salt).with(id_salt) } @@ -2368,7 +2367,7 @@ impl Ui { /// ``` pub fn push_id( &mut self, - id_salt: impl Hash + Debug, + id_salt: impl AsId, add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse { self.scope_dyn(UiBuilder::new().id_salt(id_salt), Box::new(add_contents)) @@ -2468,7 +2467,7 @@ impl Ui { #[inline] pub fn indent( &mut self, - id_salt: impl Hash + Debug, + id_salt: impl AsId, add_contents: impl FnOnce(&mut Ui) -> R, ) -> InnerResponse { self.indent_dyn(id_salt, Box::new(add_contents)) @@ -2476,7 +2475,7 @@ impl Ui { fn indent_dyn<'c, R>( &mut self, - id_salt: impl Hash + Debug, + id_salt: impl AsId, add_contents: Box R + 'c>, ) -> InnerResponse { assert!( diff --git a/crates/egui/src/ui_builder.rs b/crates/egui/src/ui_builder.rs index 9b4e32ecc..b448b722c 100644 --- a/crates/egui/src/ui_builder.rs +++ b/crates/egui/src/ui_builder.rs @@ -1,10 +1,9 @@ -use std::fmt::Debug; -use std::{hash::Hash, sync::Arc}; +use std::sync::Arc; use crate::ClosableTag; #[expect(unused_imports)] // Used for doclinks use crate::Ui; -use crate::{Id, LayerId, Layout, Rect, Sense, Style, UiStackInfo}; +use crate::{AsId, Id, LayerId, Layout, Rect, Sense, Style, UiStackInfo}; /// Build a [`Ui`] as the child of another [`Ui`]. /// @@ -40,7 +39,7 @@ impl UiBuilder { /// You should give each [`Ui`] an `id_salt` that is unique /// within the parent, or give it none at all. #[inline] - pub fn id_salt(mut self, id_salt: impl Hash + Debug) -> Self { + pub fn id_salt(mut self, id_salt: impl AsId) -> Self { self.id_salt = Some(Id::new(id_salt)); self } @@ -55,7 +54,7 @@ impl UiBuilder { /// /// This is a shortcut for `.id_salt(my_id).global_scope(true)`. #[inline] - pub fn id(mut self, id: impl Hash + Debug) -> Self { + pub fn id(mut self, id: Id) -> Self { self.id_salt = Some(id); self.global_scope = true; self