pub struct Id(_);
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.

Implementations

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!

Generate a new Id by hashing some source (e.g. a string or integer).

Generate a new Id by hashing the parent Id and the given argument.

Short and readable summary

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.