-
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * 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 { | ||
|
|
||
| // Represents a resolved grid track size during layout computation. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: If all this after resolution step, can we make fields in struct const? That way, we would know, that it isn't mutated after-the-fact, during the layout algorithm, like some other structures.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, made the |
||
| // Includes variables used by the track sizing algorithm. | ||
| // https://www.w3.org/TR/css-grid-1/#algo-track-sizing | ||
| struct GridTrack { | ||
| GridTrackSize trackSize; | ||
| float baseSize = 0.0f; | ||
| float growthLimit = 0.0f; | ||
| bool infinitelyGrowable = false; | ||
|
|
||
| explicit GridTrack(const GridTrackSize& ts) : trackSize(ts) {} | ||
| }; | ||
|
|
||
| } // namespace facebook::yoga | ||
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.