As per #28 (comment), we would like to support CSS Grid in Taffy. This is a modified version of research I did on supporting this in Stretch (vislyhq/stretch#63 (comment)). Which I thought I would copy and update here as a starting point.
Status (22nd Dec 2022)
The implementation is largely feature complete, and a pre-release version of Taffy containing the CSS Grid implementation has been released. There is now a lot of testing and validating to be done before it is ready for a stable release.
Blocking questions / issues
Update: Both of these solutions were implemented as part of #246. Grid's integration with other layout modes is now unblocked.
Useful Resources:
MVP Implementation Plan
Code quality tasks:
Correctness fixes:
To test thoroughly
Performance related tasks:
Further tasks
Grid related further tasks
- Support for named grid lines
- Support for
grid-template-areas and grid-area
- Support for CSS Grid Level 2 (subgrids)
Non-grid further tasks
- Support for
min-content/max-content/fit-content sizes (widths/heights)
- Add sub-directory support to gentests to separate grid and flexbox tests.
As per #28 (comment), we would like to support CSS Grid in Taffy. This is a modified version of research I did on supporting this in Stretch (vislyhq/stretch#63 (comment)). Which I thought I would copy and update here as a starting point.
Status (22nd Dec 2022)
The implementation is largely feature complete, and a pre-release version of Taffy containing the CSS Grid implementation has been released. There is now a lot of testing and validating to be done before it is ready for a stable release.
Blocking questions / issues
How should Grid interact with intrinsically sized leaf nodes. The spec seems to define child nodes as having both amin-size(e.g. text node that wraps at all opportunities) andmax-size(e.g. a text node that doesn't wrap at all). Possibly these would need to be added to nodes as additional "measure functions"? Or possibly they could both be assumed to be equal to the one measure functions at first? Possibly min can be obtained by passing the MeasureFuncwidth: 0, height: 0, and max can be obtained by passing the MeasureFuncwidth: undefined, height: undefined? But perhaps it would be better to redefine the MeasureFunc to "sizing constraints" (https://www.w3.org/TR/css-sizing-3/#constraints) in addition a definite size constraint if one is available? https://www.w3.org/TR/css-sizing-3/#intrinsic-contributionPlan is to update
MeasureFuncto take the sizing constraint as parameter (which it can then use or ignore as it sees fit).The interaction between nested Grid and Flexbox nodes. The comment at https://github.com/DioxusLabs/taffy/blob/main/src/flexbox.rs#L463-L466 suggests that the Flex implementation could be made more spec compliant by passing min-content/max-content constraints into to the top (presumably of thecompute_internalfunction. I feel like this may be a prerequisite to getting Grid and Flex to play nicely with each other in indefinitely sized contexts. Tracking issue here: Fixmin_maxcomputation when resolving flexible lengths to follow the spec #122Plan is not to worry about integration at first, but it's likely that we'll adjust the Flexbox implementation to take sizing constraints as input as suggested above when we are ready to integrate.
Update: Both of these solutions were implemented as part of #246. Grid's integration with other layout modes is now unblocked.
Useful Resources:
MVP Implementation Plan
Extend the Style and Geometry sections of Stretch to include definitions for CSS Grid styles, while ensuring that the existing Flex implementation continues to work:
This has been implemented as thefrunitsFlexvariant of the newTrackSizingFunctionenum rather than being added toDimensionas it only applies to grid templates, and it turns out there are also a bunch of other options (likeminmax) that apply there but not elsewhere.display: gridgrid-template-columns/grid-template-rowsgrid-auto-rows/grid-auto-columns/grid-auto-flowgrid-column/grid-row/grid-row-start/grid-row-end/grid-column-start/grid-column-endrow-gap/column-gap(note:gapshorthand implemented instead)justify-items/justify-self(justify-content/align-content/align-items/align-selfalready implemented for flexbox). Note: *-items and *-self properties align grid items (children) within their cell. *-content properties align cells (rows/columns) within the grid container. I think that all are set to stretch to fit by default.We can probably ignore the shorthand properties for now, as their functionality is covered by the longhand equivalents above.
Resolve the explicit grid:
grid-template-columns/grid-template-rows(Sections 7.1-7.4 of the spec).repeat()syntaxrepeat(integer)Grid: Add support for repeat() with an integer repetition count #342repeat(auto-fill)repeat(auto-fit)(Not strictly necessary features like named grid lines/areas defined by
grid-template-areaswill be left until later.)Implement grid placement. Matching Grid Items (child nodes of the grid) to Grid Areas. This may include generating extra rows and columns that form the "implicit grid" if any Grid Items are placed outside of the bounds of the "explicit grid". (note: the "implicit grid" is the whole grid, not just the extra bit) (Sections 7.5-8.5 of the spec)
Resolve the track sizing functions for all grid tracks (explicit and implicit).
Implement the Grid Sizing Algorithm to determine the size of each Grid Area. This mostly consists of the Track Sizing Algorithm, iterated a few times. A Grid Track is a row or column of the grid. Gutters sizes should also be resolved here, although this is relatively simple. (Section 11 of the spec).
fit-content()track sizing functionsResolve Grid Item (node) sizes and positions, by summing the size of the track and gutters in their grid area (in each axis), and taking into accounts spacing and alignment properties (Section 10 of the spec).
align_contentandjustify_contentalign_items/align_self/justify_items/justify_selfResolve sizes and positions of absolutely positioned elements (Section 9 of the spec)
Support for baseline alignment Grid: baseline alignment support #344
Code quality tasks:
LengthPercentagerather thanDimensiongridcrateexperimental_grid?)Correctness fixes:
GridPlacement::Lineshould useNonZeroI16. Grid/refactor coordinate handling #301To test thoroughly
Repetition ((covered by unit tests. could still do with gentests but lower priority)repeat(integer),repeat(auto-fill)andrepeat(auto-fit))Placement using Span(covered by unit tests. could still do with gentests but lower priority)Flex-column childrenWe don't match chrome on this, but our behaviour (actually containing the width of the child node) seems better, and matches the spec as best as I can tell.fit-content(percentage)and for items spanning percentage gaps #335fit-content(percentage)and for items spanning percentage gaps #335minmax()tracks Grid: Fixes for minmax, fr proportions and distributing space across multiple tracks #349frvalues summing to less than 1 Grid: Fixes for minmax, fr proportions and distributing space across multiple tracks #349Performance related tasks:
Further tasks
Grid related further tasks
grid-template-areasandgrid-areaNon-grid further tasks
min-content/max-content/fit-contentsizes (widths/heights)