use cranpose_core::{NodeId, collections::map::HashMap};
use cranpose_ui_graphics::Rect;
use crate::{graph::ProjectiveTransform, scene_store::LayerRef};
pub(crate) fn for_each_node_window_bounds(
layer: LayerRef<'_>,
to_window: ProjectiveTransform,
surfaces: &HashMap<NodeId, ProjectiveTransform>,
visit: &mut dyn FnMut(NodeId, Rect),
) {
let shown = layer.node_id().and_then(|node_id| surfaces.get(&node_id));
let to_window = shown
.copied()
.unwrap_or_else(|| layer.transform_to_parent().then(to_window));
if let Some(node_id) = layer.node_id() {
visit(node_id, to_window.bounds_for_rect(layer.node_rect()));
}
for child in layer.children() {
for_each_node_window_bounds(child, to_window, surfaces, visit);
}
}