Skip to main content

ReactiveList

Struct ReactiveList 

Source
pub struct ReactiveList { /* private fields */ }
Expand description

A reactive list: for item in $items key id (or, keyless, for item in $items) in .rsx. Re-runs its source reactively and reconciles the item widgets — reused keys/positions keep their node/widget, new ones are built, gone ones are disposed, and the layout children are reordered — instead of rebuilding the whole block on every change. new/with_gap reconcile by key (identity-stable); positional/ positional_with_gap reconcile by index (no key clause needed, cheap append/truncate).

Implementations§

Source§

impl ReactiveList

Source

pub fn as_row(self) -> Self

Runs the reconciled items along the horizontal axis instead of stacking them.

Every constructor builds a column, because a list’s own node exists before it is attached and cannot ask a parent it does not have yet. A for written inside a row reconciles into that row as a transparent fragment and never reaches here; one that cannot — inside a reactive if, say, which owns a node of its own — is boxed, and this is how it learns which way its items run.

Source

pub fn new<Item, Key, S, K, B>( source: S, key: K, build: B, gap: f32, ) -> Result<Self, LayoutError>
where Key: Hash + 'static, Item: 'static, S: Fn() -> Vec<Item> + 'static, K: Fn(&Item) -> Key + 'static, B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,

source reads the reactive item collection; key extracts a stable identity per item; build constructs one widget per item, creating its nodes against the live (thread-local) layout tree from inside the reconcile effect.

Source

pub fn with_style<Item, Key, S, K, B>( container_style: LayoutStyle, source: S, key: K, build: B, ) -> Result<Self, LayoutError>
where Key: Hash + 'static, Item: 'static, S: Fn() -> Vec<Item> + 'static, K: Fn(&Item) -> Key + 'static, B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,

Keyed like new/with_gap, but the caller supplies the container’s LayoutStyle — flex direction, gap, alignment. Use it for a horizontal reactive row (e.g. a bar’s workspace chips), which the column-oriented constructors can’t express.

Source

pub fn positional<Item, S, B>( source: S, build: B, gap: f32, ) -> Result<Self, LayoutError>
where Item: 'static, S: Fn() -> Vec<Item> + 'static, B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,

A keyless reactive list: for item in $items with no key clause. Reconciles by POSITION — the item at index i always reuses the node previously at index i, so an append/truncate reuses every surviving node cheaply, but a reorder rebuilds rather than moving nodes (no per-item identity without a key).

Source

pub fn keyed<Item, Key, S, K, B>( source: S, key: K, build: B, ) -> Result<Self, LayoutError>
where Key: Hash + 'static, Item: Clone + 'static, S: Fn() -> Vec<Item> + 'static, K: Fn(&Item) -> Key + 'static, B: Fn(ReadSignal<Item>) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,

A keyed list whose builder receives a live handle to its item rather than a copy of it.

The difference decides what a row is allowed to be. With an owned snapshot, a key that persists reuses the widget and the new value is discarded — so a row that must follow its data has to be keyed on that data, which rebuilds it and throws away whatever local state it held: a caret, a drag in progress, a scroll position. Keying on identity and reading the value through a handle separates the two questions — the key decides whether this is still the same row, the handle carries what that row now says.

Use Self::new where a row genuinely is its value, which most lists are, and this where a row outlives its contents.

Trait Implementations§

Source§

impl Component for ReactiveList

Source§

fn view(&self) -> RenderNode

Source§

fn on_event(&mut self, event: &Event) -> EventResult

Source§

fn debug_name(&self) -> &'static str

Human-readable widget type name for the devtools tree inspector.
Source§

impl LayoutItem for ReactiveList

Source§

fn layout_node(&self) -> NodeId

Source§

fn pointer_opaque(&self) -> bool

Whether this widget stands in front of whatever its siblings drew underneath it, for a pointer event its parent is hit-testing. Read more

Auto Trait Implementations§

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