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;
#[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()
})
}
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
}