pub struct WidgetId(_);Expand description
Widget identifier
All widgets are assigned an identifier which is unique within the window. This type may be tested for equality and order and may be iterated over as a “path” of “key” values.
Formatting a WidgetId via Display prints the the path, for example
#1290a4. Here, # represents the root; each following hexadecimal digit
represents a path component except that digits 8-f are combined with the
following digit(s). Hence, the above path has components 1, 2, 90,
a4. To interpret these values, first subtract 8 from each digit but the
last digit, then read as base-8: [1, 2, 8, 20].
This type is small (64-bit) and non-zero: Option<WidgetId> has the same
size as WidgetId. It is also very cheap to Clone: usually only one if
check, and in the worst case a pointer dereference and ref-count increment.
Paths up to 14 digits long (as printed) are represented internally;
beyond this limit a reference-counted stack allocation is used.
WidgetId is neither Send nor Sync.
Identifiers are assigned when configured and when re-configured
(via Action::RECONFIGURE or ConfigCx::configure).
In most cases values are persistent but this is not guaranteed (e.g.
inserting or removing a child from a List widget will affect the
identifiers of all following children). View-widgets assign path components
based on the data key, thus possibly making identifiers persistent.
Implementations§
source§impl WidgetId
impl WidgetId
sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Is the identifier valid?
Default-constructed identifiers are invalid. Comparing invalid ids is considered a logic error and thus will panic in debug builds. This method may be used to check an identifier’s validity.
sourcepub fn iter(&self) -> WidgetPathIter<'_> ⓘ
pub fn iter(&self) -> WidgetPathIter<'_> ⓘ
Iterate over path components
sourcepub fn is_ancestor_of(&self, id: &Self) -> bool
pub fn is_ancestor_of(&self, id: &Self) -> bool
Returns true if self equals id or if id is a descendant of self
pub fn iter_keys_after(&self, id: &Self) -> WidgetPathIter<'_> ⓘ
sourcepub fn next_key_after(&self, id: &Self) -> Option<usize>
pub fn next_key_after(&self, id: &Self) -> Option<usize>
Get first key in path of self path after id
If the path of self starts with the path of id
(id.is_ancestor_of(self)) then this returns the next key in
self’s path (if any). Otherwise, this returns None.
sourcepub fn parent(&self) -> Option<WidgetId>
pub fn parent(&self) -> Option<WidgetId>
Get the parent widget’s identifier, if not root
Note: there is no guarantee that Self::as_u64 on the result will
match that of the original parent identifier.
sourcepub fn make_child(&self, key: usize) -> Self
pub fn make_child(&self, key: usize) -> Self
Make an identifier for the child with the given key
Note: this is not a getter method. Calling multiple times with the same
key may or may not return the same value!
sourcepub fn as_u64(&self) -> u64
pub fn as_u64(&self) -> u64
Convert to a u64
This value should not be interpreted, except as follows:
- it is guaranteed non-zero
- it may be passed to
Self::opt_from_u64 - comparing two
u64values generated this way will mostly work as an equality check of the sourceWidgetId, but can return false negatives (only if each id was generated through separate calls toSelf::make_child)
sourcepub fn opt_to_u64(id: Option<&WidgetId>) -> u64
pub fn opt_to_u64(id: Option<&WidgetId>) -> u64
Convert Option<WidgetId> to u64
This value should not be interpreted, except as follows:
- it is zero if and only if
id == None - it may be passed to
Self::opt_from_u64 - comparing two
u64values generated this way will mostly work as an equality check of the sourceWidgetId, but can return false negatives (only if each id was generated through separate calls toSelf::make_child)
sourcepub unsafe fn opt_from_u64(n: u64) -> Option<WidgetId>
pub unsafe fn opt_from_u64(n: u64) -> Option<WidgetId>
Convert u64 to Option<WidgetId>
Returns None if and only if n == 0.
Safety
This may only be called with the output of Self::as_u64,
Self::opt_from_u64, or 0.
This is unsafe since Self has a heap-allocated variant. If n looks
like a heap-allocated variant but is not the result of Self::as_u64,
or it is but the source instance of Self and all clones have been
destroyed, then some operations on the result of this method will
attempt to dereference an invalid pointer.
Trait Implementations§
source§impl Ord for WidgetId
impl Ord for WidgetId
source§impl<'a> PartialEq<&'a Option<WidgetId>> for WidgetId
impl<'a> PartialEq<&'a Option<WidgetId>> for WidgetId
source§impl<'a> PartialEq<&'a WidgetId> for WidgetId
impl<'a> PartialEq<&'a WidgetId> for WidgetId
source§impl<'a> PartialEq<Option<&'a WidgetId>> for WidgetId
impl<'a> PartialEq<Option<&'a WidgetId>> for WidgetId
source§impl PartialEq<Option<WidgetId>> for WidgetId
impl PartialEq<Option<WidgetId>> for WidgetId
source§impl PartialOrd<WidgetId> for WidgetId
impl PartialOrd<WidgetId> for WidgetId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for WidgetId
Auto Trait Implementations§
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> 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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.