Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: single-line flex-container should clamp the line's cross-size #638

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/compute/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,16 @@ fn calculate_cross_size(flex_lines: &mut [FlexLine], node_size: Size<Option<f32>
})
.fold(0.0, |acc, x| acc.max(x));
}
// If the flex container is single-line, then clamp the line’s cross-size to be within the container’s computed min and max cross sizes.
if !constants.is_wrap {
let cross_axis_padding_border = constants.content_box_inset.cross_axis_sum(constants.dir);
let cross_min_size = constants.min_size.cross(constants.dir);
let cross_max_size = constants.max_size.cross(constants.dir);
flex_lines[0].cross_size = flex_lines[0].cross_size.maybe_clamp(
cross_min_size.maybe_sub(cross_axis_padding_border),
cross_max_size.maybe_sub(cross_axis_padding_border),
TtTRz marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!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">
<div style="display: flex; width: 100px; height: 100px; align-items: center; align-content: flex-start; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; height: 100px; align-items: center; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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="width: 100px; height: 100px;">
<div style="display: flex; width: 100px; height: 100px; max-height: 50%; align-items: center; align-content: flex-start;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!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="width: 100px; max-height: 100px; align-items: center; align-content: flex-start;">
<div style="height: 50px; width: 10px;"></div>
<div style="height: 150px; width: 10px;"></div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!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: block;">
<div style="display: flex; width: 100px; max-height: 100px; align-items: center; align-content: flex-start; padding: 10px; border-width: 10px;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 150px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; max-height: 100px; align-items: center; align-content: flex-start; padding: 10px; border-width: 10px; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 150px; width: 10px;"></div>
</div>
</div>


</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!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="width: 100px; height: 100px;">
<div style="display: flex; width: 100px; min-height: 100%; align-items: center; align-content: flex-start;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!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="width: 100px; min-height: 100px; align-items: center; align-content: flex-start;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!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">
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; align-content: flex-start; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; flex-wrap: no-wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; align-content: flex-start; flex-wrap: no-wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
</div>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!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">
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; align-content: flex-start; padding: 8px; border-width: 7px;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
<div style="display: flex; width: 100px; min-height: 100px; align-items: center; align-content: flex-start; padding: 8px; border-width: 7px; flex-wrap: wrap;">
<div style="height: 10px; width: 10px;"></div>
<div style="height: 20px; width: 10px;"></div>
</div>
</div>


</body>
</html>
Loading