pub trait UiNodeImpl: Any + Send {
Show 22 methods
// Required methods
fn children_len(&self) -> usize;
fn with_child(&mut self, index: usize, visitor: &mut dyn FnMut(&mut UiNode));
// Provided methods
fn is_list(&self) -> bool { ... }
fn for_each_child(&mut self, visitor: &mut dyn FnMut(usize, &mut UiNode)) { ... }
fn try_for_each_child(
&mut self,
visitor: &mut dyn FnMut(usize, &mut UiNode) -> ControlFlow<BoxAnyVarValue>,
) -> ControlFlow<BoxAnyVarValue> { ... }
fn par_each_child(&mut self, visitor: &(dyn Fn(usize, &mut UiNode) + Sync)) { ... }
fn par_fold_reduce(
&mut self,
identity: BoxAnyVarValue,
fold: &(dyn Fn(BoxAnyVarValue, usize, &mut UiNode) -> BoxAnyVarValue + Sync),
reduce: &(dyn Fn(BoxAnyVarValue, BoxAnyVarValue) -> BoxAnyVarValue + Sync),
) -> BoxAnyVarValue { ... }
fn init(&mut self) { ... }
fn deinit(&mut self) { ... }
fn info(&mut self, info: &mut WidgetInfoBuilder) { ... }
fn event(&mut self, update: &EventUpdate) { ... }
fn update(&mut self, updates: &WidgetUpdates) { ... }
fn update_list(
&mut self,
updates: &WidgetUpdates,
observer: &mut dyn UiNodeListObserver,
) { ... }
fn measure(&mut self, wm: &mut WidgetMeasure) -> PxSize { ... }
fn measure_list(
&mut self,
wm: &mut WidgetMeasure,
measure: &(dyn Fn(usize, &mut UiNode, &mut WidgetMeasure) -> PxSize + Sync),
fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync),
) -> PxSize { ... }
fn layout(&mut self, wl: &mut WidgetLayout) -> PxSize { ... }
fn layout_list(
&mut self,
wl: &mut WidgetLayout,
layout: &(dyn Fn(usize, &mut UiNode, &mut WidgetLayout) -> PxSize + Sync),
fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync),
) -> PxSize { ... }
fn render(&mut self, frame: &mut FrameBuilder) { ... }
fn render_list(
&mut self,
frame: &mut FrameBuilder,
render: &(dyn Fn(usize, &mut UiNode, &mut FrameBuilder) + Sync),
) { ... }
fn render_update(&mut self, update: &mut FrameUpdate) { ... }
fn render_update_list(
&mut self,
update: &mut FrameUpdate,
render_update: &(dyn Fn(usize, &mut UiNode, &mut FrameUpdate) + Sync),
) { ... }
fn as_widget(&mut self) -> Option<&mut dyn WidgetUiNodeImpl> { ... }
}Expand description
Represents an UiNode implementation.
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 you can manually implement this trait.
Required Methods§
Sourcefn children_len(&self) -> usize
fn children_len(&self) -> usize
Gets the current count of children nodes.
Sourcefn with_child(&mut self, index: usize, visitor: &mut dyn FnMut(&mut UiNode))
fn with_child(&mut self, index: usize, visitor: &mut dyn FnMut(&mut UiNode))
Visit a child node by index. If the index is not valid visitor is not called.
Nodes with many children should also implement for_each_child and par_each_child for better performance.
Provided Methods§
Sourcefn is_list(&self) -> bool
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 child nodes for layout.
If true the node must implement all methods that iterate over children, for better performance and if possible, parallelization.
A warning is logged in debug builds if a list node did not implement one of these methods.
Sourcefn for_each_child(&mut self, visitor: &mut dyn FnMut(usize, &mut UiNode))
fn for_each_child(&mut self, visitor: &mut dyn 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.
Sourcefn try_for_each_child(
&mut self,
visitor: &mut dyn FnMut(usize, &mut UiNode) -> ControlFlow<BoxAnyVarValue>,
) -> ControlFlow<BoxAnyVarValue>
fn try_for_each_child( &mut self, visitor: &mut dyn FnMut(usize, &mut UiNode) -> ControlFlow<BoxAnyVarValue>, ) -> ControlFlow<BoxAnyVarValue>
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.
Sourcefn par_each_child(&mut self, visitor: &(dyn Fn(usize, &mut UiNode) + Sync))
fn par_each_child(&mut self, visitor: &(dyn Fn(usize, &mut UiNode) + Sync))
Calls visitor for each child node in parallel.
The closure parameters are the child index and the child.
Sourcefn par_fold_reduce(
&mut self,
identity: BoxAnyVarValue,
fold: &(dyn Fn(BoxAnyVarValue, usize, &mut UiNode) -> BoxAnyVarValue + Sync),
reduce: &(dyn Fn(BoxAnyVarValue, BoxAnyVarValue) -> BoxAnyVarValue + Sync),
) -> BoxAnyVarValue
fn par_fold_reduce( &mut self, identity: BoxAnyVarValue, fold: &(dyn Fn(BoxAnyVarValue, usize, &mut UiNode) -> BoxAnyVarValue + Sync), reduce: &(dyn Fn(BoxAnyVarValue, BoxAnyVarValue) -> BoxAnyVarValue + Sync), ) -> BoxAnyVarValue
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.
Sourcefn init(&mut self)
fn init(&mut self)
Initializes the node in a new UI context.
Common init operations are subscribing to variables and events and initializing data.
You can use WIDGET to subscribe events and vars, the subscriptions live until the widget is deinited.
If the node is a custom widget it must request an info, layout and render updates, other nodes do not need to request any sort of update on init.
Note that this method can be called again, after a deinit.
Sourcefn deinit(&mut self)
fn deinit(&mut self)
Deinitializes the node in the current UI context.
Common deinit operations include dropping allocations and handlers.
If the node is a custom widget it must request an info, layout and render updates, other nodes do not need to request any sort of update on deinit.
Note that init can be called again after this.
Sourcefn info(&mut self, info: &mut WidgetInfoBuilder)
fn info(&mut self, info: &mut WidgetInfoBuilder)
Builds widget info.
This method is called every time there are structural changes in the UI tree such as a node added or removed, you
can also request an info rebuild using WIDGET.update_info.
Only nodes in widgets that requested info rebuild and nodes in their ancestors receive this call. Other
widgets reuse their info in the new info tree. The widget’s latest built info is available in WIDGET.info.
Note that info rebuild has higher priority over event, update, layout and render, this means that if you set a variable and request info update the next info rebuild will still observe the old variable value, you can work around this issue by only requesting info rebuild after the variable updates.
Sourcefn event(&mut self, update: &EventUpdate)
fn event(&mut self, update: &EventUpdate)
Receives an event.
Every call to this method is for a single update of a single event type, you can listen to events
by subscribing to then on init and using the Event::on method in this method to detect the event.
Note that events sent to descendant nodes also flow through this method and must be delegated. If you observe an event for a descendant before delegating to the descendant this is a preview handling, in the normal handling you delegate first, then check the event propagation.
Sourcefn update(&mut self, updates: &WidgetUpdates)
fn update(&mut self, updates: &WidgetUpdates)
Receives variable and other non-event updates.
Calls to this method aggregate all updates that happen in the last pass, multiple variables can be new at the same time.
You can listen to variable updates by subscribing to then on init and using the Var::get_new method in this method to
receive the new values.
A custom update can be requested using the context WIDGET.update. Common update operations include reacting to variable
changes that generate an intermediary value for layout or render, the update implementation uses WIDGET to request layout
and render after updating the data. Note that for simple variables that are used directly on layout or render you can subscribe
to that operation directly, skipping update.
Sourcefn update_list(
&mut self,
updates: &WidgetUpdates,
observer: &mut dyn UiNodeListObserver,
)
fn update_list( &mut self, updates: &WidgetUpdates, observer: &mut dyn UiNodeListObserver, )
Does update and if the node is a list notifies list changes to the observer.
Sourcefn measure(&mut self, wm: &mut WidgetMeasure) -> PxSize
fn measure(&mut self, wm: &mut WidgetMeasure) -> PxSize
Computes the widget size given the contextual layout metrics without actually updating the widget layout.
Implementers must return the same size layout returns for the given LayoutMetrics, without
affecting the actual widget render. Panel widgets that implement some complex layouts need to get an
what the widget would be given some constraints, this value is used to inform the actual layout call.
Nodes that implement layout must also implement this method, the LAYOUT context can be used to retrieve the metrics,
the WidgetMeasure parameter can be used to communicate with the parent layout, such as disabling inline layout, the
returned PxSize is the desired size given the parent constraints.
Sourcefn measure_list(
&mut self,
wm: &mut WidgetMeasure,
measure: &(dyn Fn(usize, &mut UiNode, &mut WidgetMeasure) -> PxSize + Sync),
fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync),
) -> PxSize
fn measure_list( &mut self, wm: &mut WidgetMeasure, measure: &(dyn Fn(usize, &mut UiNode, &mut WidgetMeasure) -> PxSize + Sync), fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync), ) -> PxSize
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.
Sourcefn layout(&mut self, wl: &mut WidgetLayout) -> PxSize
fn layout(&mut self, wl: &mut WidgetLayout) -> PxSize
Computes the widget layout given the contextual layout metrics.
Implementers must also implement measure. This method is called by the parent layout once the final constraints
for the frame are defined, the LAYOUT context can be used to retrieve the constraints, the WidgetLayout parameter
can be used to communicate layout metadata such as inline segments to the parent layout, the returned PxSize is the
final size given the constraints.
Only widgets and ancestors that requested layout or use metrics that changed since last layout receive this call. Other widgets reuse the last layout result.
Nodes that render can also implement this operation just to observe the latest widget size, if changes are detected
the WIDGET.render method can be used to request render.
Sourcefn layout_list(
&mut self,
wl: &mut WidgetLayout,
layout: &(dyn Fn(usize, &mut UiNode, &mut WidgetLayout) -> PxSize + Sync),
fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync),
) -> PxSize
fn layout_list( &mut self, wl: &mut WidgetLayout, layout: &(dyn Fn(usize, &mut UiNode, &mut WidgetLayout) -> PxSize + Sync), fold_size: &(dyn Fn(PxSize, PxSize) -> PxSize + Sync), ) -> PxSize
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.
Sourcefn render(&mut self, frame: &mut FrameBuilder)
fn render(&mut self, frame: &mut FrameBuilder)
Generates render instructions and updates transforms and hit-test areas.
This method does not generate pixels immediately, it generates display items that are visual building block instructions for the renderer that will run after the window display list is built.
Only widgets and ancestors that requested render receive this call, other widgets reuse the display items and transforms from the last frame.
Sourcefn render_list(
&mut self,
frame: &mut FrameBuilder,
render: &(dyn Fn(usize, &mut UiNode, &mut FrameBuilder) + Sync),
)
fn render_list( &mut self, frame: &mut FrameBuilder, render: &(dyn 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.
Sourcefn render_update(&mut self, update: &mut FrameUpdate)
fn render_update(&mut self, update: &mut FrameUpdate)
Updates values in the last generated frame.
Some display item values and transforms can be updated directly, without needing to rebuild the display list. All FrameBuilder
methods that accept a FrameValue<T> input can be bound to an ID that can be used to update that value.
Only widgets and ancestors that requested render update receive this call. Note that if any other widget in the same window requests render all pending render update requests are upgraded to render requests.
Sourcefn render_update_list(
&mut self,
update: &mut FrameUpdate,
render_update: &(dyn Fn(usize, &mut UiNode, &mut FrameUpdate) + Sync),
)
fn render_update_list( &mut self, update: &mut FrameUpdate, render_update: &(dyn 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.
Sourcefn as_widget(&mut self) -> Option<&mut dyn WidgetUiNodeImpl>
fn as_widget(&mut self) -> Option<&mut dyn WidgetUiNodeImpl>
Gets the node implementation as a WidgetUiNodeImpl, if the node defines a widget instance scope.
Implementations§
Source§impl dyn UiNodeImpl
impl dyn UiNodeImpl
Sourcepub fn parallelize_hint(&mut self) -> bool
pub fn parallelize_hint(&mut self) -> bool
Gets if this node is a good candidate for parallelization when visiting children.
List implementers should check this and PARALLEL_VAR to enable parallelization of node methods.