Skip to content

Commit

Permalink
[css-grid-3] Add intrinsic auto-repeater definition
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Sep 17, 2024
1 parent 0d3ba6e commit 79dd950
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion css-grid-3/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,90 @@ Masonry Track Specification</h3>
Initial: auto
Applies to: grid containers
Inherited: no
Percentages: refer to correspodning dimension of the content area
Percentages: refer to corresponding dimension of the content area
Computed value: a [=computed track list=]
Canonical order: per grammar
Animation type: if the list lengths match, by computed value type per item; discrete otherwise
</pre>

'masonry-auto-tracks' has the same syntax and interpretation as 'grid-auto-columns'.


<h4 id=masonry-intrinsic-repeat>
Intrinsic Tracks and repeat()</h4>

In Grid Layout,
all [=grid items=] are placed in the grid
<em>before</em> the grid tracks are sized.
This implies that ''repeat()/auto-fill''/''repeat()/auto-fit'' repetition
can't include intrinsically sized tracks such as ''grid-template-rows/auto''
(either in the ''repeat()'' function <em>or</em> alongside it
in the fixed portion of the track list),
as that would require the layout algorithm
to have already determined which items would go in those tracks,
to determine how large the tracks are,
to determine how many repetitions fit in the available space.

In Masonry Layout,
as [=masonry item=] placement and layout are intertwined and somewhat simplified,
this restriction is no longer strictly required.
It requires a slightly heuristic definition of sizing,
but auto repetition <em>can</em> include intrinsically-sized tracks
in a [=masonry container=]
(and the initial value of 'masonry-template-tracks' uses this!).

<div algorithm="determine intrinsic repetitions">
To determine the number of repetitions
that a ''repeat()'' function resolves to,
run layout as defined in [[#track-sizing-performance]],
with the following changes:

* Expand ''repeat()/auto-fill''/''repeat()/auto-fit'' repeat functions once.
* Ignore item placement.
(That is, assume all items have ''masonry-track: auto''.)
* If a [=masonry item=] has a span larger than 1,
then for each of its intrinsic sizes
that it would contribute to the [=virtual masonry item=],
first subtract the combined size of the gaps it would span,
and divide by its span.
Then treat it as being a span-1 item with those sizes.

Any intrinsically-sized tracks are then treated as having the size
calculated by this simplified layout
(including those in ''repeat()'' arguments,
taking from their corresponding single repetition)
for the purpose of determining how many repetitions
the ''repeat()'' functions resolve to.
</div>

<details class=note>
<summary>Motivation</summary>

This simplified layout heuristic is defined to be "good enough",
while remaining fast and consistent.

Ignoring placement is required just to make the concept coherent;
before you know how many repetitions you need,
you can't tell what track an item with a definite placement
will end up in.

By chopping spanning items into span-1 items,
this avoids the possible need to expand a repeat() multiple times,
and the incoherent possibility of getting different sizes
for the same keyword across the repetitions.

It also makes the layout as a whole significantly cheaper,
as you only need to consider each unique track size;
you don't even <em>really</em> need to do any repeat() expansion.
That is, in ''auto repeat(auto-fill, min-content auto)'',
both of the ''grid-template-rows/auto'' keywords
will resolve to the same size under this heuristic layout;
you can just figure out what
a ''masonry-template-tracks: auto''
and ''masonry-template-tracks: min-content''
would each result in,
and use those sizes.
</details>
</section>

<h3 id="subgrids">
Expand Down

0 comments on commit 79dd950

Please sign in to comment.