Skip to content

Commit

Permalink
Apply aspect ratio to absolute children of flex container
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jan 5, 2023
1 parent 3a7b4d8 commit 7ff739f
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 75 deletions.
33 changes: 33 additions & 0 deletions benches/generated/aspect_ratio_flex_column_percent_fill_width.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs

This file was deleted.

4 changes: 2 additions & 2 deletions benches/generated/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/compute/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,10 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node
let (start_cross, end_cross) = if constants.is_row { (top, bottom) } else { (start, end) };

// Compute known dimensions from min/max/inherent size styles
let style_size = child_style.size.maybe_resolve(constants.container_size);
let min_size = child_style.min_size.maybe_resolve(constants.container_size);
let max_size = child_style.max_size.maybe_resolve(constants.container_size);
let aspect_ratio = child_style.aspect_ratio;
let style_size = child_style.size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio);
let min_size = child_style.min_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio);
let max_size = child_style.max_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio);
let mut known_dimensions = style_size.maybe_clamp(min_size, max_size);

// Fill in width from left/right and height from top/bottom is appropriate
Expand All @@ -1635,6 +1636,9 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node
known_dimensions.height = Some(container_height.maybe_sub(top).maybe_sub(bottom));
}

// Re-apply aspect ratio
let known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio);

let preliminary_size = compute_node_layout(
tree,
child,
Expand Down
17 changes: 17 additions & 0 deletions test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
<head/>
<body>

<div id="test-root" style="display: flex; width: 1280px; height: 720px;">
<div style="position: absolute; top: 5%; left: 5%; width: 20%; aspect-ratio: 3;"></div>
</div>

</body>
</html>
17 changes: 17 additions & 0 deletions test_fixtures/aspect_ratio_flex_column_percent_fill_width.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../scripts/gentest/test_helper.js"></script>
<link rel="stylesheet" type="text/css" href="../scripts/gentest/test_base_style.css">
<title>
Test description
</title>
<head/>
<body>

<div id="test-root" style="display: flex; width: 1280px; height: 720px;">
<div style="position: absolute; top: 5%; left: 5%; width: 20%; aspect-ratio: 3;"></div>
</div>

</body>
</html>
48 changes: 48 additions & 0 deletions tests/generated/aspect_ratio_flex_column_percent_fill_width.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 0 additions & 42 deletions tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/generated/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7ff739f

Please sign in to comment.