pub struct Id(_);
Expand description
egui tracks widgets frame-to-frame using Id
s.
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 Id
s 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 Id
s 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.
Implementations
sourceimpl Id
impl Id
sourcepub fn null() -> Self
pub fn 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) -> Id
pub fn new(source: impl Hash) -> Id
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
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Id
impl<'de> Deserialize<'de> for Id
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<Id> for Id
impl PartialEq<Id> for Id
impl Copy for Id
impl Eq for Id
impl StructuralEq for Id
impl StructuralPartialEq for Id
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more