-
Notifications
You must be signed in to change notification settings - Fork 111
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
Support CSS Grid #204
Comments
For an MVP, I'm totally fine to punt on this, and forbid mixed layouts. In fact, I'd probably prefer that, to reduce the complexity in the initial PR (which will be extremely high already). |
Style PropertiesImplementation status and priorities for implementing Y = Supported in spec and implemented in Taffy
|
Super interesting. Do you think we should split the |
I'm not quite sure. I think we'll want to think about what's efficient in terms of number of allocations vs. size of structs with properties potentially not being used. It could possibly make sense to have it an enum based on A couple of other complications:
|
Bevy has a
IMO this is a great fit for something like a SmallVec: it's stack-allocated until it gets too large, then it swaps to the heap. |
Update: I have implemented support for CSS grid style properties in the gentest scripts ( One note: CSS Grid has some extra values for some of the alignment properties that aren't supported in Flexbox. For example, both Flexbox and Grid use For now, I've left these properties as-is. And I also haven't yet added the two missing alignment properties (see above). I have added the |
I have a pretty strong preference for this. I don't think there's much value in reusing the enums, and I'd like to try to get nice type safety wherever we can. |
I agree with alice here. When we start supporting even more algorithms I'd prefer to not add noise from one into the other as it would make it even harder to reason about |
It still needs a lot of work – tidying up the code, removing all the debug logs, documenting, improving performance, and likely fixing correctness issues – but this is now working to the point that it would be reasonable for other people to try it and play around with it. Generated tests are working end-to-end. So that could be a good way to try this out. And if anyone is interested in helping, then coming up with generated tests which don't work with the current implementation would be helpful. I have also extended the test generator to support generating measure_funcs. This is triggered by adding text to a leaf node. In order to make sure that measurements match correctly, you should only use EDIT: I should add that it is absolutely not ready for code review. Some of the older code is in decent shape, but the recently added track sizing code needs a lot of cleaning up! |
Possible source of test cases here: https://github.com/web-platform-tests/wpt/tree/master/css/css-grid |
Knew that was going to happen. Reopening so we can continue to track progress. |
As it happens, all of the The arithmetic we have currently will work so long as it doesn't end up crossing zero (which will be most of the time), but will fail (placing the item in the wrong place) is it does cross zero. |
Hi! I was going trough today's commit and came across this isn't it supposed to be |
@adjabaev I believe you are correct. Well spotted! Would you like to submit a PR to fix it? |
@nicoburns done! I'm glad it helps!! 🎉 |
Phew! So it's been a long journey, but the end is in sight! I've just submitted #344 implementing baseline alignment, which means that once the following outstanding PRs have been merged:
... we are feature complete, performant enough for an initial release, and have no outstanding known issues! The remaining task will be to create some high-level tests that test complex track content-sizing scenarios, and the interaction between grid and flexbox. Although I'm keen not to go overboard with this, as with N grid features and M flexbox features it would be end up being a ridiculous amount of tests if we attempted to test all feature combinations. I suggest we stick to a strategy of mostly "unit style" generated tests that test features in isolation or in combination with a single other feature, along with few carefully crafted integration tests that test a lot of features at once (allowing us to keep the total number of them low as each test is testing many features). Once that's completed, we can close this issue and start thinking about putting out a stable |
@nicoburns this is amazing, any way to test it out with current dioxus? |
@berkus So Dioxus is currently only using Taffy for the TUI platform. All other platforms are rendering in a web view that already has built-in support for Flexbox and CSS Grid layout. Experimental native rendering which also uses Taffy exists in https://github.com/DioxusLabs/blitz. To test Grid support with the TUI or Blitz I believe you would currently need to upgrade the Taffy version yourself. |
@nicoburns I’ve been experimenting with using taffy for Android and iOS since the initial grid support was merged with hopes to replace NativeScript’s views 😅 and to bring it closer to the web. It’s not perfect but I do have a couple wrappers |
@triniwiz That's awesome. Would you be willing to contribute the bindings upstream into Taffy? |
@nicoburns I could would love to try but rather not subject anyone to those crimes committed in that repo 😭. |
@triniwiz Well contributing upstream could be an opportunity to clean things up ;) |
The remaining feature PR have been merged. And the testing / bug fixing ones have too. There's always more testing that can be done, but we have to draw the line somewhere and I think it's fair to say that we have a working CSS Grid implementation at this point. Closing this issue as completed. Further work can continue in new issues if need be. |
I'll spend some time working with @Demonthos to get it wired up into blitz! Amazing! Thanks for all the hard work here. |
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
MeasureFunc
to 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_internal
function. 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_max
computation 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 thefr
unitsFlex
variant of the newTrackSizingFunction
enum rather than being added toDimension
as 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: grid
grid-template-columns
/grid-template-rows
grid-auto-rows
/grid-auto-columns
/grid-auto-flow
grid-column
/grid-row
/grid-row-start
/grid-row-end
/grid-column-start
/grid-column-end
row-gap
/column-gap
(note:gap
shorthand implemented instead)justify-items
/justify-self
(justify-content
/align-content
/align-items
/align-self
already 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-areas
will 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_content
andjustify_content
align_items
/align_self
/justify_items
/justify_self
Resolve sizes and positions of absolutely positioned elements (Section 9 of the spec)
Support for baseline alignment Grid: baseline alignment support #344
Code quality tasks:
LengthPercentage
rather thanDimension
grid
crateexperimental_grid
?)Correctness fixes:
GridPlacement::Line
should 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 #349fr
values 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-areas
andgrid-area
Non-grid further tasks
min-content
/max-content
/fit-content
sizes (widths/heights)The text was updated successfully, but these errors were encountered: