Skip to content

Commit

Permalink
Rename abs_x/abs_y to cumulative_x/cumulative_y
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 23, 2023
1 parent 3123056 commit 30c7948
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/compute/taffy_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,32 @@ fn perform_taffy_tree_hidden_layout(tree: &mut Taffy, node: NodeId) {
}

/// Rounds the calculated [`Layout`] to exact pixel values
///
/// In order to ensure that no gaps in the layout are introduced we:
/// - Always round based on the absolute coordinates rather than parent-relative coordinates
/// - Always round based on the cumulative x/y coordinates (relative to the viewport) rather than
/// parent-relative coordinates
/// - Compute width/height by first rounding the top/bottom/left/right and then computing the difference
/// rather than rounding the width/height directly
///
/// See <https://github.com/facebook/yoga/commit/aa5b296ac78f7a22e1aeaf4891243c6bb76488e2> for more context
fn round_layout(tree: &mut Taffy, node_id: NodeId, abs_x: f32, abs_y: f32) {
///
/// In order to prevent innacuracies caused by rounding already-rounded values, we read from `unrounded_layout`
/// and write to `final_layout`.
fn round_layout(tree: &mut Taffy, node_id: NodeId, cumulative_x: f32, cumulative_y: f32) {
let node = &mut tree.nodes[node_id.into()];
let unrounded_layout = node.unrounded_layout;
let layout = &mut node.final_layout;

let abs_x = abs_x + unrounded_layout.location.x;
let abs_y = abs_y + unrounded_layout.location.y;
let cumulative_x = cumulative_x + unrounded_layout.location.x;
let cumulative_y = cumulative_y + unrounded_layout.location.y;

layout.location.x = round(unrounded_layout.location.x);
layout.location.y = round(unrounded_layout.location.y);
layout.size.width = round(abs_x + unrounded_layout.size.width) - round(abs_x);
layout.size.height = round(abs_y + unrounded_layout.size.height) - round(abs_y);
layout.size.width = round(cumulative_x + unrounded_layout.size.width) - round(cumulative_x);
layout.size.height = round(cumulative_y + unrounded_layout.size.height) - round(cumulative_y);

let child_count = tree.child_count(node_id).unwrap();
for index in 0..child_count {
let child = tree.child(node_id, index);
round_layout(tree, child, abs_x, abs_y);
round_layout(tree, child, cumulative_x, cumulative_y);
}
}

0 comments on commit 30c7948

Please sign in to comment.