use dioxus_native_core::NodeId;
use freya_dom::prelude::FreyaDOM;
use freya_engine::prelude::*;
use freya_layout::Layers;
use torin::prelude::Area;
use crate::ViewportsCollection;
pub fn process_render<HookOptions>(
viewports_collection: &ViewportsCollection,
dom: &FreyaDOM,
font_collection: &mut FontCollection,
layers: &Layers,
hook_options: &mut HookOptions,
render_hook: impl Fn(
&FreyaDOM,
&NodeId,
&Area,
&mut FontCollection,
&ViewportsCollection,
&mut HookOptions,
),
) {
let mut layers_nums: Vec<&i16> = layers.layers.keys().collect();
layers_nums.sort();
for layer_num in &layers_nums {
let layer = layers.layers.get(layer_num).unwrap();
'elements: for node_id in layer {
let viewports = viewports_collection.get(node_id);
let layout = dom.layout();
let areas = layout.get(*node_id);
if let Some(areas) = areas {
if let Some((_, viewports)) = viewports {
for viewport_id in viewports {
let viewport = viewports_collection.get(viewport_id).unwrap().0;
if let Some(viewport) = viewport {
if !viewport.intersects(&areas.area) {
continue 'elements;
}
}
}
}
render_hook(
dom,
node_id,
&areas.visible_area(),
font_collection,
viewports_collection,
hook_options,
)
}
}
}
}