Skip to main content

IncrementalLayout

Struct IncrementalLayout 

Source
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

Source

pub fn new() -> Self

Create an empty incremental layout engine.

Source

pub fn with_capacity(node_cap: usize) -> Self

Create with pre-allocated capacity.

Source

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.

Source

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.

Source

pub fn remove_node(&mut self, id: NodeId)

Remove a node and evict its cache entry.

Source

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.

Source

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.

Source

pub fn mark_dirty(&mut self, id: NodeId)

Force-mark a node as dirty without hash comparison.

Source

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.

Source

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.

Source

pub fn is_dirty(&self, id: NodeId) -> bool

Check if a node is currently dirty.

Source

pub fn get_or_compute<F>( &mut self, id: NodeId, area: Rect, compute: F, ) -> Vec<Rect>
where F: FnOnce(Rect) -> Vec<Rect>,

Get the cached layout for a node, or compute and cache it.

A cache hit requires:

  1. The node is not dirty.
  2. The area matches the previously cached area.
  3. force_full is not enabled.

On a cache miss, compute is called with the area and the result is stored. The node is cleaned after computation.

Source

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.

Source

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.

Source

pub fn result_hash(&self, id: NodeId) -> Option<u64>

Get the hash of a node’s last computed result.

Source

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.

Source

pub fn force_full(&self) -> bool

Whether force-full mode is enabled.

Source

pub fn stats(&self) -> IncrementalStats

Current-pass statistics.

Source

pub fn reset_stats(&mut self)

Reset per-pass statistics to zero.

Source

pub fn clean_all(&mut self)

Mark all nodes clean and advance the generation.

Source

pub fn invalidate_all(&mut self)

Mark all nodes dirty (forces full recomputation on next pass).

Source

pub fn clear_cache(&mut self)

Clear the entire result cache (frees memory).

Source

pub fn graph(&self) -> &DepGraph

Borrow the underlying dependency graph.

Source

pub fn graph_mut(&mut self) -> &mut DepGraph

Mutable access to the dependency graph.

Source

pub fn cache_len(&self) -> usize

Number of cached entries.

Source

pub fn node_count(&self) -> usize

Number of live nodes in the dependency graph.

Trait Implementations§

Source§

impl Debug for IncrementalLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IncrementalLayout

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.