diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index e43a38e64e..82f8dd9619 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include using namespace facebook; using namespace facebook::yoga; diff --git a/yoga/algorithm/grid/GridItem.h b/yoga/algorithm/grid/GridItem.h new file mode 100644 index 0000000000..72f92e4964 --- /dev/null +++ b/yoga/algorithm/grid/GridItem.h @@ -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 +#include +#include +#include +#include + +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>; + +} // namespace facebook::yoga diff --git a/yoga/algorithm/grid/GridTrack.h b/yoga/algorithm/grid/GridTrack.h new file mode 100644 index 0000000000..056721013e --- /dev/null +++ b/yoga/algorithm/grid/GridTrack.h @@ -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 + +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 diff --git a/yoga/style/GridTrack.h b/yoga/style/GridTrackSize.h similarity index 87% rename from yoga/style/GridTrack.h rename to yoga/style/GridTrackSize.h index 2a2bafb50c..a889054ac5 100644 --- a/yoga/style/GridTrack.h +++ b/yoga/style/GridTrackSize.h @@ -11,18 +11,13 @@ #include namespace facebook::yoga { +// Represents a track size as defined in // https://www.w3.org/TR/css-grid-1/#typedef-track-size +// and helper functions for creating common track sizes. struct GridTrackSize { StyleSizeLength minSizingFunction; StyleSizeLength maxSizingFunction; - // These are used in the grid layout algorithm when distributing spaces among - // tracks - // TODO: maybe move them to TrackSizing since these are track states - float baseSize = 0.0f; - float growthLimit = 0.0f; - bool infinitelyGrowable = false; - // Static factory methods for common cases constexpr static GridTrackSize auto_() { return GridTrackSize{ diff --git a/yoga/style/Style.h b/yoga/style/Style.h index eedeaba2e5..12df6c1b8c 100644 --- a/yoga/style/Style.h +++ b/yoga/style/Style.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include