UiNode

Struct UiNode 

Source
pub struct UiNode(/* private fields */);
Expand description

Represents an UI tree node instance.

You can use the match_node helper to quickly declare a new node from a closure, most property nodes are implemented using the match helpers. For more advanced nodes can implement the UiNodeImpl trait. Other types can be converted to nodes if they implement IntoUiNode.

Implementations§

Source§

impl UiNode

List methods.

Source

pub fn chain(self, other: impl IntoUiNode) -> UiNode

Create a list node that has self followed by other.

If self or other are already lists returns a list view that flattens the children when iterating.

This method returns an optimized list view, it will reuse chain lists when possible, ignore nil and other tricks, if you need the inner lists to be a predictable arrangement use ChainList directly.

Source

pub fn sorting_by( self, sort: impl Fn(&mut UiNode, &mut UiNode) -> Ordering + Send + 'static, ) -> UiNode

Create a sorting list view for this node into list.

The list items are not moved, they are sorted only for layout and render, see SortingList for more details.

If this node is already a sorting list just replaces the sort.

Source§

impl UiNode

Constructors.

Source

pub fn new(implementation: impl UiNodeImpl) -> UiNode

New UI node instance from implementation.

Note that IntoUiNode is implemented for all U: UiNodeImpl so you don’t usually need to call this.

Source

pub fn nil() -> UiNode

New UI node that does nothing and collapses layout.

Source§

impl UiNode

UI operations.

Source

pub fn op(&mut self, op: UiNodeOp<'_>)

Calls the UiNodeOp.

Source

pub fn init(&mut self)

Initialize the node in a new UI context.

See UiNodeImpl::init for more details.

Source

pub fn deinit(&mut self)

Deinitialize the node in the current UI context.

This must be called before dropping the node.

After calling this you can move the node to a new context and call init again.

See UiNodeImpl::deinit for more details.

Source

pub fn info(&mut self, info: &mut WidgetInfoBuilder)

Continue building widget info metadata.

See UiNodeImpl::info for more details.

Source

pub fn event(&mut self, update: &EventUpdate)

Notify event update.

See UiNodeImpl::event for more details.

Source

pub fn update(&mut self, updates: &WidgetUpdates)

Notify non-event update.

See UiNodeImpl::update for more details.

Source

pub fn update_list( &mut self, updates: &WidgetUpdates, observer: &mut impl UiNodeListObserver, )

Notify non-event update and observe list changes if the widget is a list.

See UiNodeImpl::update_list for more details.

Source

pub fn measure(&mut self, wm: &mut WidgetMeasure) -> Size2D<Px, Px>

Estimate node layout without actually updating the node render state.

See UiNodeImpl::measure for more details.

Source

pub fn measure_list( &mut self, wm: &mut WidgetMeasure, measure: impl Fn(usize, &mut UiNode, &mut WidgetMeasure) -> Size2D<Px, Px> + Sync, fold_size: impl Fn(Size2D<Px, Px>, Size2D<Px, Px>) -> Size2D<Px, Px> + Sync, ) -> Size2D<Px, Px>

If the node is_list measure each child and combine the size using fold_size.

If the node is not a list, simply measures it.

See UiNodeImpl::measure_list for more details.

Source

pub fn layout(&mut self, wl: &mut WidgetLayout) -> Size2D<Px, Px>

Update node layout.

See UiNodeImpl::layout for more details.

Source

pub fn layout_list( &mut self, wl: &mut WidgetLayout, layout: impl Fn(usize, &mut UiNode, &mut WidgetLayout) -> Size2D<Px, Px> + Sync, fold_size: impl Fn(Size2D<Px, Px>, Size2D<Px, Px>) -> Size2D<Px, Px> + Sync, ) -> Size2D<Px, Px>

If the node is_list layout each child and combine the size using fold_size.

If the node is not a list, simply layout it.

See UiNodeImpl::layout_list for more details.

Source

pub fn render(&mut self, frame: &mut FrameBuilder)

Collect render instructions for a new frame.

See UiNodeImpl::render for more details.

Source

pub fn render_list( &mut self, frame: &mut FrameBuilder, render: impl Fn(usize, &mut UiNode, &mut FrameBuilder) + Sync, )

If the node is_list render each child.

If the node is not a list, simply renders it.

See UiNodeImpl::render_list for more details.

Source

pub fn render_update(&mut self, update: &mut FrameUpdate)

Collect render patches to apply to the previous frame.

See UiNodeImpl::render_update for more details.

Source

pub fn render_update_list( &mut self, update: &mut FrameUpdate, render_update: impl Fn(usize, &mut UiNode, &mut FrameUpdate) + Sync, )

If the node is_list render_update each child.

If the node is not a list, simply render_update it.

See UiNodeImpl::render_update_list for more details.

Source§

impl UiNode

Children.

Source

pub fn children_len(&self) -> usize

Number of direct descendants of this node.

Source

pub fn try_with_child<R>( &mut self, index: usize, visitor: impl FnOnce(&mut UiNode) -> R, ) -> Option<R>

Call visitor with a exclusive reference to the child node identified by index.

If the index is out of bounds the closure is not called and returns None.

Source

pub fn with_child<R>( &mut self, index: usize, visitor: impl FnOnce(&mut UiNode) -> R, ) -> R

Call visitor with a exclusive reference to the child node identified by index.

Panics if the index is out of bounds.

Source

pub fn for_each_child(&mut self, visitor: impl FnMut(usize, &mut UiNode))

Call visitor for each child node of self, one at a time.

The closure parameters are the child index and the child.

Source

pub fn try_for_each_child<B>( &mut self, visitor: impl FnMut(usize, &mut UiNode) -> ControlFlow<B>, ) -> ControlFlow<B>
where B: VarValue,

Call visitor for each child node of self, one at a time, with control flow.

The closure parameters are the child index and the child.

Source

pub fn par_each_child(&mut self, visitor: impl Fn(usize, &mut UiNode) + Sync)

Calls visitor for each child node in parallel.

The closure parameters are the child index and the child.

Source

pub fn par_fold_reduce<T>( &mut self, identity: T, fold: impl Fn(T, usize, &mut UiNode) -> T + Sync, reduce: impl Fn(T, T) -> T + Sync, ) -> T
where T: VarValue,

Calls fold for each child node in parallel, with fold accumulators produced by cloning identity, then merges the folded results using reduce to produce the final value also in parallel.

If the reduce closure is associative, an append like operation will produce a result in the same order as the input items.

Source§

impl UiNode

Node type.

Source

pub fn downcast_ref<U>(&self) -> Option<&U>
where U: UiNodeImpl,

Returns some reference to implementation of type U, if the node instance is of that implementation.

Source

pub fn downcast_mut<U>(&mut self) -> Option<&mut U>
where U: UiNodeImpl,

Returns some mutable reference to implementation of type U, if the node instance is of that implementation.

Source

pub fn is<U>(&self) -> bool
where U: UiNodeImpl,

Gets if the node is an instance of implementation U.

Source

pub fn as_dyn(&mut self) -> &mut (dyn UiNodeImpl + 'static)

Exclusive borrow the node implementation directly.

Source

pub fn is_list(&self) -> bool

Gets if the node represents a list of other nodes.

If true the node provides only minimal layout implementations and expects the caller to use measure_list, layout_list or direct access to the child nodes for layout.

Source

pub fn into_list(self) -> UiNode

Returns a node that is_list.

If self is a list returns it unchanged.

If self is nil returns an empty list node.

Otherwise returns a new list node with self as the single entry.

Source

pub fn is_nil(&self) -> bool

Gets if is nil.

Source

pub fn as_widget(&mut self) -> Option<WidgetUiNode<'_>>

Access widget node methods, if the node defines a widget context.

Source

pub fn into_widget(self) -> UiNode

Returns a node that defines a widget context.

If this node already defines a widget just returns it, if not wraps it in a minimal widget implementation.

See also init_widget for a node that awaits until self is inited to verify if a new widget really needs to be declared.

Source

pub fn init_widget(self) -> (UiNode, ResponseVar<WidgetId>)

Returns a node that defines a widget context or will begin defining it after init.

Also returns a response var that contains or will contain the widget instance ID.

If self is already an widget node simply returns it and the ID, otherwise returns a node that wraps self and checks again if self is a widget after init, if self is still not a widget after init the wrapper node starts defining a minimal widget context.

Some nodes like ArcNode::take_on_init can only become widgets on init, this helper is an alternative to into_widget that avoids declaring a second wrapper widget in those cases. Note that because the wrapper node needs to define a widget context after the init call the wrapped self node will need to be reinited inside the new widget.

Source

pub fn trace<E, S>(self, enter_mtd: E) -> UiNode
where UiNode: Sized, E: FnMut(UiNodeOpMethod) -> S + Send + 'static,

Wraps this in a node that, before delegating each method, calls a closure with the UiNodeOpMethod, the closure can return a span that is dropped after the method delegation.

The tracing node delegates all methods to self, but currently only traces the UiNodeOpMethod methods. If this node is an widget the enter_mtd closure will be called (and span dropped) in the context of the widget.

You can use the tracing crate to create the span. You can also use the RunOnDrop struct to run a closure after the method executes.

Trait Implementations§

Source§

impl IntoUiNode for UiNode

Source§

fn into_node(self) -> UiNode

Instantiate the UI node.
Source§

impl UpdatesTraceUiNodeExt for UiNode

Source§

fn instrument<S>(self, tag: S) -> UiNode
where S: Into<String>,

Defines a custom span.

Auto Trait Implementations§

§

impl Freeze for UiNode

§

impl !RefUnwindSafe for UiNode

§

impl Send for UiNode

§

impl !Sync for UiNode

§

impl Unpin for UiNode

§

impl !UnwindSafe for UiNode

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
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,