nativeview-layout 0.1.0-rc.1

Shared NodeStore layout layer: StoreLayoutEngine / TextMeasurer traits and the default direct Taffy engine
Documentation
//! CSS Transforms Level 1 ยง2 containing-block helpers for [`super::TaffyStoreLayout`].
//!
//! A box-generating node with a non-identity `Transform` row establishes a containing block for
//! both `position: absolute` and `position: fixed` descendants.

use nativeview_store::{NodeId, NodeStore};
use nativeview_tables::tables::{
    Layout as NvLayout, Position as NvPosition, Transform as TransformTable, is_display_contents,
    is_node_display_none,
};
use nativeview_tables::transform::Transform2D;

/// Returns `true` when `id` carries a non-identity `Transform` row in `store`.
///
/// Tracks raw `Transform` state independent of `Display::None` / `Display::Contents` so
/// `TaffyStoreLayout::was_transformed` never goes stale across `display: none <-> flex/block`
/// toggles (box-generation gating happens in `StyleView::is_containing_block`).
#[inline]
pub(super) fn has_store_transform(store: &NodeStore, id: NodeId) -> bool {
    store.try_row::<TransformTable>(id).is_some_and(|t| {
        !Transform2D {
            translate_x: t.translate_x(),
            translate_y: t.translate_y(),
            scale_x: t.scale_x(),
            scale_y: t.scale_y(),
            rotate_deg: t.rotate_deg(),
            origin_x: t.origin_x(),
            origin_y: t.origin_y(),
        }
        .is_identity()
    })
}

/// Returns `true` iff any live non-`display: none` descendant of `id` is out-of-flow
/// (`position: absolute | fixed`). Fast O(1) exit on leaves so 120 Hz transform animations on
/// leaf cards never dirty Taffy layout.
pub(super) fn subtree_has_out_of_flow(store: &NodeStore, id: NodeId) -> bool {
    let kids = store.children(id);
    if kids.is_empty() {
        return false;
    }
    let mut stack = [NodeId::NULL; 64];
    let mut overflow: Vec<NodeId> = Vec::new();
    let mut len = 0usize;
    let push = |n: NodeId, s: &mut [NodeId; 64], ov: &mut Vec<NodeId>, l: &mut usize| {
        if *l < 64 {
            s[*l] = n;
        } else {
            ov.push(n);
        }
        *l += 1;
    };
    for &c in kids {
        push(c, &mut stack, &mut overflow, &mut len);
    }
    let mut visited = 0usize;
    while len > 0 && visited < 4096 {
        len -= 1;
        let Some(cur) = (if len < 64 {
            Some(stack[len])
        } else {
            overflow.pop()
        }) else {
            break;
        };
        visited += 1;
        if !store.is_live(cur) || is_node_display_none(store, cur) {
            continue;
        }
        if !is_display_contents(store, cur)
            && store
                .try_row::<NvLayout>(cur)
                .is_some_and(|l| matches!(l.position(), NvPosition::Absolute | NvPosition::Fixed))
        {
            return true;
        }
        for &c in store.children(cur) {
            push(c, &mut stack, &mut overflow, &mut len);
        }
    }
    visited >= 4096
}