diff --git a/crates/torin/src/measure.rs b/crates/torin/src/measure.rs index 78e17611e..1b6d24d12 100644 --- a/crates/torin/src/measure.rs +++ b/crates/torin/src/measure.rs @@ -370,13 +370,17 @@ where let is_last_child = last_child == Some(*child_id); - let inner_area = initial_phase_inner_area; + let (parent_area, available_parent_area) = if child_data.position.is_absolute() { + (&initial_phase_area, &initial_phase_area) + } else { + (&initial_phase_inner_area, &initial_phase_available_area) + }; let (_, child_areas) = self.measure_node( *child_id, &child_data, - &inner_area, - &initial_phase_available_area, + parent_area, + available_parent_area, false, parent_is_dirty, Phase::Initial, @@ -550,12 +554,18 @@ where } } + let (parent_area, parent_available_area) = if child_data.position.is_absolute() { + (&*area, &*area) + } else { + (&*inner_area, &adapted_available_area) + }; + // Final measurement let (child_revalidated, mut child_areas) = self.measure_node( child_id, &child_data, - inner_area, - &adapted_available_area, + parent_area, + parent_available_area, must_cache_children, parent_is_dirty, Phase::Final, diff --git a/crates/torin/tests/position.rs b/crates/torin/tests/position.rs index 57e59bd2f..bf8858417 100644 --- a/crates/torin/tests/position.rs +++ b/crates/torin/tests/position.rs @@ -99,18 +99,18 @@ pub fn position() { assert_eq!( layout.get(2).unwrap().area, - Rect::new(Point2D::new(100.0, 150.0), Size2D::new(200.0, 200.0)), + Rect::new(Point2D::new(70.0, 120.0), Size2D::new(200.0, 200.0)), ); assert_eq!( layout.get(3).unwrap().area.round(), - Rect::new(Point2D::new(700.0, 150.0), Size2D::new(200.0, 200.0)), + Rect::new(Point2D::new(730.0, 120.0), Size2D::new(200.0, 200.0)), ); assert_eq!( layout.get(4).unwrap().area.round(), - Rect::new(Point2D::new(700.0, 650.0), Size2D::new(200.0, 200.0)), + Rect::new(Point2D::new(730.0, 680.0), Size2D::new(200.0, 200.0)), ); assert_eq!( layout.get(5).unwrap().area.round(), - Rect::new(Point2D::new(100.0, 650.0), Size2D::new(200.0, 200.0)), + Rect::new(Point2D::new(70.0, 680.0), Size2D::new(200.0, 200.0)), ); } diff --git a/examples/position.rs b/examples/position.rs index ebba69810..65cb63e37 100644 --- a/examples/position.rs +++ b/examples/position.rs @@ -45,6 +45,23 @@ fn app() -> Element { position: "absolute", position_bottom: "10", position_left: "10", + padding: "20", + + rect { + height: "100%", + width: "100%", + corner_radius: "12", + background: "red", + position: "absolute", + position_top: "0", + position_left: "0", + } + + rect { + height: "20%", + width: "20%", + background: "blue", + } } } )