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 TkAction::RECONFIGURE or ConfigMgr::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
sourceimpl 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<'_>ⓘNotable traits for WidgetPathIter<'a>impl<'a> Iterator for WidgetPathIter<'a> type Item = usize;
pub fn iter(&self) -> WidgetPathIter<'_>ⓘNotable traits for WidgetPathIter<'a>impl<'a> Iterator for WidgetPathIter<'a> type Item = usize;
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<'_>ⓘNotable traits for WidgetPathIter<'a>impl<'a> Iterator for WidgetPathIter<'a> type Item = usize;
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
sourceimpl Ord for WidgetId
impl Ord for WidgetId
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<'a> PartialEq<&'a Option<WidgetId>> for WidgetId
impl<'a> PartialEq<&'a Option<WidgetId>> for WidgetId
sourceimpl<'a> PartialEq<&'a WidgetId> for WidgetId
impl<'a> PartialEq<&'a WidgetId> for WidgetId
sourceimpl<'a> PartialEq<Option<&'a WidgetId>> for WidgetId
impl<'a> PartialEq<Option<&'a WidgetId>> for WidgetId
sourceimpl PartialEq<Option<WidgetId>> for WidgetId
impl PartialEq<Option<WidgetId>> for WidgetId
sourceimpl PartialEq<WidgetId> for WidgetId
impl PartialEq<WidgetId> for WidgetId
sourceimpl PartialOrd<WidgetId> for WidgetId
impl PartialOrd<WidgetId> for WidgetId
sourcefn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
sourcefn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Try approximate conversion from Self to T Read more
sourcefn cast_approx(self) -> T
fn cast_approx(self) -> T
Cast approximately from Self to T Read more
sourceimpl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
sourcefn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
sourcefn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
sourcefn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
sourcefn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more
sourceimpl<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,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.