pub struct Id(/* private fields */);Expand description
egui tracks widgets frame-to-frame using Ids.
For instance, if you start dragging a slider one frame, egui stores
the sliders Id as the current active id so that next frame when
you move the mouse the same slider changes, even if the mouse has
moved outside the slider.
For some widgets Ids are also used to persist some state about the
widgets, such as Window position or whether not a collapsing header region is open.
This implies that the Ids must be unique.
For simple things like sliders and buttons that don’t have any memory and doesn’t move we can use the location of the widget as a source of identity. For instance, a slider only needs a unique and persistent ID while you are dragging the slider. As long as it is still while moving, that is fine.
For things that need to persist state even after moving (windows, collapsing headers) the location of the widgets is obviously not good enough. For instance, a collapsing region needs to remember whether or not it is open even if the layout next frame is different and the collapsing is not lower down on the screen.
Then there are widgets that need no identifiers at all, like labels, because they have no state nor are interacted with.
This is niche-optimized to that Option<Id> is the same size as Id.
Implementations§
Source§impl Id
impl Id
Sourcepub const NULL: Self
pub const NULL: Self
A special Id, in particular as a key to crate::Memory::data
for when there is no particular widget to attach the data.
The null Id is still a valid id to use in all circumstances,
though obviously it will lead to a lot of collisions if you do use it!
Sourcepub fn new(source: impl Hash) -> Self
pub fn new(source: impl Hash) -> Self
Generate a new Id by hashing some source (e.g. a string or integer).
Sourcepub fn short_debug_format(&self) -> String
pub fn short_debug_format(&self) -> String
Short and readable summary
Sourcepub fn value(&self) -> u64
pub fn value(&self) -> u64
The inner value of the Id.
This is a high-entropy hash, or Self::NULL.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Id
impl<'de> Deserialize<'de> for Id
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<ViewportId> for Id
impl From<ViewportId> for Id
Source§fn from(id: ViewportId) -> Self
fn from(id: ViewportId) -> Self
impl Copy for Id
impl Eq for Id
impl IsEnabled for Id
impl StructuralPartialEq for Id
Auto Trait Implementations§
impl Freeze for Id
impl RefUnwindSafe for Id
impl Send for Id
impl Sync for Id
impl Unpin for Id
impl UnwindSafe for Id
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more