Struct egui::Id

source · []
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

Deserialize this value from the given Serde deserializer. 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

Serialize this value into the given Serde serializer. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more