pub struct IncrementalLayout { /* private fields */ }Expand description
Incremental layout engine.
Combines a DepGraph for dirty tracking with a per-node result
cache. The user drives the DFS tree walk; at each node,
get_or_compute decides whether to return
the cached result or call the supplied compute closure.
Implementations§
Source§impl IncrementalLayout
impl IncrementalLayout
Sourcepub fn with_capacity(node_cap: usize) -> Self
pub fn with_capacity(node_cap: usize) -> Self
Create with pre-allocated capacity.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Create from environment configuration.
Reads FRANKENTUI_FULL_LAYOUT. When set to "1", "true", or
"yes" (case-insensitive), force-full mode is enabled and all
get_or_compute calls bypass the cache.
Sourcepub fn add_node(&mut self, parent: Option<NodeId>) -> NodeId
pub fn add_node(&mut self, parent: Option<NodeId>) -> NodeId
Add a layout node, optionally with a parent.
When a parent is provided, a dependency edge is added so that dirtying the parent also dirties this child.
Sourcepub fn remove_node(&mut self, id: NodeId)
pub fn remove_node(&mut self, id: NodeId)
Remove a node and evict its cache entry.
Sourcepub fn add_dependency(
&mut self,
from: NodeId,
to: NodeId,
) -> Result<(), CycleError>
pub fn add_dependency( &mut self, from: NodeId, to: NodeId, ) -> Result<(), CycleError>
Add a custom dependency edge: from depends on to.
Use this for bidirectional flex-sibling relationships or cross-subtree dependencies.
Sourcepub fn mark_changed(&mut self, id: NodeId, kind: InputKind, new_hash: u64)
pub fn mark_changed(&mut self, id: NodeId, kind: InputKind, new_hash: u64)
Mark a node’s input as changed (hash-deduplicated).
The node will not be dirtied if new_hash matches the stored
hash for this InputKind.
Sourcepub fn mark_dirty(&mut self, id: NodeId)
pub fn mark_dirty(&mut self, id: NodeId)
Force-mark a node as dirty without hash comparison.
Sourcepub fn mark_dirty_with_ancestors(&mut self, id: NodeId)
pub fn mark_dirty_with_ancestors(&mut self, id: NodeId)
Mark a node dirty and also dirty all its ancestors up to the root. This implements the “flex sibling” pattern: when a child changes, its parent must recompute, which propagates to all siblings via parent→child edges.
Sourcepub fn propagate(&mut self) -> Vec<NodeId>
pub fn propagate(&mut self) -> Vec<NodeId>
Propagate dirtiness from pending nodes to all transitive
dependents. Must be called before get_or_compute.
Returns the dirty set in DFS pre-order.
Sourcepub fn get_or_compute<F>(
&mut self,
id: NodeId,
area: Rect,
compute: F,
) -> Vec<Rect>
pub fn get_or_compute<F>( &mut self, id: NodeId, area: Rect, compute: F, ) -> Vec<Rect>
Get the cached layout for a node, or compute and cache it.
A cache hit requires:
- The node is not dirty.
- The area matches the previously cached area.
force_fullis not enabled.
On a cache miss, compute is called with the area and the
result is stored. The node is cleaned after computation.
Sourcepub fn cached_rects(&self, id: NodeId) -> Option<&[Rect]>
pub fn cached_rects(&self, id: NodeId) -> Option<&[Rect]>
Retrieve the cached result for a node without recomputing.
Returns None if the node has no cached result.
Sourcepub fn result_changed(&self, id: NodeId) -> bool
pub fn result_changed(&self, id: NodeId) -> bool
Check whether a node’s last computed result changed compared to its previous result. Useful for detecting when a parent must propagate layout changes to children.
Sourcepub fn result_hash(&self, id: NodeId) -> Option<u64>
pub fn result_hash(&self, id: NodeId) -> Option<u64>
Get the hash of a node’s last computed result.
Sourcepub fn set_force_full(&mut self, force: bool)
pub fn set_force_full(&mut self, force: bool)
Enable or disable force-full mode.
When enabled, every get_or_compute call recomputes from
scratch, ignoring the cache. Useful for debugging or as a
fallback path.
Sourcepub fn force_full(&self) -> bool
pub fn force_full(&self) -> bool
Whether force-full mode is enabled.
Sourcepub fn stats(&self) -> IncrementalStats
pub fn stats(&self) -> IncrementalStats
Current-pass statistics.
Sourcepub fn reset_stats(&mut self)
pub fn reset_stats(&mut self)
Reset per-pass statistics to zero.
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Mark all nodes dirty (forces full recomputation on next pass).
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear the entire result cache (frees memory).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of live nodes in the dependency graph.