pub struct WidgetId(/* private fields */);
Expand description
A unique identifier for a single Widget
.
WidgetId
s are generated automatically for all widgets in the widget tree.
More specifically, each WidgetPod
has a unique WidgetId
.
These ids are used internally to route events, and can be used to communicate
between widgets, by submitting a command (as with [EventCtx::submit_command
])
and passing a WidgetId
as the Target
.
A widget can retrieve its id via methods on the various contexts, such as
LifeCycleCtx::widget_id
.
§Explicit WidgetId
s.
Sometimes, you may want to construct a widget, in a way that lets you know its id,
so you can refer to the widget later. You can use WidgetPod::new_with_id
to pass
an id to the WidgetPod
you’re creating; various widgets which have methods to create
children may have variants taking ids as parameters.
If you set a WidgetId
directly, you are responsible for ensuring that it
is unique. Two widgets must not be created with the same id.
Implementations§
source§impl WidgetId
impl WidgetId
sourcepub fn next() -> WidgetId
pub fn next() -> WidgetId
Allocate a new, unique WidgetId
.
All widgets are assigned ids automatically; you should only create an explicit id if you need to know it ahead of time, for instance if you want two sibling widgets to know each others’ ids.
You must ensure that a given WidgetId
is only ever used for one
widget at a time.
sourcepub const fn reserved(raw: u16) -> WidgetId
pub const fn reserved(raw: u16) -> WidgetId
Create a reserved WidgetId
, suitable for reuse.
The caller is responsible for ensuring that this ID is in fact assigned to a single widget at any time, or your code may become haunted.
The actual inner representation of the returned WidgetId
will not
be the same as the raw value that is passed in; it will be
u64::max_value() - raw
.
pub fn to_raw(self) -> u64
Trait Implementations§
source§impl PartialEq for WidgetId
impl PartialEq for WidgetId
impl Copy for WidgetId
impl Eq for WidgetId
impl StructuralPartialEq for WidgetId
Auto Trait Implementations§
impl Freeze for WidgetId
impl RefUnwindSafe for WidgetId
impl Send for WidgetId
impl Sync for WidgetId
impl Unpin for WidgetId
impl UnwindSafe for WidgetId
Blanket Implementations§
source§impl<T> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
source§fn as_dyn_any(&self) -> &(dyn Any + 'static)
fn as_dyn_any(&self) -> &(dyn Any + 'static)
source§fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.