C++ Cleanup 1/N: Reorganize YGStyle (#1349)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1349 X-link: https://github.com/facebook/react-native/pull/39171 ## This diff This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation. ## This stack The organization of the C++ internals of Yoga are in need of attention. 1. Some of the C++ internals are namespaced, but others not. 2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these) 2. Most of the files are in a flat hierarchy, except for event tracing in its own folder 3. Some files and functions begin with YG, others don’t 4. Some functions are uppercase, others are not 5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about 6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h) 7. There is no clear indication from file structure or type naming what is private vs not 8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers This stack does some much needed spring cleaning: 1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy 3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended 4. Utils files are split 5. Most C++ internals drop the YG prefix 6. Most C++ internal function names are all lower camel case 7. We start to split up Yoga.cpp 8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings 9. It is not possible to use private APIs without static casting handles to internal classes This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well. These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer. Changelog: [Internal] Reviewed By: rshest Differential Revision: D48710084 fbshipit-source-id: 20961aee30d54a6b0d8c1cc2976df09b9b6d486a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
49fbd406b6
commit
b289d12248
11
Yoga.podspec
11
Yoga.podspec
@@ -35,7 +35,14 @@ Pod::Spec.new do |spec|
|
|||||||
'-std=c++17',
|
'-std=c++17',
|
||||||
'-fPIC'
|
'-fPIC'
|
||||||
]
|
]
|
||||||
spec.source_files = 'yoga/**/*.{h,cpp}'
|
|
||||||
spec.public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGValue}.h'
|
|
||||||
spec.swift_version = '5.1'
|
spec.swift_version = '5.1'
|
||||||
|
spec.source_files = 'yoga/**/*.{h,cpp}'
|
||||||
|
spec.header_mappings_dir = 'yoga'
|
||||||
|
|
||||||
|
public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGValue}.h'
|
||||||
|
spec.public_header_files = public_header_files
|
||||||
|
|
||||||
|
all_header_files = 'yoga/**/*.h'
|
||||||
|
spec.private_header_files = Dir.glob(all_header_files) - Dir.glob(public_header_files)
|
||||||
end
|
end
|
||||||
|
@@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
#define YOGA_COMPACT_VALUE_TEST
|
#define YOGA_COMPACT_VALUE_TEST
|
||||||
|
|
||||||
#include <yoga/CompactValue.h>
|
#include <yoga/style/CompactValue.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using facebook::yoga::detail::CompactValue;
|
using facebook::yoga::CompactValue;
|
||||||
|
|
||||||
const auto tooSmall = nextafterf(CompactValue::LOWER_BOUND, -INFINITY);
|
const auto tooSmall = nextafterf(CompactValue::LOWER_BOUND, -INFINITY);
|
||||||
const auto tooLargePoints =
|
const auto tooLargePoints =
|
||||||
|
@@ -8,9 +8,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/YGEnums.h>
|
#include <yoga/Yoga.h>
|
||||||
#include <yoga/YGStyle.h>
|
#include <yoga/style/Style.h>
|
||||||
#include <yoga/YGValue.h>
|
|
||||||
|
|
||||||
#define ACCESSOR_TESTS_1(NAME, X) \
|
#define ACCESSOR_TESTS_1(NAME, X) \
|
||||||
style.NAME() = X; \
|
style.NAME() = X; \
|
||||||
@@ -33,10 +32,10 @@
|
|||||||
|
|
||||||
#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
{ \
|
{ \
|
||||||
auto style = YGStyle{}; \
|
auto style = Style{}; \
|
||||||
style.NAME()[IDX] = X; \
|
style.NAME()[IDX] = X; \
|
||||||
ASSERT_EQ(style.NAME()[IDX], X); \
|
ASSERT_EQ(style.NAME()[IDX], X); \
|
||||||
auto asArray = decltype(std::declval<const YGStyle&>().NAME()){X}; \
|
auto asArray = decltype(std::declval<const Style&>().NAME()){X}; \
|
||||||
style.NAME() = asArray; \
|
style.NAME() = asArray; \
|
||||||
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
|
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
|
||||||
}
|
}
|
||||||
@@ -64,22 +63,20 @@
|
|||||||
|
|
||||||
// test macro for up to 5 values. If more are needed, extend the macros above.
|
// test macro for up to 5 values. If more are needed, extend the macros above.
|
||||||
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
|
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
|
||||||
TEST(YGStyle, style_##NAME##_access) { \
|
TEST(Style, style_##NAME##_access) { \
|
||||||
auto style = YGStyle{}; \
|
auto style = Style{}; \
|
||||||
ASSERT_EQ(style.NAME(), DEFAULT_VAL); \
|
ASSERT_EQ(style.NAME(), DEFAULT_VAL); \
|
||||||
ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \
|
ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \
|
#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \
|
||||||
TEST(YGStyle, style_##NAME##_access) { \
|
TEST(Style, style_##NAME##_access) { \
|
||||||
ASSERT_EQ(YGStyle{}.NAME()[IDX], DEFAULT_VAL); \
|
ASSERT_EQ(Style{}.NAME()[IDX], DEFAULT_VAL); \
|
||||||
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
|
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
using CompactValue = detail::CompactValue;
|
|
||||||
|
|
||||||
// TODO: MSVC doesn't like the macros
|
// TODO: MSVC doesn't like the macros
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
|
|
||||||
|
12
yoga/Utils.h
12
yoga/Utils.h
@@ -8,8 +8,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "YGNode.h"
|
#include "YGNode.h"
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
#include "CompactValue.h"
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
// This struct is an helper model to hold the data for step 4 of flexbox algo,
|
// This struct is an helper model to hold the data for step 4 of flexbox algo,
|
||||||
// which is collecting the flex items in a line.
|
// which is collecting the flex items in a line.
|
||||||
@@ -56,8 +56,8 @@ struct YGCollectFlexItemsRowValues {
|
|||||||
|
|
||||||
bool YGValueEqual(const YGValue& a, const YGValue& b);
|
bool YGValueEqual(const YGValue& a, const YGValue& b);
|
||||||
inline bool YGValueEqual(
|
inline bool YGValueEqual(
|
||||||
facebook::yoga::detail::CompactValue a,
|
facebook::yoga::CompactValue a,
|
||||||
facebook::yoga::detail::CompactValue b) {
|
facebook::yoga::CompactValue b) {
|
||||||
return YGValueEqual((YGValue) a, (YGValue) b);
|
return YGValueEqual((YGValue) a, (YGValue) b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ inline YGFloatOptional YGResolveValue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline YGFloatOptional YGResolveValue(
|
inline YGFloatOptional YGResolveValue(
|
||||||
facebook::yoga::detail::CompactValue value,
|
facebook::yoga::CompactValue value,
|
||||||
float ownerSize) {
|
float ownerSize) {
|
||||||
return YGResolveValue((YGValue) value, ownerSize);
|
return YGResolveValue((YGValue) value, ownerSize);
|
||||||
}
|
}
|
||||||
@@ -140,7 +140,7 @@ inline YGFlexDirection YGResolveFlexDirection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline YGFloatOptional YGResolveValueMargin(
|
inline YGFloatOptional YGResolveValueMargin(
|
||||||
facebook::yoga::detail::CompactValue value,
|
facebook::yoga::CompactValue value,
|
||||||
const float ownerSize) {
|
const float ownerSize) {
|
||||||
return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize);
|
return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize);
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include "BitUtils.h"
|
#include <yoga/BitUtils.h>
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
struct YGFloatOptional {
|
struct YGFloatOptional {
|
||||||
private:
|
private:
|
||||||
|
@@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BitUtils.h"
|
#include <yoga/BitUtils.h>
|
||||||
#include "YGFloatOptional.h"
|
#include <yoga/YGFloatOptional.h>
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
|
|
||||||
struct YGLayout {
|
struct YGLayout {
|
||||||
std::array<float, 4> position = {};
|
std::array<float, 4> position = {};
|
||||||
|
@@ -11,7 +11,8 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
using facebook::yoga::detail::CompactValue;
|
using namespace facebook::yoga;
|
||||||
|
using facebook::yoga::CompactValue;
|
||||||
|
|
||||||
YGNode::YGNode(const YGConfigRef config) : config_{config} {
|
YGNode::YGNode(const YGConfigRef config) : config_{config} {
|
||||||
YGAssert(
|
YGAssert(
|
||||||
@@ -53,7 +54,7 @@ void YGNode::print(void* printContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompactValue YGNode::computeEdgeValueForRow(
|
CompactValue YGNode::computeEdgeValueForRow(
|
||||||
const YGStyle::Edges& edges,
|
const Style::Edges& edges,
|
||||||
YGEdge rowEdge,
|
YGEdge rowEdge,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
@@ -71,7 +72,7 @@ CompactValue YGNode::computeEdgeValueForRow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompactValue YGNode::computeEdgeValueForColumn(
|
CompactValue YGNode::computeEdgeValueForColumn(
|
||||||
const YGStyle::Edges& edges,
|
const Style::Edges& edges,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
if (!edges[edge].isUndefined()) {
|
if (!edges[edge].isUndefined()) {
|
||||||
@@ -86,7 +87,7 @@ CompactValue YGNode::computeEdgeValueForColumn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompactValue YGNode::computeRowGap(
|
CompactValue YGNode::computeRowGap(
|
||||||
const YGStyle::Gutters& gutters,
|
const Style::Gutters& gutters,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
if (!gutters[YGGutterRow].isUndefined()) {
|
if (!gutters[YGGutterRow].isUndefined()) {
|
||||||
return gutters[YGGutterRow];
|
return gutters[YGGutterRow];
|
||||||
@@ -98,7 +99,7 @@ CompactValue YGNode::computeRowGap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompactValue YGNode::computeColumnGap(
|
CompactValue YGNode::computeColumnGap(
|
||||||
const YGStyle::Gutters& gutters,
|
const Style::Gutters& gutters,
|
||||||
CompactValue defaultValue) {
|
CompactValue defaultValue) {
|
||||||
if (!gutters[YGGutterColumn].isUndefined()) {
|
if (!gutters[YGGutterColumn].isUndefined()) {
|
||||||
return gutters[YGGutterColumn];
|
return gutters[YGGutterColumn];
|
||||||
@@ -431,7 +432,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {
|
|||||||
|
|
||||||
void YGNode::resolveDimension() {
|
void YGNode::resolveDimension() {
|
||||||
using namespace yoga;
|
using namespace yoga;
|
||||||
const YGStyle& style = getStyle();
|
const Style& style = getStyle();
|
||||||
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
|
||||||
if (!style.maxDimensions()[dim].isUndefined() &&
|
if (!style.maxDimensions()[dim].isUndefined() &&
|
||||||
YGValueEqual(style.maxDimensions()[dim], style.minDimensions()[dim])) {
|
YGValueEqual(style.maxDimensions()[dim], style.minDimensions()[dim])) {
|
||||||
|
@@ -9,11 +9,12 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "CompactValue.h"
|
|
||||||
#include "YGConfig.h"
|
#include "YGConfig.h"
|
||||||
#include "YGLayout.h"
|
#include "YGLayout.h"
|
||||||
#include "YGStyle.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
#include "Yoga-internal.h"
|
|
||||||
|
#include <yoga/style/CompactValue.h>
|
||||||
|
#include <yoga/style/Style.h>
|
||||||
|
|
||||||
YGConfigRef YGConfigGetDefault();
|
YGConfigRef YGConfigGetDefault();
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ private:
|
|||||||
PrintWithContextFn withContext;
|
PrintWithContextFn withContext;
|
||||||
} print_ = {nullptr};
|
} print_ = {nullptr};
|
||||||
YGDirtiedFunc dirtied_ = nullptr;
|
YGDirtiedFunc dirtied_ = nullptr;
|
||||||
YGStyle style_ = {};
|
facebook::yoga::Style style_ = {};
|
||||||
YGLayout layout_ = {};
|
YGLayout layout_ = {};
|
||||||
uint32_t lineIndex_ = 0;
|
uint32_t lineIndex_ = 0;
|
||||||
YGNodeRef owner_ = nullptr;
|
YGNodeRef owner_ = nullptr;
|
||||||
@@ -80,7 +81,7 @@ private:
|
|||||||
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
|
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
|
||||||
YGNode& operator=(YGNode&&) = default;
|
YGNode& operator=(YGNode&&) = default;
|
||||||
|
|
||||||
using CompactValue = facebook::yoga::detail::CompactValue;
|
using CompactValue = facebook::yoga::CompactValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; }
|
YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; }
|
||||||
@@ -123,9 +124,9 @@ public:
|
|||||||
YGDirtiedFunc getDirtied() const { return dirtied_; }
|
YGDirtiedFunc getDirtied() const { return dirtied_; }
|
||||||
|
|
||||||
// For Performance reasons passing as reference.
|
// For Performance reasons passing as reference.
|
||||||
YGStyle& getStyle() { return style_; }
|
facebook::yoga::Style& getStyle() { return style_; }
|
||||||
|
|
||||||
const YGStyle& getStyle() const { return style_; }
|
const facebook::yoga::Style& getStyle() const { return style_; }
|
||||||
|
|
||||||
// For Performance reasons passing as reference.
|
// For Performance reasons passing as reference.
|
||||||
YGLayout& getLayout() { return layout_; }
|
YGLayout& getLayout() { return layout_; }
|
||||||
@@ -178,22 +179,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CompactValue computeEdgeValueForColumn(
|
static CompactValue computeEdgeValueForColumn(
|
||||||
const YGStyle::Edges& edges,
|
const facebook::yoga::Style::Edges& edges,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeEdgeValueForRow(
|
static CompactValue computeEdgeValueForRow(
|
||||||
const YGStyle::Edges& edges,
|
const facebook::yoga::Style::Edges& edges,
|
||||||
YGEdge rowEdge,
|
YGEdge rowEdge,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeRowGap(
|
static CompactValue computeRowGap(
|
||||||
const YGStyle::Gutters& gutters,
|
const facebook::yoga::Style::Gutters& gutters,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
static CompactValue computeColumnGap(
|
static CompactValue computeColumnGap(
|
||||||
const YGStyle::Gutters& gutters,
|
const facebook::yoga::Style::Gutters& gutters,
|
||||||
CompactValue defaultValue);
|
CompactValue defaultValue);
|
||||||
|
|
||||||
// Methods related to positions, margin, padding and border
|
// Methods related to positions, margin, padding and border
|
||||||
@@ -273,7 +274,7 @@ public:
|
|||||||
|
|
||||||
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; }
|
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { dirtied_ = dirtiedFunc; }
|
||||||
|
|
||||||
void setStyle(const YGStyle& style) { style_ = style; }
|
void setStyle(const facebook::yoga::Style& style) { style_ = style; }
|
||||||
|
|
||||||
void setLayout(const YGLayout& layout) { layout_ = layout; }
|
void setLayout(const YGLayout& layout) { layout_ = layout; }
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#include "YGNodePrint.h"
|
#include "YGNodePrint.h"
|
||||||
#include "YGNode.h"
|
#include "YGNode.h"
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
@@ -25,7 +25,7 @@ static void indent(string& base, uint32_t level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool areFourValuesEqual(const YGStyle::Edges& four) {
|
static bool areFourValuesEqual(const Style::Edges& four) {
|
||||||
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
|
return YGValueEqual(four[0], four[1]) && YGValueEqual(four[0], four[2]) &&
|
||||||
YGValueEqual(four[0], four[3]);
|
YGValueEqual(four[0], four[3]);
|
||||||
}
|
}
|
||||||
@@ -90,10 +90,10 @@ static void appendNumberIfNotZero(
|
|||||||
static void appendEdges(
|
static void appendEdges(
|
||||||
string& base,
|
string& base,
|
||||||
const string& key,
|
const string& key,
|
||||||
const YGStyle::Edges& edges) {
|
const Style::Edges& edges) {
|
||||||
if (areFourValuesEqual(edges)) {
|
if (areFourValuesEqual(edges)) {
|
||||||
auto edgeValue = YGNode::computeEdgeValueForColumn(
|
auto edgeValue = YGNode::computeEdgeValueForColumn(
|
||||||
edges, YGEdgeLeft, detail::CompactValue::ofZero());
|
edges, YGEdgeLeft, CompactValue::ofZero());
|
||||||
appendNumberIfNotZero(base, key, edgeValue);
|
appendNumberIfNotZero(base, key, edgeValue);
|
||||||
} else {
|
} else {
|
||||||
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
|
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
|
||||||
@@ -106,14 +106,14 @@ static void appendEdges(
|
|||||||
static void appendEdgeIfNotUndefined(
|
static void appendEdgeIfNotUndefined(
|
||||||
string& base,
|
string& base,
|
||||||
const string& str,
|
const string& str,
|
||||||
const YGStyle::Edges& edges,
|
const Style::Edges& edges,
|
||||||
const YGEdge edge) {
|
const YGEdge edge) {
|
||||||
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
||||||
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
|
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
|
||||||
? YGNode::computeEdgeValueForRow(
|
? YGNode::computeEdgeValueForRow(
|
||||||
edges, edge, edge, detail::CompactValue::ofUndefined())
|
edges, edge, edge, CompactValue::ofUndefined())
|
||||||
: YGNode::computeEdgeValueForColumn(
|
: YGNode::computeEdgeValueForColumn(
|
||||||
edges, edge, detail::CompactValue::ofUndefined());
|
edges, edge, CompactValue::ofUndefined());
|
||||||
appendNumberIfNotUndefined(base, str, value);
|
appendNumberIfNotUndefined(base, str, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,17 +188,15 @@ void YGNodeToString(
|
|||||||
appendEdges(str, "padding", style.padding());
|
appendEdges(str, "padding", style.padding());
|
||||||
appendEdges(str, "border", style.border());
|
appendEdges(str, "border", style.border());
|
||||||
|
|
||||||
if (YGNode::computeColumnGap(
|
if (YGNode::computeColumnGap(style.gap(), CompactValue::ofUndefined()) !=
|
||||||
style.gap(), detail::CompactValue::ofUndefined()) !=
|
|
||||||
YGNode::computeColumnGap(
|
YGNode::computeColumnGap(
|
||||||
YGNode().getStyle().gap(), detail::CompactValue::ofUndefined())) {
|
YGNode().getStyle().gap(), CompactValue::ofUndefined())) {
|
||||||
appendNumberIfNotUndefined(
|
appendNumberIfNotUndefined(
|
||||||
str, "column-gap", style.gap()[YGGutterColumn]);
|
str, "column-gap", style.gap()[YGGutterColumn]);
|
||||||
}
|
}
|
||||||
if (YGNode::computeRowGap(
|
if (YGNode::computeRowGap(style.gap(), CompactValue::ofUndefined()) !=
|
||||||
style.gap(), detail::CompactValue::ofUndefined()) !=
|
|
||||||
YGNode::computeRowGap(
|
YGNode::computeRowGap(
|
||||||
YGNode().getStyle().gap(), detail::CompactValue::ofUndefined())) {
|
YGNode().getStyle().gap(), CompactValue::ofUndefined())) {
|
||||||
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
appendNumberIfNotUndefined(str, "row-gap", style.gap()[YGGutterRow]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
|
||||||
#include "CompactValue.h"
|
#include <yoga/style/CompactValue.h>
|
||||||
|
|
||||||
using YGVector = std::vector<YGNodeRef>;
|
using YGVector = std::vector<YGNodeRef>;
|
||||||
|
|
||||||
|
154
yoga/Yoga.cpp
154
yoga/Yoga.cpp
@@ -17,7 +17,7 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "YGNode.h"
|
#include "YGNode.h"
|
||||||
#include "YGNodePrint.h"
|
#include "YGNodePrint.h"
|
||||||
#include "Yoga-internal.h"
|
#include <yoga/Yoga-internal.h>
|
||||||
#include "event/event.h"
|
#include "event/event.h"
|
||||||
|
|
||||||
using namespace facebook::yoga;
|
using namespace facebook::yoga;
|
||||||
@@ -480,26 +480,25 @@ void updateStyle(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Ref, typename T>
|
template <typename Ref, typename T>
|
||||||
void updateStyle(YGNode* node, Ref (YGStyle::*prop)(), T value) {
|
void updateStyle(YGNode* node, Ref (Style::*prop)(), T value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
node,
|
node,
|
||||||
value,
|
value,
|
||||||
[prop](YGStyle& s, T x) { return (s.*prop)() != x; },
|
[prop](Style& s, T x) { return (s.*prop)() != x; },
|
||||||
[prop](YGStyle& s, T x) { (s.*prop)() = x; });
|
[prop](Style& s, T x) { (s.*prop)() = x; });
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Ref, typename Idx>
|
template <typename Ref, typename Idx>
|
||||||
void updateIndexedStyleProp(
|
void updateIndexedStyleProp(
|
||||||
YGNode* node,
|
YGNode* node,
|
||||||
Ref (YGStyle::*prop)(),
|
Ref (Style::*prop)(),
|
||||||
Idx idx,
|
Idx idx,
|
||||||
detail::CompactValue value) {
|
CompactValue value) {
|
||||||
using detail::CompactValue;
|
|
||||||
updateStyle(
|
updateStyle(
|
||||||
node,
|
node,
|
||||||
value,
|
value,
|
||||||
[idx, prop](YGStyle& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
||||||
[idx, prop](YGStyle& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -509,12 +508,12 @@ void updateIndexedStyleProp(
|
|||||||
// overload like clang and GCC. For the purposes of updateStyle(), we can help
|
// overload like clang and GCC. For the purposes of updateStyle(), we can help
|
||||||
// MSVC by specifying that return type explicitly. In combination with
|
// MSVC by specifying that return type explicitly. In combination with
|
||||||
// decltype, MSVC will prefer the non-const version.
|
// decltype, MSVC will prefer the non-const version.
|
||||||
#define MSVC_HINT(PROP) decltype(YGStyle{}.PROP())
|
#define MSVC_HINT(PROP) decltype(Style{}.PROP())
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetDirection(
|
YOGA_EXPORT void YGNodeStyleSetDirection(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGDirection value) {
|
const YGDirection value) {
|
||||||
updateStyle<MSVC_HINT(direction)>(node, &YGStyle::direction, value);
|
updateStyle<MSVC_HINT(direction)>(node, &Style::direction, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeConstRef node) {
|
||||||
return node->getStyle().direction();
|
return node->getStyle().direction();
|
||||||
@@ -524,7 +523,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexDirection(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGFlexDirection flexDirection) {
|
const YGFlexDirection flexDirection) {
|
||||||
updateStyle<MSVC_HINT(flexDirection)>(
|
updateStyle<MSVC_HINT(flexDirection)>(
|
||||||
node, &YGStyle::flexDirection, flexDirection);
|
node, &Style::flexDirection, flexDirection);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGFlexDirection
|
YOGA_EXPORT YGFlexDirection
|
||||||
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
YGNodeStyleGetFlexDirection(const YGNodeConstRef node) {
|
||||||
@@ -535,7 +534,7 @@ YOGA_EXPORT void YGNodeStyleSetJustifyContent(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGJustify justifyContent) {
|
const YGJustify justifyContent) {
|
||||||
updateStyle<MSVC_HINT(justifyContent)>(
|
updateStyle<MSVC_HINT(justifyContent)>(
|
||||||
node, &YGStyle::justifyContent, justifyContent);
|
node, &Style::justifyContent, justifyContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeConstRef node) {
|
||||||
return node->getStyle().justifyContent();
|
return node->getStyle().justifyContent();
|
||||||
@@ -545,7 +544,7 @@ YOGA_EXPORT void YGNodeStyleSetAlignContent(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGAlign alignContent) {
|
const YGAlign alignContent) {
|
||||||
updateStyle<MSVC_HINT(alignContent)>(
|
updateStyle<MSVC_HINT(alignContent)>(
|
||||||
node, &YGStyle::alignContent, alignContent);
|
node, &Style::alignContent, alignContent);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignContent();
|
return node->getStyle().alignContent();
|
||||||
@@ -554,7 +553,7 @@ YOGA_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
YOGA_EXPORT void YGNodeStyleSetAlignItems(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGAlign alignItems) {
|
const YGAlign alignItems) {
|
||||||
updateStyle<MSVC_HINT(alignItems)>(node, &YGStyle::alignItems, alignItems);
|
updateStyle<MSVC_HINT(alignItems)>(node, &Style::alignItems, alignItems);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignItems();
|
return node->getStyle().alignItems();
|
||||||
@@ -563,7 +562,7 @@ YOGA_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
YOGA_EXPORT void YGNodeStyleSetAlignSelf(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGAlign alignSelf) {
|
const YGAlign alignSelf) {
|
||||||
updateStyle<MSVC_HINT(alignSelf)>(node, &YGStyle::alignSelf, alignSelf);
|
updateStyle<MSVC_HINT(alignSelf)>(node, &Style::alignSelf, alignSelf);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
YOGA_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeConstRef node) {
|
||||||
return node->getStyle().alignSelf();
|
return node->getStyle().alignSelf();
|
||||||
@@ -573,7 +572,7 @@ YOGA_EXPORT void YGNodeStyleSetPositionType(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGPositionType positionType) {
|
const YGPositionType positionType) {
|
||||||
updateStyle<MSVC_HINT(positionType)>(
|
updateStyle<MSVC_HINT(positionType)>(
|
||||||
node, &YGStyle::positionType, positionType);
|
node, &Style::positionType, positionType);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGPositionType
|
YOGA_EXPORT YGPositionType
|
||||||
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
||||||
@@ -583,7 +582,7 @@ YGNodeStyleGetPositionType(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
YOGA_EXPORT void YGNodeStyleSetFlexWrap(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGWrap flexWrap) {
|
const YGWrap flexWrap) {
|
||||||
updateStyle<MSVC_HINT(flexWrap)>(node, &YGStyle::flexWrap, flexWrap);
|
updateStyle<MSVC_HINT(flexWrap)>(node, &Style::flexWrap, flexWrap);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
||||||
return node->getStyle().flexWrap();
|
return node->getStyle().flexWrap();
|
||||||
@@ -592,7 +591,7 @@ YOGA_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
YOGA_EXPORT void YGNodeStyleSetOverflow(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGOverflow overflow) {
|
const YGOverflow overflow) {
|
||||||
updateStyle<MSVC_HINT(overflow)>(node, &YGStyle::overflow, overflow);
|
updateStyle<MSVC_HINT(overflow)>(node, &Style::overflow, overflow);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
||||||
return node->getStyle().overflow();
|
return node->getStyle().overflow();
|
||||||
@@ -601,7 +600,7 @@ YOGA_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
YOGA_EXPORT void YGNodeStyleSetDisplay(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGDisplay display) {
|
const YGDisplay display) {
|
||||||
updateStyle<MSVC_HINT(display)>(node, &YGStyle::display, display);
|
updateStyle<MSVC_HINT(display)>(node, &Style::display, display);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
||||||
return node->getStyle().display();
|
return node->getStyle().display();
|
||||||
@@ -609,7 +608,7 @@ YOGA_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
|
|||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
YOGA_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
|
||||||
updateStyle<MSVC_HINT(flex)>(node, &YGStyle::flex, YGFloatOptional{flex});
|
updateStyle<MSVC_HINT(flex)>(node, &Style::flex, YGFloatOptional{flex});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
@@ -624,7 +623,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexGrow(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexGrow) {
|
const float flexGrow) {
|
||||||
updateStyle<MSVC_HINT(flexGrow)>(
|
updateStyle<MSVC_HINT(flexGrow)>(
|
||||||
node, &YGStyle::flexGrow, YGFloatOptional{flexGrow});
|
node, &Style::flexGrow, YGFloatOptional{flexGrow});
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
// TODO(T26792433): Change the API to accept YGFloatOptional.
|
||||||
@@ -632,7 +631,7 @@ YOGA_EXPORT void YGNodeStyleSetFlexShrink(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexShrink) {
|
const float flexShrink) {
|
||||||
updateStyle<MSVC_HINT(flexShrink)>(
|
updateStyle<MSVC_HINT(flexShrink)>(
|
||||||
node, &YGStyle::flexShrink, YGFloatOptional{flexShrink});
|
node, &Style::flexShrink, YGFloatOptional{flexShrink});
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
||||||
@@ -647,37 +646,37 @@ YOGA_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetFlexBasis(
|
YOGA_EXPORT void YGNodeStyleSetFlexBasis(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexBasis) {
|
const float flexBasis) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(flexBasis);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(flexBasis);
|
||||||
updateStyle<MSVC_HINT(flexBasis)>(node, &YGStyle::flexBasis, value);
|
updateStyle<MSVC_HINT(flexBasis)>(node, &Style::flexBasis, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent(
|
YOGA_EXPORT void YGNodeStyleSetFlexBasisPercent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float flexBasisPercent) {
|
const float flexBasisPercent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(flexBasisPercent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(flexBasisPercent);
|
||||||
updateStyle<MSVC_HINT(flexBasis)>(node, &YGStyle::flexBasis, value);
|
updateStyle<MSVC_HINT(flexBasis)>(node, &Style::flexBasis, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
|
YOGA_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
|
||||||
updateStyle<MSVC_HINT(flexBasis)>(
|
updateStyle<MSVC_HINT(flexBasis)>(
|
||||||
node, &YGStyle::flexBasis, detail::CompactValue::ofAuto());
|
node, &Style::flexBasis, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetPosition(
|
YOGA_EXPORT void YGNodeStyleSetPosition(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float points) {
|
float points) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<MSVC_HINT(position)>(
|
updateIndexedStyleProp<MSVC_HINT(position)>(
|
||||||
node, &YGStyle::position, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetPositionPercent(
|
YOGA_EXPORT void YGNodeStyleSetPositionPercent(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float percent) {
|
float percent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<MSVC_HINT(position)>(
|
updateIndexedStyleProp<MSVC_HINT(position)>(
|
||||||
node, &YGStyle::position, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
||||||
return node->getStyle().position()[edge];
|
return node->getStyle().position()[edge];
|
||||||
@@ -687,21 +686,19 @@ YOGA_EXPORT void YGNodeStyleSetMargin(
|
|||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float points) {
|
float points) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<MSVC_HINT(margin)>(
|
updateIndexedStyleProp<MSVC_HINT(margin)>(node, &Style::margin, edge, value);
|
||||||
node, &YGStyle::margin, edge, value);
|
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMarginPercent(
|
YOGA_EXPORT void YGNodeStyleSetMarginPercent(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float percent) {
|
float percent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<MSVC_HINT(margin)>(
|
updateIndexedStyleProp<MSVC_HINT(margin)>(node, &Style::margin, edge, value);
|
||||||
node, &YGStyle::margin, edge, value);
|
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
YOGA_EXPORT void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
||||||
updateIndexedStyleProp<MSVC_HINT(margin)>(
|
updateIndexedStyleProp<MSVC_HINT(margin)>(
|
||||||
node, &YGStyle::margin, edge, detail::CompactValue::ofAuto());
|
node, &Style::margin, edge, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
||||||
return node->getStyle().margin()[edge];
|
return node->getStyle().margin()[edge];
|
||||||
@@ -711,17 +708,17 @@ YOGA_EXPORT void YGNodeStyleSetPadding(
|
|||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float points) {
|
float points) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
||||||
node, &YGStyle::padding, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetPaddingPercent(
|
YOGA_EXPORT void YGNodeStyleSetPaddingPercent(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
YGEdge edge,
|
YGEdge edge,
|
||||||
float percent) {
|
float percent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
||||||
node, &YGStyle::padding, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
YOGA_EXPORT YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
||||||
return node->getStyle().padding()[edge];
|
return node->getStyle().padding()[edge];
|
||||||
@@ -732,9 +729,8 @@ YOGA_EXPORT void YGNodeStyleSetBorder(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
const float border) {
|
const float border) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(border);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(border);
|
||||||
updateIndexedStyleProp<MSVC_HINT(border)>(
|
updateIndexedStyleProp<MSVC_HINT(border)>(node, &Style::border, edge, value);
|
||||||
node, &YGStyle::border, edge, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetBorder(
|
YOGA_EXPORT float YGNodeStyleGetBorder(
|
||||||
@@ -754,8 +750,8 @@ YOGA_EXPORT void YGNodeStyleSetGap(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const YGGutter gutter,
|
const YGGutter gutter,
|
||||||
const float gapLength) {
|
const float gapLength) {
|
||||||
auto length = detail::CompactValue::ofMaybe<YGUnitPoint>(gapLength);
|
auto length = CompactValue::ofMaybe<YGUnitPoint>(gapLength);
|
||||||
updateIndexedStyleProp<MSVC_HINT(gap)>(node, &YGStyle::gap, gutter, length);
|
updateIndexedStyleProp<MSVC_HINT(gap)>(node, &Style::gap, gutter, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT float YGNodeStyleGetGap(
|
YOGA_EXPORT float YGNodeStyleGetGap(
|
||||||
@@ -784,46 +780,40 @@ YOGA_EXPORT void YGNodeStyleSetAspectRatio(
|
|||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float aspectRatio) {
|
const float aspectRatio) {
|
||||||
updateStyle<MSVC_HINT(aspectRatio)>(
|
updateStyle<MSVC_HINT(aspectRatio)>(
|
||||||
node, &YGStyle::aspectRatio, YGFloatOptional{aspectRatio});
|
node, &Style::aspectRatio, YGFloatOptional{aspectRatio});
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
YOGA_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float points) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node, &YGStyle::dimensions, YGDimensionWidth, value);
|
node, &Style::dimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
|
YOGA_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node, &YGStyle::dimensions, YGDimensionWidth, value);
|
node, &Style::dimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
YOGA_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node) {
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node,
|
node, &Style::dimensions, YGDimensionWidth, CompactValue::ofAuto());
|
||||||
&YGStyle::dimensions,
|
|
||||||
YGDimensionWidth,
|
|
||||||
detail::CompactValue::ofAuto());
|
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
|
||||||
return node->getStyle().dimensions()[YGDimensionWidth];
|
return node->getStyle().dimensions()[YGDimensionWidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
YOGA_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float points) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node, &YGStyle::dimensions, YGDimensionHeight, value);
|
node, &Style::dimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
|
YOGA_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node, &YGStyle::dimensions, YGDimensionHeight, value);
|
node, &Style::dimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
YOGA_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node) {
|
||||||
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(dimensions)>(
|
||||||
node,
|
node, &Style::dimensions, YGDimensionHeight, CompactValue::ofAuto());
|
||||||
&YGStyle::dimensions,
|
|
||||||
YGDimensionHeight,
|
|
||||||
detail::CompactValue::ofAuto());
|
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
||||||
return node->getStyle().dimensions()[YGDimensionHeight];
|
return node->getStyle().dimensions()[YGDimensionHeight];
|
||||||
@@ -832,16 +822,16 @@ YOGA_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
YOGA_EXPORT void YGNodeStyleSetMinWidth(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float minWidth) {
|
const float minWidth) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(minWidth);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(minWidth);
|
||||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||||
node, &YGStyle::minDimensions, YGDimensionWidth, value);
|
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinWidthPercent(
|
YOGA_EXPORT void YGNodeStyleSetMinWidthPercent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float minWidth) {
|
const float minWidth) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(minWidth);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(minWidth);
|
||||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||||
node, &YGStyle::minDimensions, YGDimensionWidth, value);
|
node, &Style::minDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
||||||
return node->getStyle().minDimensions()[YGDimensionWidth];
|
return node->getStyle().minDimensions()[YGDimensionWidth];
|
||||||
@@ -850,16 +840,16 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
YOGA_EXPORT void YGNodeStyleSetMinHeight(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float minHeight) {
|
const float minHeight) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(minHeight);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(minHeight);
|
||||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||||
node, &YGStyle::minDimensions, YGDimensionHeight, value);
|
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMinHeightPercent(
|
YOGA_EXPORT void YGNodeStyleSetMinHeightPercent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float minHeight) {
|
const float minHeight) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(minHeight);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(minHeight);
|
||||||
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(minDimensions)>(
|
||||||
node, &YGStyle::minDimensions, YGDimensionHeight, value);
|
node, &Style::minDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
||||||
return node->getStyle().minDimensions()[YGDimensionHeight];
|
return node->getStyle().minDimensions()[YGDimensionHeight];
|
||||||
@@ -868,16 +858,16 @@ YOGA_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
YOGA_EXPORT void YGNodeStyleSetMaxWidth(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float maxWidth) {
|
const float maxWidth) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(maxWidth);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxWidth);
|
||||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||||
node, &YGStyle::maxDimensions, YGDimensionWidth, value);
|
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
YOGA_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float maxWidth) {
|
const float maxWidth) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(maxWidth);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxWidth);
|
||||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||||
node, &YGStyle::maxDimensions, YGDimensionWidth, value);
|
node, &Style::maxDimensions, YGDimensionWidth, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
||||||
return node->getStyle().maxDimensions()[YGDimensionWidth];
|
return node->getStyle().maxDimensions()[YGDimensionWidth];
|
||||||
@@ -886,16 +876,16 @@ YOGA_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
|
|||||||
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
YOGA_EXPORT void YGNodeStyleSetMaxHeight(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float maxHeight) {
|
const float maxHeight) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPoint>(maxHeight);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(maxHeight);
|
||||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||||
node, &YGStyle::maxDimensions, YGDimensionHeight, value);
|
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
YOGA_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
const float maxHeight) {
|
const float maxHeight) {
|
||||||
auto value = detail::CompactValue::ofMaybe<YGUnitPercent>(maxHeight);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(maxHeight);
|
||||||
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
updateIndexedStyleProp<MSVC_HINT(maxDimensions)>(
|
||||||
node, &YGStyle::maxDimensions, YGDimensionHeight, value);
|
node, &Style::maxDimensions, YGDimensionHeight, value);
|
||||||
}
|
}
|
||||||
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
YOGA_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
|
||||||
return node->getStyle().maxDimensions()[YGDimensionHeight];
|
return node->getStyle().maxDimensions()[YGDimensionHeight];
|
||||||
@@ -2519,7 +2509,7 @@ static void YGJustifyMainAxis(
|
|||||||
i < collectedFlexItemsValues.endOfLineIndex;
|
i < collectedFlexItemsValues.endOfLineIndex;
|
||||||
i++) {
|
i++) {
|
||||||
const YGNodeRef child = node->getChild(i);
|
const YGNodeRef child = node->getChild(i);
|
||||||
const YGStyle& childStyle = child->getStyle();
|
const Style& childStyle = child->getStyle();
|
||||||
const YGLayout childLayout = child->getLayout();
|
const YGLayout childLayout = child->getLayout();
|
||||||
const bool isLastChild = i == collectedFlexItemsValues.endOfLineIndex - 1;
|
const bool isLastChild = i == collectedFlexItemsValues.endOfLineIndex - 1;
|
||||||
// remove the gap if it is the last element of the line
|
// remove the gap if it is the last element of the line
|
||||||
|
@@ -38,7 +38,7 @@ static_assert(
|
|||||||
#define VISIBLE_FOR_TESTING private:
|
#define VISIBLE_FOR_TESTING private:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace facebook::yoga::detail {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
// This class stores YGValue in 32 bits.
|
// This class stores YGValue in 32 bits.
|
||||||
// - The value does not matter for Undefined and Auto. NaNs are used for their
|
// - The value does not matter for Undefined and Auto. NaNs are used for their
|
||||||
@@ -207,4 +207,4 @@ constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
|
|||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace facebook::yoga::detail
|
} // namespace facebook::yoga
|
@@ -5,11 +5,13 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGStyle.h"
|
#include <yoga/style/Style.h>
|
||||||
#include "Utils.h"
|
#include <yoga/Utils.h>
|
||||||
|
|
||||||
|
namespace facebook::yoga {
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
|
bool operator==(const Style& lhs, const Style& rhs) {
|
||||||
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
|
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
|
||||||
lhs.flexDirection() == rhs.flexDirection() &&
|
lhs.flexDirection() == rhs.flexDirection() &&
|
||||||
lhs.justifyContent() == rhs.justifyContent() &&
|
lhs.justifyContent() == rhs.justifyContent() &&
|
||||||
@@ -54,3 +56,5 @@ bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
|
|||||||
|
|
||||||
return areNonFloatValuesEqual;
|
return areNonFloatValuesEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace facebook::yoga
|
@@ -13,17 +13,17 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
#include <yoga/YGFloatOptional.h>
|
||||||
|
#include <yoga/Yoga-internal.h>
|
||||||
|
#include <yoga/BitUtils.h>
|
||||||
|
|
||||||
#include "CompactValue.h"
|
#include <yoga/style/CompactValue.h>
|
||||||
#include "YGFloatOptional.h"
|
|
||||||
#include "Yoga-internal.h"
|
|
||||||
#include "BitUtils.h"
|
|
||||||
|
|
||||||
class YOGA_EXPORT YGStyle {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
class YOGA_EXPORT Style {
|
||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
using Values =
|
using Values = detail::Values<enums::count<Enum>()>;
|
||||||
facebook::yoga::detail::Values<facebook::yoga::enums::count<Enum>()>;
|
|
||||||
using CompactValue = facebook::yoga::detail::CompactValue;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Dimensions = Values<YGDimension>;
|
using Dimensions = Values<YGDimension>;
|
||||||
@@ -32,7 +32,7 @@ public:
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct BitfieldRef {
|
struct BitfieldRef {
|
||||||
YGStyle& style;
|
Style& style;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
operator T() const {
|
operator T() const {
|
||||||
return facebook::yoga::detail::getEnumData<T>(style.flags, offset);
|
return facebook::yoga::detail::getEnumData<T>(style.flags, offset);
|
||||||
@@ -43,9 +43,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, T YGStyle::*Prop>
|
template <typename T, T Style::*Prop>
|
||||||
struct Ref {
|
struct Ref {
|
||||||
YGStyle& style;
|
Style& style;
|
||||||
operator T() const { return style.*Prop; }
|
operator T() const { return style.*Prop; }
|
||||||
Ref<T, Prop>& operator=(T value) {
|
Ref<T, Prop>& operator=(T value) {
|
||||||
style.*Prop = value;
|
style.*Prop = value;
|
||||||
@@ -53,10 +53,10 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Idx, Values<Idx> YGStyle::*Prop>
|
template <typename Idx, Values<Idx> Style::*Prop>
|
||||||
struct IdxRef {
|
struct IdxRef {
|
||||||
struct Ref {
|
struct Ref {
|
||||||
YGStyle& style;
|
Style& style;
|
||||||
Idx idx;
|
Idx idx;
|
||||||
operator CompactValue() const { return (style.*Prop)[idx]; }
|
operator CompactValue() const { return (style.*Prop)[idx]; }
|
||||||
operator YGValue() const { return (style.*Prop)[idx]; }
|
operator YGValue() const { return (style.*Prop)[idx]; }
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
YGStyle& style;
|
Style& style;
|
||||||
IdxRef<Idx, Prop>& operator=(const Values<Idx>& values) {
|
IdxRef<Idx, Prop>& operator=(const Values<Idx>& values) {
|
||||||
style.*Prop = values;
|
style.*Prop = values;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -76,11 +76,11 @@ public:
|
|||||||
CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; }
|
CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
YGStyle() {
|
Style() {
|
||||||
alignContent() = YGAlignFlexStart;
|
alignContent() = YGAlignFlexStart;
|
||||||
alignItems() = YGAlignStretch;
|
alignItems() = YGAlignStretch;
|
||||||
}
|
}
|
||||||
~YGStyle() = default;
|
~Style() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr size_t directionOffset = 0;
|
static constexpr size_t directionOffset = 0;
|
||||||
@@ -188,51 +188,52 @@ public:
|
|||||||
BitfieldRef<YGDisplay> display() { return {*this, displayOffset}; }
|
BitfieldRef<YGDisplay> display() { return {*this, displayOffset}; }
|
||||||
|
|
||||||
YGFloatOptional flex() const { return flex_; }
|
YGFloatOptional flex() const { return flex_; }
|
||||||
Ref<YGFloatOptional, &YGStyle::flex_> flex() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flex_> flex() { return {*this}; }
|
||||||
|
|
||||||
YGFloatOptional flexGrow() const { return flexGrow_; }
|
YGFloatOptional flexGrow() const { return flexGrow_; }
|
||||||
Ref<YGFloatOptional, &YGStyle::flexGrow_> flexGrow() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flexGrow_> flexGrow() { return {*this}; }
|
||||||
|
|
||||||
YGFloatOptional flexShrink() const { return flexShrink_; }
|
YGFloatOptional flexShrink() const { return flexShrink_; }
|
||||||
Ref<YGFloatOptional, &YGStyle::flexShrink_> flexShrink() { return {*this}; }
|
Ref<YGFloatOptional, &Style::flexShrink_> flexShrink() { return {*this}; }
|
||||||
|
|
||||||
CompactValue flexBasis() const { return flexBasis_; }
|
CompactValue flexBasis() const { return flexBasis_; }
|
||||||
Ref<CompactValue, &YGStyle::flexBasis_> flexBasis() { return {*this}; }
|
Ref<CompactValue, &Style::flexBasis_> flexBasis() { return {*this}; }
|
||||||
|
|
||||||
const Edges& margin() const { return margin_; }
|
const Edges& margin() const { return margin_; }
|
||||||
IdxRef<YGEdge, &YGStyle::margin_> margin() { return {*this}; }
|
IdxRef<YGEdge, &Style::margin_> margin() { return {*this}; }
|
||||||
|
|
||||||
const Edges& position() const { return position_; }
|
const Edges& position() const { return position_; }
|
||||||
IdxRef<YGEdge, &YGStyle::position_> position() { return {*this}; }
|
IdxRef<YGEdge, &Style::position_> position() { return {*this}; }
|
||||||
|
|
||||||
const Edges& padding() const { return padding_; }
|
const Edges& padding() const { return padding_; }
|
||||||
IdxRef<YGEdge, &YGStyle::padding_> padding() { return {*this}; }
|
IdxRef<YGEdge, &Style::padding_> padding() { return {*this}; }
|
||||||
|
|
||||||
const Edges& border() const { return border_; }
|
const Edges& border() const { return border_; }
|
||||||
IdxRef<YGEdge, &YGStyle::border_> border() { return {*this}; }
|
IdxRef<YGEdge, &Style::border_> border() { return {*this}; }
|
||||||
|
|
||||||
const Gutters& gap() const { return gap_; }
|
const Gutters& gap() const { return gap_; }
|
||||||
IdxRef<YGGutter, &YGStyle::gap_> gap() { return {*this}; }
|
IdxRef<YGGutter, &Style::gap_> gap() { return {*this}; }
|
||||||
|
|
||||||
const Dimensions& dimensions() const { return dimensions_; }
|
const Dimensions& dimensions() const { return dimensions_; }
|
||||||
IdxRef<YGDimension, &YGStyle::dimensions_> dimensions() { return {*this}; }
|
IdxRef<YGDimension, &Style::dimensions_> dimensions() { return {*this}; }
|
||||||
|
|
||||||
const Dimensions& minDimensions() const { return minDimensions_; }
|
const Dimensions& minDimensions() const { return minDimensions_; }
|
||||||
IdxRef<YGDimension, &YGStyle::minDimensions_> minDimensions() {
|
IdxRef<YGDimension, &Style::minDimensions_> minDimensions() {
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dimensions& maxDimensions() const { return maxDimensions_; }
|
const Dimensions& maxDimensions() const { return maxDimensions_; }
|
||||||
IdxRef<YGDimension, &YGStyle::maxDimensions_> maxDimensions() {
|
IdxRef<YGDimension, &Style::maxDimensions_> maxDimensions() {
|
||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
YGFloatOptional aspectRatio() const { return aspectRatio_; }
|
YGFloatOptional aspectRatio() const { return aspectRatio_; }
|
||||||
Ref<YGFloatOptional, &YGStyle::aspectRatio_> aspectRatio() { return {*this}; }
|
Ref<YGFloatOptional, &Style::aspectRatio_> aspectRatio() { return {*this}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs);
|
YOGA_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
||||||
YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) {
|
YOGA_EXPORT inline bool operator!=(const Style& lhs, const Style& rhs) {
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
} // namespace facebook::yoga
|
Reference in New Issue
Block a user