Struct kas::Node

source ·
pub struct Node<'a>(/* private fields */);
Expand description

Type-erased widget with input data

This type is a &mut dyn Widget<Data = A> paired with input data &A, where the type A is erased.

The default implementation of this type uses a boxed trait object. The unsafe_node feature enables a more efficient unboxed implementation (this must make assumptions about VTables beyond what Rust specifies, thus lacks even the usual programmer-provided verification of unsafe code).

Implementations§

source§

impl<'a> Node<'a>

source

pub fn new<T>(widget: &'a mut dyn Widget<Data = T>, data: &'a T) -> Node<'a>
where T: 'a,

Construct

source

pub fn re<'b>(&'b mut self) -> Node<'b>
where 'a: 'b,

Reborrow with a new lifetime

Rust allows references like &T or &mut T to be “reborrowed” through coercion: essentially, the pointer is copied under a new, shorter, lifetime. Until rfcs#1403 lands, reborrows on user types require a method call.

source

pub fn as_layout(&self) -> &dyn Layout

Reborrow as a dyn Layout

source

pub fn id_ref(&self) -> &Id

Get the widget’s identifier

source

pub fn id(&self) -> Id

Get the widget’s identifier

source

pub fn eq_id<T>(&self, rhs: T) -> bool
where Id: PartialEq<T>,

Test widget identifier for equality

This method may be used to test against Id, Option<Id> and Option<&Id>.

source

pub fn is_ancestor_of(&self, id: &Id) -> bool

Check whether id is self or a descendant

This function assumes that id is a valid widget.

source

pub fn is_strict_ancestor_of(&self, id: &Id) -> bool

Check whether id is not self and is a descendant

This function assumes that id is a valid widget.

source

pub fn rect(&self) -> Rect

Get the widget’s region, relative to its parent.

source

pub fn num_children(&self) -> usize

Get the number of child widgets

Every value in the range 0..self.num_children() is a valid child index.

source

pub fn for_child<R>( &mut self, index: usize, f: impl FnOnce(Node<'_>) -> R ) -> Option<R>

Run f on some child by index and, if valid, return the result.

Calls the closure and returns Some(result) exactly when index < self.num_children().

source

pub fn for_children(&mut self, f: impl FnMut(Node<'_>))

Run a f on all children

source

pub fn find_child_index(&self, id: &Id) -> Option<usize>

Find the child which is an ancestor of this id, if any

If Some(index) is returned, this is probably but not guaranteed to be a valid child index.

source

pub fn find_node<F, T>(&mut self, id: &Id, cb: F) -> Option<T>
where F: FnOnce(Node<'_>) -> T,

Find the descendant with this id, if any, and call cb on it

Returns Some(result) if and only if node id was found.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Node<'a>

§

impl<'a> !Send for Node<'a>

§

impl<'a> !Sync for Node<'a>

§

impl<'a> Unpin for Node<'a>

§

impl<'a> !UnwindSafe for Node<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<S, T> Cast<T> for S
where T: Conv<S>,

§

fn cast(self) -> T

Cast from Self to T Read more
§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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