Skip to content

Commit

Permalink
feat: Simply make the viewports inheritance a bit faster (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Sep 18, 2023
1 parent c0cd1e5 commit 1247940
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions crates/core/src/viewports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ pub fn calculate_viewports(
let node_areas = layout.get(*node_id);

if let Some((node, node_areas)) = node.zip(node_areas) {
let style = node.get::<Style>().unwrap();
let node_type = &*node.node_type();

if let NodeType::Element(..) = node_type {
let style = node.get::<Style>().unwrap();

// Clip any overflow from it's children
if style.overflow == OverflowMode::Clip {
viewports_collection
Expand All @@ -38,14 +39,16 @@ pub fn calculate_viewports(
.0 = Some(node_areas.area);
}

for child in node.children() {
if viewports_collection.contains_key(node_id) {
let mut inherited_viewports =
viewports_collection.get(node_id).unwrap().1.clone();

inherited_viewports.push(*node_id);
// Pass viewports to the children
if let Some((_, mut inherited_viewports)) =
viewports_collection.get(node_id).cloned()
{
// Add the itself
inherited_viewports.push(*node_id);

viewports_collection.insert(child.id(), (None, inherited_viewports));
for child in node.children() {
viewports_collection
.insert(child.id(), (None, inherited_viewports.clone()));
}
}
}
Expand Down

0 comments on commit 1247940

Please sign in to comment.