Back out "Modify private apis to set, store, and get intrinsic sizing keywords" (#1750)
Summary: X-link: https://github.com/facebook/react-native/pull/47895 Pull Request resolved: https://github.com/facebook/yoga/pull/1750 These APIs were only added so that we could do TDD as we work on intrinsic sizing functionality. As of right now they do nothing. We are aiming on publishing a new version of Yoga soon so for the time being we are going to back these out so as not to confuse anyone with this new functionality. Ideally we get to a point where we have some temporary experimental header to stage these in but this is a bit time sensitive so just backing out for now Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D66332307 fbshipit-source-id: 1d596964e0c893091c541988506e8b80fa6d1957
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0c995496c8
commit
be00354b71
10
enums.py
10
enums.py
@@ -8,15 +8,7 @@ import os
|
||||
|
||||
ENUMS = {
|
||||
"Direction": ["Inherit", "LTR", "RTL"],
|
||||
"Unit": [
|
||||
"Undefined",
|
||||
"Point",
|
||||
"Percent",
|
||||
"Auto",
|
||||
"MaxContent",
|
||||
"FitContent",
|
||||
"Stretch",
|
||||
],
|
||||
"Unit": ["Undefined", "Point", "Percent", "Auto"],
|
||||
"FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"],
|
||||
"Justify": [
|
||||
"FlexStart",
|
||||
|
@@ -13,10 +13,7 @@ public enum YogaUnit {
|
||||
UNDEFINED(0),
|
||||
POINT(1),
|
||||
PERCENT(2),
|
||||
AUTO(3),
|
||||
MAX_CONTENT(4),
|
||||
FIT_CONTENT(5),
|
||||
STRETCH(6);
|
||||
AUTO(3);
|
||||
|
||||
private final int mIntValue;
|
||||
|
||||
@@ -34,9 +31,6 @@ public enum YogaUnit {
|
||||
case 1: return POINT;
|
||||
case 2: return PERCENT;
|
||||
case 3: return AUTO;
|
||||
case 4: return MAX_CONTENT;
|
||||
case 5: return FIT_CONTENT;
|
||||
case 6: return STRETCH;
|
||||
default: throw new IllegalArgumentException("Unknown enum value: " + value);
|
||||
}
|
||||
}
|
||||
|
@@ -125,9 +125,6 @@ export enum Unit {
|
||||
Point = 1,
|
||||
Percent = 2,
|
||||
Auto = 3,
|
||||
MaxContent = 4,
|
||||
FitContent = 5,
|
||||
Stretch = 6,
|
||||
}
|
||||
|
||||
export enum Wrap {
|
||||
@@ -206,9 +203,6 @@ const constants = {
|
||||
UNIT_POINT: Unit.Point,
|
||||
UNIT_PERCENT: Unit.Percent,
|
||||
UNIT_AUTO: Unit.Auto,
|
||||
UNIT_MAX_CONTENT: Unit.MaxContent,
|
||||
UNIT_FIT_CONTENT: Unit.FitContent,
|
||||
UNIT_STRETCH: Unit.Stretch,
|
||||
WRAP_NO_WRAP: Wrap.NoWrap,
|
||||
WRAP_WRAP: Wrap.Wrap,
|
||||
WRAP_WRAP_REVERSE: Wrap.WrapReverse,
|
||||
|
@@ -128,19 +128,4 @@ TEST(StyleValuePool, store_undefined_after_large_int) {
|
||||
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
|
||||
}
|
||||
|
||||
TEST(StyleValuePool, store_keywords) {
|
||||
StyleValuePool pool;
|
||||
StyleValueHandle handleMaxContent;
|
||||
StyleValueHandle handleFitContent;
|
||||
StyleValueHandle handleStretch;
|
||||
|
||||
pool.store(handleMaxContent, StyleSizeLength::ofMaxContent());
|
||||
pool.store(handleFitContent, StyleSizeLength::ofFitContent());
|
||||
pool.store(handleStretch, StyleSizeLength::ofStretch());
|
||||
|
||||
EXPECT_EQ(pool.getSize(handleMaxContent), StyleSizeLength::ofMaxContent());
|
||||
EXPECT_EQ(pool.getSize(handleFitContent), StyleSizeLength::ofFitContent());
|
||||
EXPECT_EQ(pool.getSize(handleStretch), StyleSizeLength::ofStretch());
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
|
@@ -245,12 +245,6 @@ const char* YGUnitToString(const YGUnit value) {
|
||||
return "percent";
|
||||
case YGUnitAuto:
|
||||
return "auto";
|
||||
case YGUnitMaxContent:
|
||||
return "max-content";
|
||||
case YGUnitFitContent:
|
||||
return "fit-content";
|
||||
case YGUnitStretch:
|
||||
return "stretch";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
@@ -131,10 +131,7 @@ YG_ENUM_DECL(
|
||||
YGUnitUndefined,
|
||||
YGUnitPoint,
|
||||
YGUnitPercent,
|
||||
YGUnitAuto,
|
||||
YGUnitMaxContent,
|
||||
YGUnitFitContent,
|
||||
YGUnitStretch)
|
||||
YGUnitAuto)
|
||||
|
||||
YG_ENUM_DECL(
|
||||
YGWrap,
|
||||
|
@@ -177,19 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
|
||||
|
||||
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
|
||||
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
|
||||
node, StyleSizeLength::points(flexBasis));
|
||||
node, StyleLength::points(flexBasis));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetFlexBasisPercent(
|
||||
const YGNodeRef node,
|
||||
const float flexBasisPercent) {
|
||||
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
|
||||
node, StyleSizeLength::percent(flexBasisPercent));
|
||||
node, StyleLength::percent(flexBasisPercent));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
|
||||
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
|
||||
node, StyleSizeLength::ofAuto());
|
||||
node, StyleLength::ofAuto());
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
||||
@@ -308,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::points(points));
|
||||
node, Dimension::Width, StyleLength::points(points));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::percent(percent));
|
||||
node, Dimension::Width, StyleLength::percent(percent));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::ofAuto());
|
||||
node, Dimension::Width, StyleLength::ofAuto());
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||
@@ -327,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::points(points));
|
||||
node, Dimension::Height, StyleLength::points(points));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::percent(percent));
|
||||
node, Dimension::Height, StyleLength::percent(percent));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
||||
updateStyle<&Style::dimension, &Style::setDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::ofAuto());
|
||||
node, Dimension::Height, StyleLength::ofAuto());
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||
@@ -346,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
|
||||
updateStyle<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::points(minWidth));
|
||||
node, Dimension::Width, StyleLength::points(minWidth));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
|
||||
updateStyle<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::percent(minWidth));
|
||||
node, Dimension::Width, StyleLength::percent(minWidth));
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||
@@ -360,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
|
||||
updateStyle<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::points(minHeight));
|
||||
node, Dimension::Height, StyleLength::points(minHeight));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMinHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float minHeight) {
|
||||
updateStyle<&Style::minDimension, &Style::setMinDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::percent(minHeight));
|
||||
node, Dimension::Height, StyleLength::percent(minHeight));
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||
@@ -376,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
|
||||
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::points(maxWidth));
|
||||
node, Dimension::Width, StyleLength::points(maxWidth));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
|
||||
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, Dimension::Width, StyleSizeLength::percent(maxWidth));
|
||||
node, Dimension::Width, StyleLength::percent(maxWidth));
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||
@@ -390,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||
|
||||
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
|
||||
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::points(maxHeight));
|
||||
node, Dimension::Height, StyleLength::points(maxHeight));
|
||||
}
|
||||
|
||||
void YGNodeStyleSetMaxHeightPercent(
|
||||
const YGNodeRef node,
|
||||
const float maxHeight) {
|
||||
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
|
||||
node, Dimension::Height, StyleSizeLength::percent(maxHeight));
|
||||
node, Dimension::Height, StyleLength::percent(maxHeight));
|
||||
}
|
||||
|
||||
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||
|
@@ -65,9 +65,6 @@ inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
|
||||
switch (lhs.unit) {
|
||||
case YGUnitUndefined:
|
||||
case YGUnitAuto:
|
||||
case YGUnitFitContent:
|
||||
case YGUnitMaxContent:
|
||||
case YGUnitStretch:
|
||||
return true;
|
||||
case YGUnitPoint:
|
||||
case YGUnitPercent:
|
||||
|
@@ -741,7 +741,7 @@ static float distributeFreeSpaceSecondPass(
|
||||
marginCross;
|
||||
const bool isLoosePercentageMeasurement =
|
||||
currentLineChild->getProcessedDimension(dimension(crossAxis))
|
||||
.isPercent() &&
|
||||
.unit() == Unit::Percent &&
|
||||
sizingModeCrossDim != SizingMode::StretchFit;
|
||||
childCrossSizingMode =
|
||||
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
|
||||
|
@@ -20,14 +20,11 @@ enum class Unit : uint8_t {
|
||||
Point = YGUnitPoint,
|
||||
Percent = YGUnitPercent,
|
||||
Auto = YGUnitAuto,
|
||||
MaxContent = YGUnitMaxContent,
|
||||
FitContent = YGUnitFitContent,
|
||||
Stretch = YGUnitStretch,
|
||||
};
|
||||
|
||||
template <>
|
||||
constexpr int32_t ordinalCount<Unit>() {
|
||||
return 7;
|
||||
return 4;
|
||||
}
|
||||
|
||||
constexpr Unit scopedEnum(YGUnit unscoped) {
|
||||
|
@@ -314,16 +314,16 @@ void Node::setPosition(
|
||||
crossAxisTrailingEdge);
|
||||
}
|
||||
|
||||
Style::SizeLength Node::processFlexBasis() const {
|
||||
Style::SizeLength flexBasis = style_.flexBasis();
|
||||
if (!flexBasis.isAuto() && !flexBasis.isUndefined()) {
|
||||
Style::Length Node::processFlexBasis() const {
|
||||
Style::Length flexBasis = style_.flexBasis();
|
||||
if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) {
|
||||
return flexBasis;
|
||||
}
|
||||
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
|
||||
return config_->useWebDefaults() ? StyleSizeLength::ofAuto()
|
||||
: StyleSizeLength::points(0);
|
||||
return config_->useWebDefaults() ? StyleLength::ofAuto()
|
||||
: StyleLength::points(0);
|
||||
}
|
||||
return StyleSizeLength::ofAuto();
|
||||
return StyleLength::ofAuto();
|
||||
}
|
||||
|
||||
FloatOptional Node::resolveFlexBasis(
|
||||
|
@@ -172,7 +172,7 @@ class YG_EXPORT Node : public ::YGNode {
|
||||
return isDirty_;
|
||||
}
|
||||
|
||||
Style::SizeLength getProcessedDimension(Dimension dimension) const {
|
||||
Style::Length getProcessedDimension(Dimension dimension) const {
|
||||
return processedDimensions_[static_cast<size_t>(dimension)];
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ class YG_EXPORT Node : public ::YGNode {
|
||||
void setPosition(Direction direction, float ownerWidth, float ownerHeight);
|
||||
|
||||
// Other methods
|
||||
Style::SizeLength processFlexBasis() const;
|
||||
Style::Length processFlexBasis() const;
|
||||
FloatOptional resolveFlexBasis(
|
||||
Direction direction,
|
||||
FlexDirection flexDirection,
|
||||
@@ -322,8 +322,8 @@ class YG_EXPORT Node : public ::YGNode {
|
||||
Node* owner_ = nullptr;
|
||||
std::vector<Node*> children_;
|
||||
const Config* config_;
|
||||
std::array<Style::SizeLength, 2> processedDimensions_{
|
||||
{StyleSizeLength::undefined(), StyleSizeLength::undefined()}};
|
||||
std::array<Style::Length, 2> processedDimensions_{
|
||||
{StyleLength::undefined(), StyleLength::undefined()}};
|
||||
};
|
||||
|
||||
inline Node* resolveRef(const YGNodeRef ref) {
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include <yoga/enums/Wrap.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/style/StyleLength.h>
|
||||
#include <yoga/style/StyleSizeLength.h>
|
||||
#include <yoga/style/StyleValuePool.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
@@ -38,7 +37,6 @@ namespace facebook::yoga {
|
||||
class YG_EXPORT Style {
|
||||
public:
|
||||
using Length = StyleLength;
|
||||
using SizeLength = StyleSizeLength;
|
||||
|
||||
static constexpr float DefaultFlexGrow = 0.0f;
|
||||
static constexpr float DefaultFlexShrink = 0.0f;
|
||||
@@ -135,10 +133,10 @@ class YG_EXPORT Style {
|
||||
pool_.store(flexShrink_, value);
|
||||
}
|
||||
|
||||
Style::SizeLength flexBasis() const {
|
||||
return pool_.getSize(flexBasis_);
|
||||
Style::Length flexBasis() const {
|
||||
return pool_.getLength(flexBasis_);
|
||||
}
|
||||
void setFlexBasis(Style::SizeLength value) {
|
||||
void setFlexBasis(Style::Length value) {
|
||||
pool_.store(flexBasis_, value);
|
||||
}
|
||||
|
||||
@@ -177,17 +175,17 @@ class YG_EXPORT Style {
|
||||
pool_.store(gap_[yoga::to_underlying(gutter)], value);
|
||||
}
|
||||
|
||||
Style::SizeLength dimension(Dimension axis) const {
|
||||
return pool_.getSize(dimensions_[yoga::to_underlying(axis)]);
|
||||
Style::Length dimension(Dimension axis) const {
|
||||
return pool_.getLength(dimensions_[yoga::to_underlying(axis)]);
|
||||
}
|
||||
void setDimension(Dimension axis, Style::SizeLength value) {
|
||||
void setDimension(Dimension axis, Style::Length value) {
|
||||
pool_.store(dimensions_[yoga::to_underlying(axis)], value);
|
||||
}
|
||||
|
||||
Style::SizeLength minDimension(Dimension axis) const {
|
||||
return pool_.getSize(minDimensions_[yoga::to_underlying(axis)]);
|
||||
Style::Length minDimension(Dimension axis) const {
|
||||
return pool_.getLength(minDimensions_[yoga::to_underlying(axis)]);
|
||||
}
|
||||
void setMinDimension(Dimension axis, Style::SizeLength value) {
|
||||
void setMinDimension(Dimension axis, Style::Length value) {
|
||||
pool_.store(minDimensions_[yoga::to_underlying(axis)], value);
|
||||
}
|
||||
|
||||
@@ -209,10 +207,10 @@ class YG_EXPORT Style {
|
||||
: FloatOptional{0.0});
|
||||
}
|
||||
|
||||
Style::SizeLength maxDimension(Dimension axis) const {
|
||||
return pool_.getSize(maxDimensions_[yoga::to_underlying(axis)]);
|
||||
Style::Length maxDimension(Dimension axis) const {
|
||||
return pool_.getLength(maxDimensions_[yoga::to_underlying(axis)]);
|
||||
}
|
||||
void setMaxDimension(Dimension axis, Style::SizeLength value) {
|
||||
void setMaxDimension(Dimension axis, Style::Length value) {
|
||||
pool_.store(maxDimensions_[yoga::to_underlying(axis)], value);
|
||||
}
|
||||
|
||||
|
@@ -19,11 +19,13 @@ namespace facebook::yoga {
|
||||
* 3. A CSS <length-percentage> value:
|
||||
* a. <length> value (e.g. 10px)
|
||||
* b. <percentage> value of a reference <length>
|
||||
* 4. (soon) A math function which returns a <length-percentage> value
|
||||
*
|
||||
* References:
|
||||
* 1. https://www.w3.org/TR/css-values-4/#lengths
|
||||
* 2. https://www.w3.org/TR/css-values-4/#percentage-value
|
||||
* 3. https://www.w3.org/TR/css-values-4/#mixed-percentages
|
||||
* 4. https://www.w3.org/TR/css-values-4/#math
|
||||
*/
|
||||
class StyleLength {
|
||||
public:
|
||||
@@ -57,14 +59,6 @@ class StyleLength {
|
||||
return unit_ == Unit::Undefined;
|
||||
}
|
||||
|
||||
constexpr bool isPoints() const {
|
||||
return unit_ == Unit::Point;
|
||||
}
|
||||
|
||||
constexpr bool isPercent() const {
|
||||
return unit_ == Unit::Percent;
|
||||
}
|
||||
|
||||
constexpr bool isDefined() const {
|
||||
return !isUndefined();
|
||||
}
|
||||
@@ -73,6 +67,10 @@ class StyleLength {
|
||||
return value_;
|
||||
}
|
||||
|
||||
constexpr Unit unit() const {
|
||||
return unit_;
|
||||
}
|
||||
|
||||
constexpr FloatOptional resolve(float referenceLength) {
|
||||
switch (unit_) {
|
||||
case Unit::Point:
|
||||
@@ -92,11 +90,6 @@ class StyleLength {
|
||||
return value_ == rhs.value_ && unit_ == rhs.unit_;
|
||||
}
|
||||
|
||||
constexpr bool inexactEquals(const StyleLength& other) const {
|
||||
return unit_ == other.unit_ &&
|
||||
facebook::yoga::inexactEquals(value_, other.value_);
|
||||
}
|
||||
|
||||
private:
|
||||
// We intentionally do not allow direct construction using value and unit, to
|
||||
// avoid invalid, or redundant combinations.
|
||||
@@ -108,7 +101,7 @@ class StyleLength {
|
||||
};
|
||||
|
||||
inline bool inexactEquals(const StyleLength& a, const StyleLength& b) {
|
||||
return a.inexactEquals(b);
|
||||
return a.unit() == b.unit() && inexactEquals(a.value(), b.value());
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
||||
|
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* 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/Unit.h>
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
|
||||
/**
|
||||
* This class represents a CSS Value for sizes (e.g. width, height, min-width,
|
||||
* etc.). It may be one of:
|
||||
* 1. Undefined
|
||||
* 2. A keyword (e.g. auto, max-content, stretch, etc.)
|
||||
* 3. A CSS <length-percentage> value:
|
||||
* a. <length> value (e.g. 10px)
|
||||
* b. <percentage> value of a reference <length>
|
||||
*
|
||||
* References:
|
||||
* 1. https://www.w3.org/TR/css-values-4/#lengths
|
||||
* 2. https://www.w3.org/TR/css-values-4/#percentage-value
|
||||
* 3. https://www.w3.org/TR/css-values-4/#mixed-percentages
|
||||
*/
|
||||
class StyleSizeLength {
|
||||
public:
|
||||
constexpr StyleSizeLength() = default;
|
||||
|
||||
constexpr static StyleSizeLength points(float value) {
|
||||
return yoga::isUndefined(value) || yoga::isinf(value)
|
||||
? undefined()
|
||||
: StyleSizeLength{FloatOptional{value}, Unit::Point};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength percent(float value) {
|
||||
return yoga::isUndefined(value) || yoga::isinf(value)
|
||||
? undefined()
|
||||
: StyleSizeLength{FloatOptional{value}, Unit::Percent};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength ofAuto() {
|
||||
return StyleSizeLength{{}, Unit::Auto};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength ofMaxContent() {
|
||||
return StyleSizeLength{{}, Unit::MaxContent};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength ofFitContent() {
|
||||
return StyleSizeLength{{}, Unit::FitContent};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength ofStretch() {
|
||||
return StyleSizeLength{{}, Unit::Stretch};
|
||||
}
|
||||
|
||||
constexpr static StyleSizeLength undefined() {
|
||||
return StyleSizeLength{{}, Unit::Undefined};
|
||||
}
|
||||
|
||||
constexpr bool isAuto() const {
|
||||
return unit_ == Unit::Auto;
|
||||
}
|
||||
|
||||
constexpr bool isMaxContent() const {
|
||||
return unit_ == Unit::MaxContent;
|
||||
}
|
||||
|
||||
constexpr bool isFitContent() const {
|
||||
return unit_ == Unit::FitContent;
|
||||
}
|
||||
|
||||
constexpr bool isStretch() const {
|
||||
return unit_ == Unit::Stretch;
|
||||
}
|
||||
|
||||
constexpr bool isUndefined() const {
|
||||
return unit_ == Unit::Undefined;
|
||||
}
|
||||
|
||||
constexpr bool isDefined() const {
|
||||
return !isUndefined();
|
||||
}
|
||||
|
||||
constexpr bool isPoints() const {
|
||||
return unit_ == Unit::Point;
|
||||
}
|
||||
|
||||
constexpr bool isPercent() const {
|
||||
return unit_ == Unit::Percent;
|
||||
}
|
||||
|
||||
constexpr FloatOptional value() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
constexpr FloatOptional resolve(float referenceLength) {
|
||||
switch (unit_) {
|
||||
case Unit::Point:
|
||||
return value_;
|
||||
case Unit::Percent:
|
||||
return FloatOptional{value_.unwrap() * referenceLength * 0.01f};
|
||||
default:
|
||||
return FloatOptional{};
|
||||
}
|
||||
}
|
||||
|
||||
explicit constexpr operator YGValue() const {
|
||||
return YGValue{value_.unwrap(), unscopedEnum(unit_)};
|
||||
}
|
||||
|
||||
constexpr bool operator==(const StyleSizeLength& rhs) const {
|
||||
return value_ == rhs.value_ && unit_ == rhs.unit_;
|
||||
}
|
||||
|
||||
constexpr bool inexactEquals(const StyleSizeLength& other) const {
|
||||
return unit_ == other.unit_ &&
|
||||
facebook::yoga::inexactEquals(value_, other.value_);
|
||||
}
|
||||
|
||||
private:
|
||||
// We intentionally do not allow direct construction using value and unit, to
|
||||
// avoid invalid, or redundant combinations.
|
||||
constexpr StyleSizeLength(FloatOptional value, Unit unit)
|
||||
: value_(value), unit_(unit) {}
|
||||
|
||||
FloatOptional value_{};
|
||||
Unit unit_{Unit::Undefined};
|
||||
};
|
||||
|
||||
inline bool inexactEquals(const StyleSizeLength& a, const StyleSizeLength& b) {
|
||||
return a.inexactEquals(b);
|
||||
}
|
||||
|
||||
} // namespace facebook::yoga
|
@@ -62,16 +62,8 @@ class StyleValueHandle {
|
||||
Percent,
|
||||
Number,
|
||||
Auto,
|
||||
Keyword
|
||||
};
|
||||
|
||||
// Intentionally leaving out auto as a fast path
|
||||
enum class Keyword : uint8_t { MaxContent, FitContent, Stretch };
|
||||
|
||||
constexpr bool isKeyword(Keyword keyword) const {
|
||||
return type() == Type::Keyword && value() == static_cast<uint16_t>(keyword);
|
||||
}
|
||||
|
||||
constexpr Type type() const {
|
||||
return static_cast<Type>(repr_ & kHandleTypeMask);
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include <yoga/numeric/FloatOptional.h>
|
||||
#include <yoga/style/SmallValueBuffer.h>
|
||||
#include <yoga/style/StyleLength.h>
|
||||
#include <yoga/style/StyleSizeLength.h>
|
||||
#include <yoga/style/StyleValueHandle.h>
|
||||
|
||||
namespace facebook::yoga {
|
||||
@@ -33,30 +32,13 @@ class StyleValuePool {
|
||||
} else if (length.isAuto()) {
|
||||
handle.setType(StyleValueHandle::Type::Auto);
|
||||
} else {
|
||||
auto type = length.isPoints() ? StyleValueHandle::Type::Point
|
||||
: StyleValueHandle::Type::Percent;
|
||||
auto type = length.unit() == Unit::Point
|
||||
? StyleValueHandle::Type::Point
|
||||
: StyleValueHandle::Type::Percent;
|
||||
storeValue(handle, length.value().unwrap(), type);
|
||||
}
|
||||
}
|
||||
|
||||
void store(StyleValueHandle& handle, StyleSizeLength sizeValue) {
|
||||
if (sizeValue.isUndefined()) {
|
||||
handle.setType(StyleValueHandle::Type::Undefined);
|
||||
} else if (sizeValue.isAuto()) {
|
||||
handle.setType(StyleValueHandle::Type::Auto);
|
||||
} else if (sizeValue.isMaxContent()) {
|
||||
storeKeyword(handle, StyleValueHandle::Keyword::MaxContent);
|
||||
} else if (sizeValue.isStretch()) {
|
||||
storeKeyword(handle, StyleValueHandle::Keyword::Stretch);
|
||||
} else if (sizeValue.isFitContent()) {
|
||||
storeKeyword(handle, StyleValueHandle::Keyword::FitContent);
|
||||
} else {
|
||||
auto type = sizeValue.isPoints() ? StyleValueHandle::Type::Point
|
||||
: StyleValueHandle::Type::Percent;
|
||||
storeValue(handle, sizeValue.value().unwrap(), type);
|
||||
}
|
||||
}
|
||||
|
||||
void store(StyleValueHandle& handle, FloatOptional number) {
|
||||
if (number.isUndefined()) {
|
||||
handle.setType(StyleValueHandle::Type::Undefined);
|
||||
@@ -84,31 +66,6 @@ class StyleValuePool {
|
||||
}
|
||||
}
|
||||
|
||||
StyleSizeLength getSize(StyleValueHandle handle) const {
|
||||
if (handle.isUndefined()) {
|
||||
return StyleSizeLength::undefined();
|
||||
} else if (handle.isAuto()) {
|
||||
return StyleSizeLength::ofAuto();
|
||||
} else if (handle.isKeyword(StyleValueHandle::Keyword::MaxContent)) {
|
||||
return StyleSizeLength::ofMaxContent();
|
||||
} else if (handle.isKeyword(StyleValueHandle::Keyword::FitContent)) {
|
||||
return StyleSizeLength::ofFitContent();
|
||||
} else if (handle.isKeyword(StyleValueHandle::Keyword::Stretch)) {
|
||||
return StyleSizeLength::ofStretch();
|
||||
} else {
|
||||
assert(
|
||||
handle.type() == StyleValueHandle::Type::Point ||
|
||||
handle.type() == StyleValueHandle::Type::Percent);
|
||||
float value = (handle.isValueIndexed())
|
||||
? std::bit_cast<float>(buffer_.get32(handle.value()))
|
||||
: unpackInlineInteger(handle.value());
|
||||
|
||||
return handle.type() == StyleValueHandle::Type::Point
|
||||
? StyleSizeLength::points(value)
|
||||
: StyleSizeLength::percent(value);
|
||||
}
|
||||
}
|
||||
|
||||
FloatOptional getNumber(StyleValueHandle handle) const {
|
||||
if (handle.isUndefined()) {
|
||||
return FloatOptional{};
|
||||
@@ -141,20 +98,6 @@ class StyleValuePool {
|
||||
}
|
||||
}
|
||||
|
||||
void storeKeyword(
|
||||
StyleValueHandle& handle,
|
||||
StyleValueHandle::Keyword keyword) {
|
||||
handle.setType(StyleValueHandle::Type::Keyword);
|
||||
|
||||
if (handle.isValueIndexed()) {
|
||||
auto newIndex =
|
||||
buffer_.replace(handle.value(), static_cast<uint32_t>(keyword));
|
||||
handle.setValue(newIndex);
|
||||
} else {
|
||||
handle.setValue(static_cast<uint16_t>(keyword));
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr bool isIntegerPackable(float f) {
|
||||
constexpr uint16_t kMaxInlineAbsValue = (1 << 11) - 1;
|
||||
|
||||
|
Reference in New Issue
Block a user