mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -04:00
Use AsId everywhere
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
use std::fmt::Debug;
|
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
use crate::{
|
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,
|
TextWrapMode, Ui, UiBuilder, UiKind, UiStackInfo, Vec2, WidgetInfo, WidgetText, WidgetType,
|
||||||
emath, epaint, pos2, remap, remap_clamp, vec2,
|
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.
|
/// 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.
|
/// This is useful if the title label is dynamic or not unique.
|
||||||
#[inline]
|
#[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.id_salt = Id::new(id_salt);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -456,7 +453,7 @@ impl CollapsingHeader {
|
|||||||
/// This is useful if the title label is dynamic or not unique.
|
/// This is useful if the title label is dynamic or not unique.
|
||||||
#[deprecated = "Renamed id_salt"]
|
#[deprecated = "Renamed id_salt"]
|
||||||
#[inline]
|
#[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.id_salt = Id::new(id_salt);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use epaint::Shape;
|
use epaint::Shape;
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Align2, Context, Id, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior, Rect,
|
Align2, AsId, Context, Id, InnerResponse, NumExt as _, Painter, Popup, PopupCloseBehavior,
|
||||||
Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, Vec2, WidgetInfo,
|
Rect, Response, ScrollArea, Sense, Stroke, TextStyle, TextWrapMode, Ui, UiBuilder, Vec2,
|
||||||
WidgetText, WidgetType, epaint, style::StyleModifier, style::WidgetVisuals, vec2,
|
WidgetInfo, WidgetText, WidgetType, epaint, style::StyleModifier, style::WidgetVisuals, vec2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[expect(unused_imports)] // Documentation
|
#[expect(unused_imports)] // Documentation
|
||||||
@@ -50,7 +49,7 @@ pub struct ComboBox {
|
|||||||
|
|
||||||
impl ComboBox {
|
impl ComboBox {
|
||||||
/// Create new [`ComboBox`] with id and label
|
/// 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 {
|
Self {
|
||||||
id_salt: Id::new(id_salt),
|
id_salt: Id::new(id_salt),
|
||||||
label: Some(label.into()),
|
label: Some(label.into()),
|
||||||
@@ -81,7 +80,7 @@ impl ComboBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Without label.
|
/// 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 {
|
Self {
|
||||||
id_salt: Id::new(id_salt),
|
id_salt: Id::new(id_salt),
|
||||||
label: Default::default(),
|
label: Default::default(),
|
||||||
@@ -97,7 +96,7 @@ impl ComboBox {
|
|||||||
|
|
||||||
/// Without label.
|
/// Without label.
|
||||||
#[deprecated = "Renamed from_id_salt"]
|
#[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)
|
Self::from_id_salt(id_salt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use crate::{
|
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,
|
UiBuilder, UiKind, UiStackInfo, Vec2, Vec2b, pos2, vec2,
|
||||||
};
|
};
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[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)`.
|
/// A source for the unique [`Id`], e.g. `.id_source("second_resize_area")` or `.id_source(loop_index)`.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[deprecated = "Renamed id_salt"]
|
#[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)
|
self.id_salt(id_salt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A source for the unique [`Id`], e.g. `.id_salt("second_resize_area")` or `.id_salt(loop_index)`.
|
/// A source for the unique [`Id`], e.g. `.id_salt("second_resize_area")` or `.id_salt(loop_index)`.
|
||||||
#[inline]
|
#[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.id_salt = Some(Id::new(id_salt));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use emath::GuiRounding as _;
|
use emath::GuiRounding as _;
|
||||||
use std::fmt::Debug;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Align2, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style, Ui,
|
Align2, AsId, Color32, Context, Id, InnerResponse, NumExt as _, Painter, Rect, Region, Style,
|
||||||
UiBuilder, Vec2, vec2,
|
Ui, UiBuilder, Vec2, vec2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@@ -325,7 +324,7 @@ pub struct Grid {
|
|||||||
|
|
||||||
impl Grid {
|
impl Grid {
|
||||||
/// Create a new [`Grid`] with a locally unique identifier.
|
/// 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 {
|
Self {
|
||||||
id_salt: Id::new(id_salt),
|
id_salt: Id::new(id_salt),
|
||||||
num_columns: None,
|
num_columns: None,
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#![warn(missing_docs)] // Let's keep `Ui` well-documented.
|
#![warn(missing_docs)] // Let's keep `Ui` well-documented.
|
||||||
#![expect(clippy::use_self)]
|
#![expect(clippy::use_self)]
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::{any::Any, ops::Deref, sync::Arc};
|
||||||
use std::{any::Any, hash::Hash, ops::Deref, sync::Arc};
|
|
||||||
|
|
||||||
use emath::GuiRounding as _;
|
use emath::GuiRounding as _;
|
||||||
use epaint::mutex::RwLock;
|
use epaint::mutex::RwLock;
|
||||||
@@ -229,7 +228,7 @@ impl Ui {
|
|||||||
&mut self,
|
&mut self,
|
||||||
max_rect: Rect,
|
max_rect: Rect,
|
||||||
layout: Layout,
|
layout: Layout,
|
||||||
id_salt: impl Hash + Debug,
|
id_salt: impl AsId,
|
||||||
ui_stack_info: Option<UiStackInfo>,
|
ui_stack_info: Option<UiStackInfo>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.new_child(
|
self.new_child(
|
||||||
@@ -1002,7 +1001,7 @@ impl Ui {
|
|||||||
/// Use this to generate widget ids for widgets that have persistent state in [`Memory`].
|
/// 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
|
pub fn make_persistent_id<IdSource>(&self, id_salt: IdSource) -> Id
|
||||||
where
|
where
|
||||||
IdSource: Hash + Debug,
|
IdSource: AsId,
|
||||||
{
|
{
|
||||||
self.id.with(&id_salt)
|
self.id.with(&id_salt)
|
||||||
}
|
}
|
||||||
@@ -1015,7 +1014,7 @@ impl Ui {
|
|||||||
/// Same as `ui.next_auto_id().with(id_salt)`
|
/// Same as `ui.next_auto_id().with(id_salt)`
|
||||||
pub fn auto_id_with<IdSource>(&self, id_salt: IdSource) -> Id
|
pub fn auto_id_with<IdSource>(&self, id_salt: IdSource) -> Id
|
||||||
where
|
where
|
||||||
IdSource: Hash + Debug,
|
IdSource: AsId,
|
||||||
{
|
{
|
||||||
Id::new(self.next_auto_id_salt).with(id_salt)
|
Id::new(self.next_auto_id_salt).with(id_salt)
|
||||||
}
|
}
|
||||||
@@ -2368,7 +2367,7 @@ impl Ui {
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn push_id<R>(
|
pub fn push_id<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
id_salt: impl Hash + Debug,
|
id_salt: impl AsId,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.scope_dyn(UiBuilder::new().id_salt(id_salt), Box::new(add_contents))
|
self.scope_dyn(UiBuilder::new().id_salt(id_salt), Box::new(add_contents))
|
||||||
@@ -2468,7 +2467,7 @@ impl Ui {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn indent<R>(
|
pub fn indent<R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
id_salt: impl Hash + Debug,
|
id_salt: impl AsId,
|
||||||
add_contents: impl FnOnce(&mut Ui) -> R,
|
add_contents: impl FnOnce(&mut Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
self.indent_dyn(id_salt, Box::new(add_contents))
|
self.indent_dyn(id_salt, Box::new(add_contents))
|
||||||
@@ -2476,7 +2475,7 @@ impl Ui {
|
|||||||
|
|
||||||
fn indent_dyn<'c, R>(
|
fn indent_dyn<'c, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
id_salt: impl Hash + Debug,
|
id_salt: impl AsId,
|
||||||
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
add_contents: Box<dyn FnOnce(&mut Ui) -> R + 'c>,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use std::fmt::Debug;
|
use std::sync::Arc;
|
||||||
use std::{hash::Hash, sync::Arc};
|
|
||||||
|
|
||||||
use crate::ClosableTag;
|
use crate::ClosableTag;
|
||||||
#[expect(unused_imports)] // Used for doclinks
|
#[expect(unused_imports)] // Used for doclinks
|
||||||
use crate::Ui;
|
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`].
|
/// 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
|
/// You should give each [`Ui`] an `id_salt` that is unique
|
||||||
/// within the parent, or give it none at all.
|
/// within the parent, or give it none at all.
|
||||||
#[inline]
|
#[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.id_salt = Some(Id::new(id_salt));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -55,7 +54,7 @@ impl UiBuilder {
|
|||||||
///
|
///
|
||||||
/// This is a shortcut for `.id_salt(my_id).global_scope(true)`.
|
/// This is a shortcut for `.id_salt(my_id).global_scope(true)`.
|
||||||
#[inline]
|
#[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.id_salt = Some(id);
|
||||||
self.global_scope = true;
|
self.global_scope = true;
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user