pub struct Composer { /* private fields */ }Implementations§
Source§impl Composer
impl Composer
pub fn new( slots: Rc<SlotsHost>, applier: Rc<dyn ApplierHost>, runtime: RuntimeHandle, observer: SnapshotStateObserver, root: Option<NodeId>, ) -> Self
Sourcepub fn register_virtual_node(
&self,
node_id: NodeId,
node: Box<dyn Node>,
) -> Result<(), NodeError>
pub fn register_virtual_node( &self, node_id: NodeId, node: Box<dyn Node>, ) -> Result<(), NodeError>
Registers a virtual node in the Applier.
This is used by SubcomposeLayoutNode to register virtual container nodes so that subsequent insert_child commands can find them and attach children. Without this, virtual nodes would only exist in SubcomposeLayoutNodeInner.virtual_nodes and applier.get_mut(virtual_node_id) would fail, breaking child attachment.
Sourcepub fn node_has_no_parent(&self, node_id: NodeId) -> bool
pub fn node_has_no_parent(&self, node_id: NodeId) -> bool
Checks if a node has no parent (is a root node). Used by SubcomposeMeasureScope to filter subcompose results.
Sourcepub fn get_node_children(&self, node_id: NodeId) -> SmallVec<[NodeId; 8]>
pub fn get_node_children(&self, node_id: NodeId) -> SmallVec<[NodeId; 8]>
Gets the children of a node from the Applier.
This is used by SubcomposeLayoutNode to get children of virtual nodes directly from the Applier, where insert_child commands have been applied.
pub fn nodes_need_measure(&self, node_ids: &[NodeId]) -> bool
Sourcepub fn record_subcompose_child(&self, child_id: NodeId)
pub fn record_subcompose_child(&self, child_id: NodeId)
Records a child node in the current parent frame’s expected children list.
Used by SubcomposeLayout’s perform_subcompose to register virtual nodes
with the outer composer’s parent frame. This ensures that the pop_parent
call at the end of subcompose_slot generates a correct SyncChildren
command that preserves (rather than removes) the virtual nodes.
Without this, pop_parent would generate SyncChildren { expected: [] },
which removes all virtual nodes and their subtrees from the applier.
Sourcepub fn clear_node_children(&self, node_id: NodeId)
pub fn clear_node_children(&self, node_id: NodeId)
Clears all children of a node in the Applier.
This is used by SubcomposeLayoutNode when reusing a virtual node for different content. Without clearing, old children remain attached, causing duplicate/interleaved items in lazy lists after scrolling.
pub fn install<R>(&self, f: impl FnOnce(&Composer) -> R) -> R
pub fn with_group<R>(&self, key: Key, f: impl FnOnce(&Composer) -> R) -> R
pub fn cranpose_with_reuse<R>( &self, key: Key, options: RecomposeOptions, f: impl FnOnce(&Composer) -> R, ) -> R
pub fn with_key<K: Hash, R>(&self, key: &K, f: impl FnOnce(&Composer) -> R) -> R
pub fn remember<T: 'static>(&self, init: impl FnOnce() -> T) -> Owned<T>
pub fn use_value_slot<'pass, T: 'static>( &'pass self, init: impl FnOnce() -> T, ) -> ValueSlotHandle<'pass, T>
pub fn with_slot_value<'pass, T: 'static, R>( &'pass self, handle: ValueSlotHandle<'pass, T>, f: impl FnOnce(&T) -> R, ) -> R
pub fn with_slot_value_mut<'pass, T: 'static, R>( &'pass self, handle: ValueSlotHandle<'pass, T>, f: impl FnOnce(&mut T) -> R, ) -> R
pub fn mutable_state_of<T: Clone + 'static>( &self, initial: T, ) -> MutableState<T>
pub fn mutable_state_list_of<T, I>(&self, values: I) -> SnapshotStateList<T>where
T: Clone + 'static,
I: IntoIterator<Item = T>,
pub fn mutable_state_map_of<K, V, I>(&self, pairs: I) -> SnapshotStateMap<K, V>
pub fn read_composition_local<T: Clone + 'static>( &self, local: &CompositionLocal<T>, ) -> T
pub fn read_static_composition_local<T: Clone + 'static>( &self, local: &StaticCompositionLocal<T>, ) -> T
pub fn current_recranpose_scope(&self) -> Option<RecomposeScope>
pub fn phase(&self) -> Phase
pub fn enter_phase(&self, phase: Phase)
pub fn subcompose_measurement<R>( &self, state: &mut SubcomposeState, slot_id: SlotId, content: impl FnOnce(&Composer) -> R, ) -> (R, Vec<NodeId>)
pub fn subcompose_in<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, f: impl FnOnce(&Composer) -> R, ) -> Result<R, NodeError>
Sourcepub fn capture_composition_locals(&self) -> CapturedCompositionLocals
pub fn capture_composition_locals(&self) -> CapturedCompositionLocals
Captures the composition-local values in scope at the current point of
composition, as an opaque snapshot that can later be replayed with
Composer::subcompose_slot_with_locals.
A SubcomposeLayout captures this while it is being composed and replays
it while subcomposing off the measure pass, so content that is
subcomposed during layout observes the same composition locals as the
SubcomposeLayout call site — matching Jetpack Compose, where a
subcomposition inherits the composition locals of the layout that
created it rather than whatever happens to be in scope during measure
(which, after composition unwinds, no longer carries ancestor providers).
Sourcepub fn subcompose_slot<R>(
&self,
slots: &Rc<SlotsHost>,
root: Option<NodeId>,
f: impl FnOnce(&Composer) -> R,
) -> Result<(R, Vec<RecomposeScope>), NodeError>
pub fn subcompose_slot<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, f: impl FnOnce(&Composer) -> R, ) -> Result<(R, Vec<RecomposeScope>), NodeError>
Subcomposes content using an isolated SlotsHost without resetting it.
Unlike subcompose_in, this preserves existing slot state across calls,
allowing efficient reuse during measurement passes. This is critical for
lazy lists where items need stable slot positions.
Sourcepub fn subcompose_slot_with_locals<R>(
&self,
slots: &Rc<SlotsHost>,
root: Option<NodeId>,
locals: Option<&CapturedCompositionLocals>,
f: impl FnOnce(&Composer) -> R,
) -> Result<(R, Vec<RecomposeScope>), NodeError>
pub fn subcompose_slot_with_locals<R>( &self, slots: &Rc<SlotsHost>, root: Option<NodeId>, locals: Option<&CapturedCompositionLocals>, f: impl FnOnce(&Composer) -> R, ) -> Result<(R, Vec<RecomposeScope>), NodeError>
Like Composer::subcompose_slot, but seeds the subcomposition with a
composition-local snapshot captured earlier (see
Composer::capture_composition_locals). When locals is None the
locals in scope right now are used, preserving the plain behavior.
pub fn skip_current_group(&self)
pub fn runtime_handle(&self) -> RuntimeHandle
pub fn set_recranpose_callback<F>(&self, callback: F)
pub fn set_recranpose_fn(&self, callback: fn(&Composer))
pub fn with_composition_locals<R>( &self, provided: Vec<ProvidedValue>, f: impl FnOnce(&Composer) -> R, ) -> R
Source§impl Composer
impl Composer
pub fn use_state<T: Clone + 'static>( &self, init: impl FnOnce() -> T, ) -> MutableState<T>
pub fn emit_node<N: Node + 'static>(&self, init: impl FnOnce() -> N) -> NodeId
pub fn emit_recyclable_node<N: Node + 'static>( &self, init: impl FnOnce() -> N, reset: impl FnOnce(&mut N), ) -> NodeId
pub fn with_node_mut<N: Node + 'static, R>( &self, id: NodeId, f: impl FnOnce(&mut N) -> R, ) -> Result<R, NodeError>
pub fn push_parent(&self, id: NodeId)
pub fn pop_parent(&self)
Sourcepub fn apply_pending_commands(&self) -> Result<(), NodeError>
pub fn apply_pending_commands(&self) -> Result<(), NodeError>
Applies any pending applier commands and runtime updates.
This is useful during measure-time subcomposition to ensure newly created nodes are available for measurement before the full composition is committed.