-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CSS Grid algorithm 1/N: data structures #1923
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
Open
intergalacticspacehighway
wants to merge
2
commits into
facebook:main
Choose a base branch
from
intergalacticspacehighway:css-grid-1-data-structures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <yoga/enums/Dimension.h> | ||
| #include <yoga/node/Node.h> | ||
| #include <cstddef> | ||
| #include <map> | ||
| #include <vector> | ||
|
|
||
| namespace facebook::yoga { | ||
|
|
||
| // A grid item with its resolved position in the grid. Positions are set by the | ||
| // auto-placement algorithm and consumed by the track sizing algorithm. | ||
| struct GridItem { | ||
| size_t columnStart; | ||
| size_t columnEnd; | ||
| size_t rowStart; | ||
| size_t rowEnd; | ||
| yoga::Node* node; | ||
|
|
||
| // Additional offset added to item to align baselines | ||
| // https://www.w3.org/TR/css-grid-1/#algo-baseline-shims | ||
| float baselineShim = 0.0f; | ||
|
|
||
| // Flags used for optimizations in track sizing algorithm. | ||
| bool crossesIntrinsicRow = false; | ||
| bool crossesIntrinsicColumn = false; | ||
| bool crossesFlexibleRow = false; | ||
| bool crossesFlexibleColumn = false; | ||
|
|
||
| GridItem( | ||
| size_t columnStart, | ||
| size_t columnEnd, | ||
| size_t rowStart, | ||
| size_t rowEnd, | ||
| yoga::Node* node, | ||
| float baselineShim = 0.0f) | ||
| : columnStart(columnStart), | ||
| columnEnd(columnEnd), | ||
| rowStart(rowStart), | ||
| rowEnd(rowEnd), | ||
| node(node), | ||
| baselineShim(baselineShim) {} | ||
|
|
||
| // Helper functions used by the track sizing algorithm | ||
| bool crossesIntrinsicTrack(Dimension dimension) const { | ||
| return dimension == Dimension::Width ? crossesIntrinsicColumn | ||
| : crossesIntrinsicRow; | ||
| } | ||
| bool crossesFlexibleTrack(Dimension dimension) const { | ||
| return dimension == Dimension::Width ? crossesFlexibleColumn | ||
| : crossesFlexibleRow; | ||
| } | ||
| }; | ||
|
|
||
| // Baseline sharing groups - items grouped by their starting row for the | ||
| // resolve intrinsic size step in track sizing algorithm. | ||
| // https://www.w3.org/TR/css-grid-1/#algo-baseline-shims | ||
| using BaselineItemGroups = std::map<size_t, std::vector<GridItem*>>; | ||
|
|
||
| } // namespace facebook::yoga | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <yoga/style/GridTrackSize.h> | ||
|
|
||
| namespace facebook::yoga { | ||
|
|
||
| // https://www.w3.org/TR/css-grid-1/#algo-track-sizing | ||
| struct GridTrack { | ||
| // Sizing functions for this track, immutable after construction | ||
| const GridTrackSize trackSize; | ||
|
|
||
| // Mutable state used by the track sizing algorithm | ||
| // https://www.w3.org/TR/css-grid-1/#base-size | ||
| float baseSize = 0.0f; | ||
| // https://www.w3.org/TR/css-grid-1/#growth-limit | ||
| float growthLimit = 0.0f; | ||
| // https://www.w3.org/TR/css-grid-1/#infinitely-growable | ||
| bool infinitelyGrowable = false; | ||
|
|
||
| explicit GridTrack(const GridTrackSize& ts) : trackSize(ts) {} | ||
| }; | ||
|
|
||
| } // namespace facebook::yoga |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need a full back-reference to the Yoga node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use node reference to call measure methods in
TrackSizingalgorithm. e.g. calling calculateLayoutInternal. Also to get style from node likeitem.node->hasDefiniteLength(),item.node->style().computeMarginForAxisetc in track sizing.