PanelList

Struct PanelList 

Source
pub struct PanelList<D = DefaultPanelListData>
where D: PanelListData,
{ /* private fields */ }
Expand description

Represents the final UI list in a panel layout node.

Panel widgets should wrap their children node on this type to support Z-index sorting and to easily track associated item data.

By default the associated item data is a DefaultPanelListData that represents the offset of each item inside the panel, but it can be any type that implements PanelListData. The panel list default render implementation uses this data to position the children widgets. Note that you must commit_data changes to this data at the end of a layout pass.

Panel widgets can also mark the list using track_info_range to implement getter properties such as is_odd or is_even.

Implementations§

Source§

impl PanelList<DefaultPanelListData>

Source

pub fn new(list: impl IntoUiNode) -> Self

New from list and default data.

Source§

impl<D> PanelList<D>
where D: PanelListData,

Source

pub fn new_custom(list: impl IntoUiNode) -> Self

New from list and custom data type.

Source

pub fn track_info_range( self, info_id: impl Into<StateId<PanelListRange>>, ) -> Self

Enable tracking the first and last child in the parent widget info.

The info is set in the info_id, it can be used to identify the children widgets that are the panel children as the info tree may track extra widgets as children when they are set by other properties, like background.

Source

pub fn into_parts( self, ) -> (UiNode, Vec<Mutex<D>>, FrameValueKey<PxTransform>, Option<StateId<PanelListRange>>)

Into list and associated data.

Source

pub fn from_parts( list: UiNode, data: Vec<Mutex<D>>, offset_key: FrameValueKey<PxTransform>, info_id: Option<StateId<PanelListRange>>, ) -> Self

New from list and associated data.

§Panics

Panics if the list and data don’t have the same length.

Source

pub fn info_id(&self) -> Option<StateId<PanelListRange>>

Gets the ID set on the parent widget info if track_info_range was enabled.

Source

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

Call visitor with a exclusive reference to the child node and associated data 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, &mut D), )

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

The closure parameters are the child index, the child and the associated data.

Source

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

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

The closure parameters are the child index, the child and the associated data.

Source

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

Calls visitor for each child node in parallel.

The closure parameters are the child index, the child and the associated data.

Source

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

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

The reduce call is associative, the order is preserved in the result.

Source

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

Call measure for each node with associated data and combines the final size using fold_size.

Source

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

Call layout for each node with associated data and combines the final size using fold_size.

Source

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

Call render for each node with associated data.

Note that the PanelListData child offset and reference frame are already pushed when render is called.

Source

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

Call render_update for each node with associated data.

Note that the PanelListData child offset and reference frame are already pushed when render_update is called.

Source

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

Iterate over the list in the Z order.

Source

pub fn z_map(&mut self, index: usize) -> usize

Gets the index sorted in the list.

Source

pub fn data(&mut self, index: usize) -> &mut D

Reference the associated data.

Source

pub fn commit_data(&mut self) -> PanelListDataChanges

Calls commit for each child data, aggregate changes.

This must be called after the last update to the children data in a layout pass. Note that you can call commit directly in a for_each iteration if that iteration is the last in the layout pass.

Source

pub fn offset_key(&self) -> FrameValueKey<PxTransform>

Key used to define reference frames for each item.

The default implementation of render_all uses this key and the item index.

Trait Implementations§

Source§

impl<D> UiNodeImpl for PanelList<D>
where D: PanelListData,

Source§

fn children_len(&self) -> usize

Gets the current count of children nodes.
Source§

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

fn is_list(&self) -> bool

Gets if the node represents a list of other nodes. Read more
Source§

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

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

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

Calls visitor for each child node in parallel. Read more
Source§

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

fn init(&mut self)

Initializes the node in a new UI context. Read more
Source§

fn deinit(&mut self)

Deinitializes the node in the current UI context. Read more
Source§

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

Builds widget info. Read more
Source§

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

Receives an event. Read more
Source§

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

Receives variable and other non-event updates. Read more
Source§

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

fn measure(&mut self, wm: &mut WidgetMeasure) -> PxSize

Computes the widget size given the contextual layout metrics without actually updating the widget layout. Read more
Source§

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

fn layout(&mut self, wl: &mut WidgetLayout) -> PxSize

Computes the widget layout given the contextual layout metrics. Read more
Source§

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

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

Generates render instructions and updates transforms and hit-test areas. Read more
Source§

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

Updates values in the last generated frame. Read more
Source§

fn as_widget(&mut self) -> Option<&mut dyn WidgetUiNodeImpl>

Gets the node implementation as a WidgetUiNodeImpl, if the node defines a widget instance scope.
Source§

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

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. Read more

Auto Trait Implementations§

§

impl<D> Freeze for PanelList<D>

§

impl<D = DefaultPanelListData> !RefUnwindSafe for PanelList<D>

§

impl<D> Send for PanelList<D>

§

impl<D = DefaultPanelListData> !Sync for PanelList<D>

§

impl<D> Unpin for PanelList<D>
where D: Unpin,

§

impl<D = DefaultPanelListData> !UnwindSafe for PanelList<D>

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> 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, 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<U> IntoUiNode for U
where U: UiNodeImpl,

Source§

fn into_node(self) -> UiNode

Instantiate the UI node.
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, 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<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