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.
impl UiNode
List methods.
Sourcepub fn chain(self, other: impl IntoUiNode) -> UiNode
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.
Sourcepub fn sorting_by(
self,
sort: impl Fn(&mut UiNode, &mut UiNode) -> Ordering + Send + 'static,
) -> UiNode
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.
impl UiNode
Constructors.
Sourcepub fn new(implementation: impl UiNodeImpl) -> UiNode
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§impl UiNode
UI operations.
impl UiNode
UI operations.
Sourcepub fn init(&mut self)
pub fn init(&mut self)
Initialize the node in a new UI context.
See UiNodeImpl::init
for more details.
Sourcepub fn deinit(&mut self)
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.
Sourcepub fn info(&mut self, info: &mut WidgetInfoBuilder)
pub fn info(&mut self, info: &mut WidgetInfoBuilder)
Continue building widget info metadata.
See UiNodeImpl::info
for more details.
Sourcepub fn event(&mut self, update: &EventUpdate)
pub fn event(&mut self, update: &EventUpdate)
Notify event update.
See UiNodeImpl::event
for more details.
Sourcepub fn update(&mut self, updates: &WidgetUpdates)
pub fn update(&mut self, updates: &WidgetUpdates)
Notify non-event update.
See UiNodeImpl::update
for more details.
Sourcepub fn update_list(
&mut self,
updates: &WidgetUpdates,
observer: &mut impl UiNodeListObserver,
)
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.
Sourcepub fn measure(&mut self, wm: &mut WidgetMeasure) -> Size2D<Px, Px>
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.
Sourcepub 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>
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.
Sourcepub fn layout(&mut self, wl: &mut WidgetLayout) -> Size2D<Px, Px>
pub fn layout(&mut self, wl: &mut WidgetLayout) -> Size2D<Px, Px>
Update node layout.
See UiNodeImpl::layout
for more details.
Sourcepub 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>
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.
Sourcepub fn render(&mut self, frame: &mut FrameBuilder)
pub fn render(&mut self, frame: &mut FrameBuilder)
Collect render instructions for a new frame.
See UiNodeImpl::render
for more details.
Sourcepub fn render_list(
&mut self,
frame: &mut FrameBuilder,
render: impl Fn(usize, &mut UiNode, &mut FrameBuilder) + Sync,
)
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.
Sourcepub fn render_update(&mut self, update: &mut FrameUpdate)
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.
Sourcepub fn render_update_list(
&mut self,
update: &mut FrameUpdate,
render_update: impl Fn(usize, &mut UiNode, &mut FrameUpdate) + Sync,
)
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.
impl UiNode
Children.
Sourcepub fn children_len(&self) -> usize
pub fn children_len(&self) -> usize
Number of direct descendants of this node.
Sourcepub fn try_with_child<R>(
&mut self,
index: usize,
visitor: impl FnOnce(&mut UiNode) -> R,
) -> Option<R>
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
.
Sourcepub fn with_child<R>(
&mut self,
index: usize,
visitor: impl FnOnce(&mut UiNode) -> R,
) -> R
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.
Sourcepub fn for_each_child(&mut self, visitor: impl FnMut(usize, &mut UiNode))
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.
Sourcepub fn try_for_each_child<B>(
&mut self,
visitor: impl FnMut(usize, &mut UiNode) -> ControlFlow<B>,
) -> ControlFlow<B>where
B: VarValue,
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.
Sourcepub fn par_each_child(&mut self, visitor: impl Fn(usize, &mut UiNode) + Sync)
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.
Sourcepub 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,
) -> Twhere
T: VarValue,
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,
) -> Twhere
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.
impl UiNode
Node type.
Sourcepub fn downcast_ref<U>(&self) -> Option<&U>where
U: UiNodeImpl,
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.
Sourcepub fn downcast_mut<U>(&mut self) -> Option<&mut U>where
U: UiNodeImpl,
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.
Sourcepub fn is<U>(&self) -> boolwhere
U: UiNodeImpl,
pub fn is<U>(&self) -> boolwhere
U: UiNodeImpl,
Gets if the node is an instance of implementation U
.
Sourcepub fn as_dyn(&mut self) -> &mut (dyn UiNodeImpl + 'static)
pub fn as_dyn(&mut self) -> &mut (dyn UiNodeImpl + 'static)
Exclusive borrow the node implementation directly.
Sourcepub fn is_list(&self) -> bool
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.
Sourcepub fn into_list(self) -> UiNode
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.
Sourcepub fn as_widget(&mut self) -> Option<WidgetUiNode<'_>>
pub fn as_widget(&mut self) -> Option<WidgetUiNode<'_>>
Access widget node methods, if the node defines a widget context.
Sourcepub fn into_widget(self) -> UiNode
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.
Sourcepub fn init_widget(self) -> (UiNode, ResponseVar<WidgetId>)
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.
Sourcepub fn trace<E, S>(self, enter_mtd: E) -> UiNode
pub fn trace<E, S>(self, enter_mtd: E) -> UiNode
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 UpdatesTraceUiNodeExt for UiNode
impl UpdatesTraceUiNodeExt for UiNode
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> 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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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