Skip to content

Commit

Permalink
Fix calculation of auto-fill/auto-fit repetition count when conta…
Browse files Browse the repository at this point in the history
…iner has a definite percentage size
  • Loading branch information
nicoburns committed Oct 22, 2024
1 parent c14a177 commit 6043567
Show file tree
Hide file tree
Showing 6 changed files with 718 additions and 3 deletions.
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## Unreleased

### Fixes

Check failure on line 5 in RELEASES.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Headings should be surrounded by blank lines

RELEASES.md:5 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "### Fixes"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md022.md
- Fix calculation of `auto-fill`/`auto-fit` repetition count when container has a definite percentage size

Check failure on line 6 in RELEASES.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Lists should be surrounded by blank lines

RELEASES.md:6 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "- Fix calculation of `auto-fil..."] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md032.md

## 0.6.0

### Highlights
Expand Down
8 changes: 5 additions & 3 deletions src/compute/grid/explicit_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::style_helpers::TaffyAuto;
use crate::util::sys::Vec;
use crate::util::MaybeMath;
use crate::util::ResolveOrZero;
use crate::GridContainerStyle;
use crate::{GridContainerStyle, MaybeResolve};

#[cfg(not(feature = "std"))]
use num_traits::float::FloatCore;
Expand Down Expand Up @@ -91,8 +91,10 @@ pub(crate) fn compute_explicit_grid_size_in_axis(
// Otherwise, if the grid container has a definite min size in the relevant axis:
// - then the number of repetitions is the smallest possible positive integer that fulfills that minimum requirement
// Otherwise, the specified track list repeats only once.
let size_is_maximum =
style.size().get_abs(axis).into_option().is_some() || style.max_size().get_abs(axis).into_option().is_some();
let style_size_is_definite = style.size().get_abs(axis).maybe_resolve(inner_container_size.get_abs(axis)).is_some();
let style_max_size_is_definite =
style.max_size().get_abs(axis).maybe_resolve(inner_container_size.get_abs(axis)).is_some();
let size_is_maximum = style_size_is_definite | style_max_size_is_definite;

// Determine the number of repetitions
let num_repetitions: u16 = match inner_container_size.get_abs(axis) {
Expand Down
26 changes: 26 additions & 0 deletions test_fixtures/grid/grid_auto_fit_definite_percentage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!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="height: 300px; width: 730px;">
<div style="display: grid; width: 100%; height: 100%; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 10px; background-color: yellow;">
<div style="display: block; background-color: teal;"></div>
<div style="display: block; background-color: pink;"></div>
<div style="display: block; background-color: royalblue;"></div>
<div style="display: block; background-color: violet;"></div>
<div style="display: block; background-color: beige;"></div>
<div style="display: block; background-color: burlywood;"></div>
<div style="display: block; background-color: lightslategrey;"></div>
<div style="display: block; background-color: lightseagreen;"></div>
</div>
</div>

</body>
</html>
26 changes: 26 additions & 0 deletions test_fixtures/grid/taffy_issue_721.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!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="height: 300px; width: 730px;">
<div style="display: grid; width: 100%; height: 100%; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 10px; background-color: yellow;">
<div style="display: block; background-color: teal;"></div>
<div style="display: block; background-color: pink;"></div>
<div style="display: block; background-color: royalblue;"></div>
<div style="display: block; background-color: violet;"></div>
<div style="display: block; background-color: beige;"></div>
<div style="display: block; background-color: burlywood;"></div>
<div style="display: block; background-color: lightslategrey;"></div>
<div style="display: block; background-color: lightseagreen;"></div>
</div>
</div>

</body>
</html>
1 change: 1 addition & 0 deletions tests/generated/grid/mod.rs

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

Loading

0 comments on commit 6043567

Please sign in to comment.