1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Use AsId everywhere

This commit is contained in:
lucasmerlin
2026-03-18 16:03:12 +01:00
parent 2418712915
commit bbf5e2d728
6 changed files with 26 additions and 34 deletions

View File

@@ -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
}

View File

@@ -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<WidgetText>) -> Self {
pub fn new(id_salt: impl AsId, label: impl Into<WidgetText>) -> 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)
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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<UiStackInfo>,
) -> 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<IdSource>(&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<IdSource>(&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<R>(
&mut self,
id_salt: impl Hash + Debug,
id_salt: impl AsId,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
self.scope_dyn(UiBuilder::new().id_salt(id_salt), Box::new(add_contents))
@@ -2468,7 +2467,7 @@ impl Ui {
#[inline]
pub fn indent<R>(
&mut self,
id_salt: impl Hash + Debug,
id_salt: impl AsId,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
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<dyn FnOnce(&mut Ui) -> R + 'c>,
) -> InnerResponse<R> {
assert!(

View File

@@ -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