Revert D50998164: Allow lazy resolution of edge dimension values
Differential Revision: D50998164 Original commit changeset: 248396f9587e Original Phabricator Diff: D50998164 fbshipit-source-id: 4f592158324d758bb9e3731ced36b8e3587c459c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f2c8acad2c
commit
27af596359
216
tests/YGStyleAccessorsTest.cpp
Normal file
216
tests/YGStyleAccessorsTest.cpp
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <yoga/style/Style.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
#define ACCESSOR_TESTS_1(NAME, X) \
|
||||||
|
style.NAME() = X; \
|
||||||
|
ASSERT_EQ(style.NAME(), X);
|
||||||
|
#define ACCESSOR_TESTS_2(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_1(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_3(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_2(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_4(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_3(NAME, __VA_ARGS__);
|
||||||
|
#define ACCESSOR_TESTS_5(NAME, X, ...) \
|
||||||
|
ACCESSOR_TESTS_1(NAME, X); \
|
||||||
|
ACCESSOR_TESTS_4(NAME, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) ACCESSOR_TESTS_##COUNT
|
||||||
|
#define ACCESSOR_TESTS(...) ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
{ \
|
||||||
|
auto style = Style{}; \
|
||||||
|
style.NAME()[IDX] = X; \
|
||||||
|
ASSERT_EQ(style.NAME()[IDX], X); \
|
||||||
|
auto asArray = decltype(std::declval<const Style&>().NAME()){X}; \
|
||||||
|
style.NAME() = asArray; \
|
||||||
|
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_2(NAME, IDX, X, Y) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, Y)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_3(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_2(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_4(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_3(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_5(NAME, IDX, X, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_1(NAME, IDX, X) \
|
||||||
|
INDEX_ACCESSOR_TESTS_4(NAME, IDX, __VA_ARGS__)
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TESTS_N(a, b, c, d, e, COUNT, ...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_##COUNT
|
||||||
|
#define INDEX_ACCESSOR_TESTS(...) \
|
||||||
|
INDEX_ACCESSOR_TESTS_N(__VA_ARGS__, 5, 4, 3, 2, 1)
|
||||||
|
|
||||||
|
// test macro for up to 5 values. If more are needed, extend the macros above.
|
||||||
|
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
|
||||||
|
TEST(Style, style_##NAME##_access) { \
|
||||||
|
auto style = Style{}; \
|
||||||
|
ASSERT_EQ(style.NAME(), DEFAULT_VAL); \
|
||||||
|
ACCESSOR_TESTS(__VA_ARGS__)(NAME, __VA_ARGS__) \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INDEX_ACCESSOR_TEST(NAME, DEFAULT_VAL, IDX, ...) \
|
||||||
|
TEST(Style, style_##NAME##_access) { \
|
||||||
|
ASSERT_EQ(Style{}.NAME()[IDX], DEFAULT_VAL); \
|
||||||
|
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
// TODO: MSVC doesn't like the macros
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
direction,
|
||||||
|
Direction::Inherit,
|
||||||
|
Direction::LTR,
|
||||||
|
Direction::RTL,
|
||||||
|
Direction::Inherit);
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexDirection,
|
||||||
|
FlexDirection::Column,
|
||||||
|
FlexDirection::ColumnReverse,
|
||||||
|
FlexDirection::RowReverse,
|
||||||
|
FlexDirection::Row)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
justifyContent,
|
||||||
|
Justify::FlexStart,
|
||||||
|
Justify::FlexEnd,
|
||||||
|
Justify::SpaceAround,
|
||||||
|
Justify::FlexStart,
|
||||||
|
Justify::SpaceEvenly)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignContent,
|
||||||
|
Align::FlexStart,
|
||||||
|
Align::Auto,
|
||||||
|
Align::FlexStart,
|
||||||
|
Align::Center,
|
||||||
|
Align::FlexEnd,
|
||||||
|
Align::Stretch)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignItems,
|
||||||
|
Align::Stretch,
|
||||||
|
Align::FlexStart,
|
||||||
|
Align::FlexEnd,
|
||||||
|
Align::Baseline,
|
||||||
|
Align::SpaceBetween,
|
||||||
|
Align::SpaceAround)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
alignSelf,
|
||||||
|
Align::Auto,
|
||||||
|
Align::FlexStart,
|
||||||
|
Align::Center,
|
||||||
|
Align::Auto,
|
||||||
|
Align::FlexEnd,
|
||||||
|
Align::Stretch)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
positionType,
|
||||||
|
PositionType::Static,
|
||||||
|
PositionType::Absolute,
|
||||||
|
PositionType::Relative)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(flexWrap, Wrap::NoWrap, Wrap::Wrap, Wrap::WrapReverse)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(overflow, Overflow::Visible, Overflow::Hidden, Overflow::Scroll)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(display, Display::Flex, Display::None, Display::Flex)
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flex,
|
||||||
|
FloatOptional{},
|
||||||
|
FloatOptional{123.45f},
|
||||||
|
FloatOptional{-9.87f},
|
||||||
|
FloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexGrow,
|
||||||
|
FloatOptional{},
|
||||||
|
FloatOptional{123.45f},
|
||||||
|
FloatOptional{-9.87f},
|
||||||
|
FloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexShrink,
|
||||||
|
FloatOptional{},
|
||||||
|
FloatOptional{123.45f},
|
||||||
|
FloatOptional{-9.87f},
|
||||||
|
FloatOptional{})
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
flexBasis,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
position,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeBottom,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
margin,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeTop,
|
||||||
|
CompactValue::ofAuto(),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
padding,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeAll,
|
||||||
|
CompactValue::of<YGUnitPoint>(7777.77f),
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
CompactValue::of<YGUnitPercent>(-100.0f))
|
||||||
|
|
||||||
|
INDEX_ACCESSOR_TEST(
|
||||||
|
border,
|
||||||
|
CompactValue::ofUndefined(),
|
||||||
|
YGEdgeHorizontal,
|
||||||
|
CompactValue::of<YGUnitPoint>(-7777.77f),
|
||||||
|
CompactValue::ofUndefined())
|
||||||
|
|
||||||
|
ACCESSOR_TEST(
|
||||||
|
aspectRatio,
|
||||||
|
FloatOptional{},
|
||||||
|
FloatOptional{-123.45f},
|
||||||
|
FloatOptional{9876.5f},
|
||||||
|
FloatOptional{0.0f},
|
||||||
|
FloatOptional{});
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace facebook::yoga
|
@@ -35,6 +35,19 @@ void updateStyle(YGNodeRef node, Ref (Style::*prop)(), T value) {
|
|||||||
[prop](Style& s, T x) { (s.*prop)() = x; });
|
[prop](Style& s, T x) { (s.*prop)() = x; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Ref, typename Idx>
|
||||||
|
void updateIndexedStyleProp(
|
||||||
|
YGNodeRef node,
|
||||||
|
Ref (Style::*prop)(),
|
||||||
|
Idx idx,
|
||||||
|
CompactValue value) {
|
||||||
|
updateStyle(
|
||||||
|
resolveRef(node),
|
||||||
|
value,
|
||||||
|
[idx, prop](Style& s, CompactValue x) { return (s.*prop)()[idx] != x; },
|
||||||
|
[idx, prop](Style& s, CompactValue x) { (s.*prop)()[idx] = x; });
|
||||||
|
}
|
||||||
|
|
||||||
template <auto GetterT, auto SetterT, typename IdxT>
|
template <auto GetterT, auto SetterT, typename IdxT>
|
||||||
void updateIndexedStyleProp(YGNodeRef node, IdxT idx, CompactValue value) {
|
void updateIndexedStyleProp(YGNodeRef node, IdxT idx, CompactValue value) {
|
||||||
updateStyle(
|
updateStyle(
|
||||||
@@ -224,53 +237,53 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
|
|||||||
|
|
||||||
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
|
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<&Style::position, &Style::setPosition>(
|
updateIndexedStyleProp<MSVC_HINT(position)>(
|
||||||
node, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
|
void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<&Style::position, &Style::setPosition>(
|
updateIndexedStyleProp<MSVC_HINT(position)>(
|
||||||
node, edge, value);
|
node, &Style::position, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
|
||||||
return resolveRef(node)->getStyle().position(edge);
|
return resolveRef(node)->getStyle().position()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
|
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<&Style::margin, &Style::setMargin>(node, edge, value);
|
updateIndexedStyleProp<MSVC_HINT(margin)>(node, &Style::margin, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
|
void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<&Style::margin, &Style::setMargin>(node, edge, value);
|
updateIndexedStyleProp<MSVC_HINT(margin)>(node, &Style::margin, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
|
||||||
updateIndexedStyleProp<&Style::margin, &Style::setMargin>(
|
updateIndexedStyleProp<MSVC_HINT(margin)>(
|
||||||
node, edge, CompactValue::ofAuto());
|
node, &Style::margin, edge, CompactValue::ofAuto());
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
|
||||||
return resolveRef(node)->getStyle().margin(edge);
|
return resolveRef(node)->getStyle().margin()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
|
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(points);
|
||||||
updateIndexedStyleProp<&Style::padding, &Style::setPadding>(
|
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
||||||
node, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
|
void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
auto value = CompactValue::ofMaybe<YGUnitPercent>(percent);
|
||||||
updateIndexedStyleProp<&Style::padding, &Style::setPadding>(
|
updateIndexedStyleProp<MSVC_HINT(padding)>(
|
||||||
node, edge, value);
|
node, &Style::padding, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
|
||||||
return resolveRef(node)->getStyle().padding(edge);
|
return resolveRef(node)->getStyle().padding()[edge];
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGNodeStyleSetBorder(
|
void YGNodeStyleSetBorder(
|
||||||
@@ -278,11 +291,11 @@ void YGNodeStyleSetBorder(
|
|||||||
const YGEdge edge,
|
const YGEdge edge,
|
||||||
const float border) {
|
const float border) {
|
||||||
auto value = CompactValue::ofMaybe<YGUnitPoint>(border);
|
auto value = CompactValue::ofMaybe<YGUnitPoint>(border);
|
||||||
updateIndexedStyleProp<&Style::border, &Style::setBorder>(node, edge, value);
|
updateIndexedStyleProp<MSVC_HINT(border)>(node, &Style::border, edge, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
|
float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
|
||||||
auto border = resolveRef(node)->getStyle().border(edge);
|
auto border = resolveRef(node)->getStyle().border()[edge];
|
||||||
if (border.isUndefined() || border.isAuto()) {
|
if (border.isUndefined() || border.isAuto()) {
|
||||||
return YGUndefined;
|
return YGUndefined;
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include <yoga/debug/AssertFatal.h>
|
#include <yoga/debug/AssertFatal.h>
|
||||||
#include <yoga/enums/Dimension.h>
|
#include <yoga/enums/Dimension.h>
|
||||||
#include <yoga/enums/Direction.h>
|
|
||||||
#include <yoga/enums/FlexDirection.h>
|
#include <yoga/enums/FlexDirection.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
@@ -7,10 +7,8 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <yoga/config/Config.h>
|
|
||||||
#include <yoga/debug/AssertFatal.h>
|
#include <yoga/debug/AssertFatal.h>
|
||||||
#include <yoga/debug/Log.h>
|
#include <yoga/debug/Log.h>
|
||||||
#include <yoga/node/Node.h>
|
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
|
@@ -8,12 +8,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
#include <yoga/config/Config.h>
|
||||||
|
#include <yoga/node/Node.h>
|
||||||
|
|
||||||
namespace facebook::yoga {
|
namespace facebook::yoga {
|
||||||
|
|
||||||
class Node;
|
|
||||||
class Config;
|
|
||||||
|
|
||||||
[[noreturn]] void fatalWithMessage(const char* message);
|
[[noreturn]] void fatalWithMessage(const char* message);
|
||||||
|
|
||||||
void assertFatal(bool condition, const char* message);
|
void assertFatal(bool condition, const char* message);
|
||||||
|
@@ -23,6 +23,12 @@ static void indent(std::string& base, uint32_t level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool areFourValuesEqual(const Style::Edges& four) {
|
||||||
|
return yoga::inexactEquals(four[0], four[1]) &&
|
||||||
|
yoga::inexactEquals(four[0], four[2]) &&
|
||||||
|
yoga::inexactEquals(four[0], four[3]);
|
||||||
|
}
|
||||||
|
|
||||||
static void appendFormattedString(std::string& str, const char* fmt, ...) {
|
static void appendFormattedString(std::string& str, const char* fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -80,13 +86,31 @@ static void appendNumberIfNotZero(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <auto Field>
|
static void appendEdges(
|
||||||
static void
|
std::string& base,
|
||||||
appendEdges(std::string& base, const std::string& key, const Style& style) {
|
const std::string& key,
|
||||||
|
const Style::Edges& edges) {
|
||||||
|
if (areFourValuesEqual(edges)) {
|
||||||
|
auto edgeValue = yoga::Node::computeEdgeValueForColumn(edges, YGEdgeLeft);
|
||||||
|
appendNumberIfNotUndefined(base, key, edgeValue);
|
||||||
|
} else {
|
||||||
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
|
for (int edge = YGEdgeLeft; edge != YGEdgeAll; ++edge) {
|
||||||
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
|
std::string str = key + "-" + YGEdgeToString(static_cast<YGEdge>(edge));
|
||||||
appendNumberIfNotZero(base, str, (style.*Field)(static_cast<YGEdge>(edge)));
|
appendNumberIfNotZero(base, str, edges[static_cast<size_t>(edge)]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void appendEdgeIfNotUndefined(
|
||||||
|
std::string& base,
|
||||||
|
const std::string& str,
|
||||||
|
const Style::Edges& edges,
|
||||||
|
const YGEdge edge) {
|
||||||
|
// TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account
|
||||||
|
auto value = (edge == YGEdgeLeft || edge == YGEdgeRight)
|
||||||
|
? yoga::Node::computeEdgeValueForRow(edges, edge, edge)
|
||||||
|
: yoga::Node::computeEdgeValueForColumn(edges, edge);
|
||||||
|
appendNumberIfNotUndefined(base, str, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nodeToString(
|
void nodeToString(
|
||||||
@@ -149,9 +173,9 @@ void nodeToString(
|
|||||||
if (style.display() != yoga::Node{}.getStyle().display()) {
|
if (style.display() != yoga::Node{}.getStyle().display()) {
|
||||||
appendFormattedString(str, "display: %s; ", toString(style.display()));
|
appendFormattedString(str, "display: %s; ", toString(style.display()));
|
||||||
}
|
}
|
||||||
appendEdges<&Style::margin>(str, "margin", style);
|
appendEdges(str, "margin", style.margin());
|
||||||
appendEdges<&Style::padding>(str, "padding", style);
|
appendEdges(str, "padding", style.padding());
|
||||||
appendEdges<&Style::border>(str, "border", style);
|
appendEdges(str, "border", style.border());
|
||||||
|
|
||||||
if (style.gap(Gutter::All).isDefined()) {
|
if (style.gap(Gutter::All).isDefined()) {
|
||||||
appendNumberIfNotUndefined(str, "gap", style.gap(Gutter::All));
|
appendNumberIfNotUndefined(str, "gap", style.gap(Gutter::All));
|
||||||
@@ -176,7 +200,10 @@ void nodeToString(
|
|||||||
str, "position: %s; ", toString(style.positionType()));
|
str, "position: %s; ", toString(style.positionType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
appendEdges<&Style::position>(str, "position", style);
|
appendEdgeIfNotUndefined(str, "left", style.position(), YGEdgeLeft);
|
||||||
|
appendEdgeIfNotUndefined(str, "right", style.position(), YGEdgeRight);
|
||||||
|
appendEdgeIfNotUndefined(str, "top", style.position(), YGEdgeTop);
|
||||||
|
appendEdgeIfNotUndefined(str, "bottom", style.position(), YGEdgeBottom);
|
||||||
appendFormattedString(str, "\" ");
|
appendFormattedString(str, "\" ");
|
||||||
|
|
||||||
if (node->hasMeasureFunc()) {
|
if (node->hasMeasureFunc()) {
|
||||||
|
@@ -56,29 +56,30 @@ void Node::print() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Edge value resolution should be moved to `yoga::Style`
|
CompactValue Node::computeEdgeValueForRow(
|
||||||
template <auto Field>
|
const Style::Edges& edges,
|
||||||
CompactValue Node::computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const {
|
YGEdge rowEdge,
|
||||||
if ((style_.*Field)(rowEdge).isDefined()) {
|
YGEdge edge) {
|
||||||
return (style_.*Field)(rowEdge);
|
if (edges[rowEdge].isDefined()) {
|
||||||
} else if ((style_.*Field)(edge).isDefined()) {
|
return edges[rowEdge];
|
||||||
return (style_.*Field)(edge);
|
} else if (edges[edge].isDefined()) {
|
||||||
} else if ((style_.*Field)(YGEdgeHorizontal).isDefined()) {
|
return edges[edge];
|
||||||
return (style_.*Field)(YGEdgeHorizontal);
|
} else if (edges[YGEdgeHorizontal].isDefined()) {
|
||||||
|
return edges[YGEdgeHorizontal];
|
||||||
} else {
|
} else {
|
||||||
return (style_.*Field)(YGEdgeAll);
|
return edges[YGEdgeAll];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Edge value resolution should be moved to `yoga::Style`
|
CompactValue Node::computeEdgeValueForColumn(
|
||||||
template <auto Field>
|
const Style::Edges& edges,
|
||||||
CompactValue Node::computeEdgeValueForColumn(YGEdge edge) const {
|
YGEdge edge) {
|
||||||
if ((style_.*Field)(edge).isDefined()) {
|
if (edges[edge].isDefined()) {
|
||||||
return (style_.*Field)(edge);
|
return edges[edge];
|
||||||
} else if ((style_.*Field)(YGEdgeVertical).isDefined()) {
|
} else if (edges[YGEdgeVertical].isDefined()) {
|
||||||
return (style_.*Field)(YGEdgeVertical);
|
return edges[YGEdgeVertical];
|
||||||
} else {
|
} else {
|
||||||
return (style_.*Field)(YGEdgeAll);
|
return edges[YGEdgeAll];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +102,8 @@ YGEdge Node::getInlineEndEdgeUsingErrata(
|
|||||||
bool Node::isFlexStartPositionDefined(FlexDirection axis) const {
|
bool Node::isFlexStartPositionDefined(FlexDirection axis) const {
|
||||||
const YGEdge startEdge = flexStartEdge(axis);
|
const YGEdge startEdge = flexStartEdge(axis);
|
||||||
auto leadingPosition = isRow(axis)
|
auto leadingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
: computeEdgeValueForColumn(style_.position(), startEdge);
|
||||||
|
|
||||||
return leadingPosition.isDefined();
|
return leadingPosition.isDefined();
|
||||||
}
|
}
|
||||||
@@ -111,8 +112,8 @@ bool Node::isInlineStartPositionDefined(FlexDirection axis, Direction direction)
|
|||||||
const {
|
const {
|
||||||
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||||
auto leadingPosition = isRow(axis)
|
auto leadingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
: computeEdgeValueForColumn(style_.position(), startEdge);
|
||||||
|
|
||||||
return leadingPosition.isDefined();
|
return leadingPosition.isDefined();
|
||||||
}
|
}
|
||||||
@@ -120,8 +121,8 @@ bool Node::isInlineStartPositionDefined(FlexDirection axis, Direction direction)
|
|||||||
bool Node::isFlexEndPositionDefined(FlexDirection axis) const {
|
bool Node::isFlexEndPositionDefined(FlexDirection axis) const {
|
||||||
const YGEdge endEdge = flexEndEdge(axis);
|
const YGEdge endEdge = flexEndEdge(axis);
|
||||||
auto trailingPosition = isRow(axis)
|
auto trailingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
: computeEdgeValueForColumn(style_.position(), endEdge);
|
||||||
|
|
||||||
return !trailingPosition.isUndefined();
|
return !trailingPosition.isUndefined();
|
||||||
}
|
}
|
||||||
@@ -130,8 +131,8 @@ bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction)
|
|||||||
const {
|
const {
|
||||||
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||||
auto trailingPosition = isRow(axis)
|
auto trailingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
: computeEdgeValueForColumn(style_.position(), endEdge);
|
||||||
|
|
||||||
return trailingPosition.isDefined();
|
return trailingPosition.isDefined();
|
||||||
}
|
}
|
||||||
@@ -139,8 +140,8 @@ bool Node::isInlineEndPositionDefined(FlexDirection axis, Direction direction)
|
|||||||
float Node::getFlexStartPosition(FlexDirection axis, float axisSize) const {
|
float Node::getFlexStartPosition(FlexDirection axis, float axisSize) const {
|
||||||
const YGEdge startEdge = flexStartEdge(axis);
|
const YGEdge startEdge = flexStartEdge(axis);
|
||||||
auto leadingPosition = isRow(axis)
|
auto leadingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
: computeEdgeValueForColumn(style_.position(), startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -151,8 +152,8 @@ float Node::getInlineStartPosition(
|
|||||||
float axisSize) const {
|
float axisSize) const {
|
||||||
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||||
auto leadingPosition = isRow(axis)
|
auto leadingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(startEdge);
|
: computeEdgeValueForColumn(style_.position(), startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
return resolveValue(leadingPosition, axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -160,8 +161,8 @@ float Node::getInlineStartPosition(
|
|||||||
float Node::getFlexEndPosition(FlexDirection axis, float axisSize) const {
|
float Node::getFlexEndPosition(FlexDirection axis, float axisSize) const {
|
||||||
const YGEdge endEdge = flexEndEdge(axis);
|
const YGEdge endEdge = flexEndEdge(axis);
|
||||||
auto trailingPosition = isRow(axis)
|
auto trailingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
: computeEdgeValueForColumn(style_.position(), endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -172,8 +173,8 @@ float Node::getInlineEndPosition(
|
|||||||
float axisSize) const {
|
float axisSize) const {
|
||||||
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||||
auto trailingPosition = isRow(axis)
|
auto trailingPosition = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::position>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.position(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::position>(endEdge);
|
: computeEdgeValueForColumn(style_.position(), endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
return resolveValue(trailingPosition, axisSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -181,8 +182,8 @@ float Node::getInlineEndPosition(
|
|||||||
float Node::getFlexStartMargin(FlexDirection axis, float widthSize) const {
|
float Node::getFlexStartMargin(FlexDirection axis, float widthSize) const {
|
||||||
const YGEdge startEdge = flexStartEdge(axis);
|
const YGEdge startEdge = flexStartEdge(axis);
|
||||||
auto leadingMargin = isRow(axis)
|
auto leadingMargin = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::margin>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.margin(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(startEdge);
|
: computeEdgeValueForColumn(style_.margin(), startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -193,8 +194,8 @@ float Node::getInlineStartMargin(
|
|||||||
float widthSize) const {
|
float widthSize) const {
|
||||||
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||||
auto leadingMargin = isRow(axis)
|
auto leadingMargin = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::margin>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.margin(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(startEdge);
|
: computeEdgeValueForColumn(style_.margin(), startEdge);
|
||||||
|
|
||||||
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
return resolveValue(leadingMargin, widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -202,8 +203,8 @@ float Node::getInlineStartMargin(
|
|||||||
float Node::getFlexEndMargin(FlexDirection axis, float widthSize) const {
|
float Node::getFlexEndMargin(FlexDirection axis, float widthSize) const {
|
||||||
const YGEdge endEdge = flexEndEdge(axis);
|
const YGEdge endEdge = flexEndEdge(axis);
|
||||||
auto trailingMargin = isRow(axis)
|
auto trailingMargin = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::margin>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.margin(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(endEdge);
|
: computeEdgeValueForColumn(style_.margin(), endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -214,8 +215,8 @@ float Node::getInlineEndMargin(
|
|||||||
float widthSize) const {
|
float widthSize) const {
|
||||||
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||||
auto trailingMargin = isRow(axis)
|
auto trailingMargin = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::margin>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.margin(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::margin>(endEdge);
|
: computeEdgeValueForColumn(style_.margin(), endEdge);
|
||||||
|
|
||||||
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
return resolveValue(trailingMargin, widthSize).unwrapOrDefault(0.0f);
|
||||||
}
|
}
|
||||||
@@ -224,8 +225,8 @@ float Node::getInlineStartBorder(FlexDirection axis, Direction direction)
|
|||||||
const {
|
const {
|
||||||
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||||
YGValue leadingBorder = isRow(axis)
|
YGValue leadingBorder = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::border>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.border(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::border>(startEdge);
|
: computeEdgeValueForColumn(style_.border(), startEdge);
|
||||||
|
|
||||||
return maxOrDefined(leadingBorder.value, 0.0f);
|
return maxOrDefined(leadingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
@@ -234,9 +235,9 @@ float Node::getFlexStartBorder(FlexDirection axis, Direction direction) const {
|
|||||||
const YGEdge leadRelativeFlexItemEdge =
|
const YGEdge leadRelativeFlexItemEdge =
|
||||||
flexStartRelativeEdge(axis, direction);
|
flexStartRelativeEdge(axis, direction);
|
||||||
YGValue leadingBorder = isRow(axis)
|
YGValue leadingBorder = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::border>(
|
? computeEdgeValueForRow(
|
||||||
leadRelativeFlexItemEdge, flexStartEdge(axis))
|
style_.border(), leadRelativeFlexItemEdge, flexStartEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::border>(flexStartEdge(axis));
|
: computeEdgeValueForColumn(style_.border(), flexStartEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(leadingBorder.value, 0.0f);
|
return maxOrDefined(leadingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
@@ -244,8 +245,8 @@ float Node::getFlexStartBorder(FlexDirection axis, Direction direction) const {
|
|||||||
float Node::getInlineEndBorder(FlexDirection axis, Direction direction) const {
|
float Node::getInlineEndBorder(FlexDirection axis, Direction direction) const {
|
||||||
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||||
YGValue trailingBorder = isRow(axis)
|
YGValue trailingBorder = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::border>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.border(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::border>(endEdge);
|
: computeEdgeValueForColumn(style_.border(), endEdge);
|
||||||
|
|
||||||
return maxOrDefined(trailingBorder.value, 0.0f);
|
return maxOrDefined(trailingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
@@ -253,9 +254,9 @@ float Node::getInlineEndBorder(FlexDirection axis, Direction direction) const {
|
|||||||
float Node::getFlexEndBorder(FlexDirection axis, Direction direction) const {
|
float Node::getFlexEndBorder(FlexDirection axis, Direction direction) const {
|
||||||
const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction);
|
const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction);
|
||||||
YGValue trailingBorder = isRow(axis)
|
YGValue trailingBorder = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::border>(
|
? computeEdgeValueForRow(
|
||||||
trailRelativeFlexItemEdge, flexEndEdge(axis))
|
style_.border(), trailRelativeFlexItemEdge, flexEndEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::border>(flexEndEdge(axis));
|
: computeEdgeValueForColumn(style_.border(), flexEndEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(trailingBorder.value, 0.0f);
|
return maxOrDefined(trailingBorder.value, 0.0f);
|
||||||
}
|
}
|
||||||
@@ -266,8 +267,8 @@ float Node::getInlineStartPadding(
|
|||||||
float widthSize) const {
|
float widthSize) const {
|
||||||
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
const YGEdge startEdge = getInlineStartEdgeUsingErrata(axis, direction);
|
||||||
auto leadingPadding = isRow(axis)
|
auto leadingPadding = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::padding>(YGEdgeStart, startEdge)
|
? computeEdgeValueForRow(style_.padding(), YGEdgeStart, startEdge)
|
||||||
: computeEdgeValueForColumn<&Style::padding>(startEdge);
|
: computeEdgeValueForColumn(style_.padding(), startEdge);
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
@@ -279,9 +280,9 @@ float Node::getFlexStartPadding(
|
|||||||
const YGEdge leadRelativeFlexItemEdge =
|
const YGEdge leadRelativeFlexItemEdge =
|
||||||
flexStartRelativeEdge(axis, direction);
|
flexStartRelativeEdge(axis, direction);
|
||||||
auto leadingPadding = isRow(axis)
|
auto leadingPadding = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::padding>(
|
? computeEdgeValueForRow(
|
||||||
leadRelativeFlexItemEdge, flexStartEdge(axis))
|
style_.padding(), leadRelativeFlexItemEdge, flexStartEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::padding>(flexStartEdge(axis));
|
: computeEdgeValueForColumn(style_.padding(), flexStartEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(resolveValue(leadingPadding, widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
@@ -292,8 +293,8 @@ float Node::getInlineEndPadding(
|
|||||||
float widthSize) const {
|
float widthSize) const {
|
||||||
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
const YGEdge endEdge = getInlineEndEdgeUsingErrata(axis, direction);
|
||||||
auto trailingPadding = isRow(axis)
|
auto trailingPadding = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::padding>(YGEdgeEnd, endEdge)
|
? computeEdgeValueForRow(style_.padding(), YGEdgeEnd, endEdge)
|
||||||
: computeEdgeValueForColumn<&Style::padding>(endEdge);
|
: computeEdgeValueForColumn(style_.padding(), endEdge);
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
@@ -304,9 +305,9 @@ float Node::getFlexEndPadding(
|
|||||||
float widthSize) const {
|
float widthSize) const {
|
||||||
const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction);
|
const YGEdge trailRelativeFlexItemEdge = flexEndRelativeEdge(axis, direction);
|
||||||
auto trailingPadding = isRow(axis)
|
auto trailingPadding = isRow(axis)
|
||||||
? computeEdgeValueForRow<&Style::padding>(
|
? computeEdgeValueForRow(
|
||||||
trailRelativeFlexItemEdge, flexEndEdge(axis))
|
style_.padding(), trailRelativeFlexItemEdge, flexEndEdge(axis))
|
||||||
: computeEdgeValueForColumn<&Style::padding>(flexEndEdge(axis));
|
: computeEdgeValueForColumn(style_.padding(), flexEndEdge(axis));
|
||||||
|
|
||||||
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
return maxOrDefined(resolveValue(trailingPadding, widthSize).unwrap(), 0.0f);
|
||||||
}
|
}
|
||||||
@@ -564,18 +565,18 @@ void Node::setPosition(
|
|||||||
}
|
}
|
||||||
|
|
||||||
YGValue Node::getFlexStartMarginValue(FlexDirection axis) const {
|
YGValue Node::getFlexStartMarginValue(FlexDirection axis) const {
|
||||||
if (isRow(axis) && style_.margin(YGEdgeStart).isDefined()) {
|
if (isRow(axis) && style_.margin()[YGEdgeStart].isDefined()) {
|
||||||
return style_.margin(YGEdgeStart);
|
return style_.margin()[YGEdgeStart];
|
||||||
} else {
|
} else {
|
||||||
return style_.margin(flexStartEdge(axis));
|
return style_.margin()[flexStartEdge(axis)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue Node::marginTrailingValue(FlexDirection axis) const {
|
YGValue Node::marginTrailingValue(FlexDirection axis) const {
|
||||||
if (isRow(axis) && style_.margin(YGEdgeEnd).isDefined()) {
|
if (isRow(axis) && style_.margin()[YGEdgeEnd].isDefined()) {
|
||||||
return style_.margin(YGEdgeEnd);
|
return style_.margin()[YGEdgeEnd];
|
||||||
} else {
|
} else {
|
||||||
return style_.margin(flexEndEdge(axis));
|
return style_.margin()[flexEndEdge(axis)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -65,12 +65,6 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
style_.alignContent() = Align::Stretch;
|
style_.alignContent() = Align::Stretch;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <auto Field>
|
|
||||||
CompactValue computeEdgeValueForColumn(YGEdge edge) const;
|
|
||||||
|
|
||||||
template <auto Field>
|
|
||||||
CompactValue computeEdgeValueForRow(YGEdge rowEdge, YGEdge edge) const;
|
|
||||||
|
|
||||||
// DANGER DANGER DANGER!
|
// DANGER DANGER DANGER!
|
||||||
// If the node assigned to has children, we'd either have to deallocate
|
// If the node assigned to has children, we'd either have to deallocate
|
||||||
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
||||||
@@ -195,6 +189,15 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
return resolvedDimensions_[static_cast<size_t>(dimension)];
|
return resolvedDimensions_[static_cast<size_t>(dimension)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CompactValue computeEdgeValueForColumn(
|
||||||
|
const Style::Edges& edges,
|
||||||
|
YGEdge edge);
|
||||||
|
|
||||||
|
static CompactValue computeEdgeValueForRow(
|
||||||
|
const Style::Edges& edges,
|
||||||
|
YGEdge rowEdge,
|
||||||
|
YGEdge edge);
|
||||||
|
|
||||||
// Methods related to positions, margin, padding and border
|
// Methods related to positions, margin, padding and border
|
||||||
bool isFlexStartPositionDefined(FlexDirection axis) const;
|
bool isFlexStartPositionDefined(FlexDirection axis) const;
|
||||||
bool isInlineStartPositionDefined(FlexDirection axis, Direction direction)
|
bool isInlineStartPositionDefined(FlexDirection axis, Direction direction)
|
||||||
|
@@ -34,11 +34,11 @@ class YG_EXPORT Style {
|
|||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
using Values = std::array<CompactValue, ordinalCount<Enum>()>;
|
using Values = std::array<CompactValue, ordinalCount<Enum>()>;
|
||||||
|
|
||||||
|
public:
|
||||||
using Dimensions = Values<Dimension>;
|
using Dimensions = Values<Dimension>;
|
||||||
using Edges = Values<YGEdge>;
|
using Edges = Values<YGEdge>;
|
||||||
using Gutters = Values<Gutter>;
|
using Gutters = Values<Gutter>;
|
||||||
|
|
||||||
public:
|
|
||||||
static constexpr float DefaultFlexGrow = 0.0f;
|
static constexpr float DefaultFlexGrow = 0.0f;
|
||||||
static constexpr float DefaultFlexShrink = 0.0f;
|
static constexpr float DefaultFlexShrink = 0.0f;
|
||||||
static constexpr float WebDefaultFlexShrink = 1.0f;
|
static constexpr float WebDefaultFlexShrink = 1.0f;
|
||||||
@@ -68,6 +68,39 @@ class YG_EXPORT Style {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename Idx, Values<Idx> Style::*Prop>
|
||||||
|
struct IdxRef {
|
||||||
|
struct Ref {
|
||||||
|
Style& style;
|
||||||
|
Idx idx;
|
||||||
|
operator CompactValue() const {
|
||||||
|
return (style.*Prop)[idx];
|
||||||
|
}
|
||||||
|
operator YGValue() const {
|
||||||
|
return (style.*Prop)[idx];
|
||||||
|
}
|
||||||
|
Ref& operator=(CompactValue value) {
|
||||||
|
(style.*Prop)[idx] = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Style& style;
|
||||||
|
IdxRef<Idx, Prop>& operator=(const Values<Idx>& values) {
|
||||||
|
style.*Prop = values;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
operator const Values<Idx>&() const {
|
||||||
|
return style.*Prop;
|
||||||
|
}
|
||||||
|
Ref operator[](Idx idx) {
|
||||||
|
return {style, idx};
|
||||||
|
}
|
||||||
|
CompactValue operator[](Idx idx) const {
|
||||||
|
return (style.*Prop)[idx];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Style() {
|
Style() {
|
||||||
alignContent() = Align::FlexStart;
|
alignContent() = Align::FlexStart;
|
||||||
alignItems() = Align::Stretch;
|
alignItems() = Align::Stretch;
|
||||||
@@ -113,6 +146,9 @@ class YG_EXPORT Style {
|
|||||||
FloatOptional aspectRatio_ = {};
|
FloatOptional aspectRatio_ = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// for library users needing a type
|
||||||
|
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
|
||||||
|
|
||||||
Direction direction() const {
|
Direction direction() const {
|
||||||
return getEnumData<Direction>(flags, directionOffset);
|
return getEnumData<Direction>(flags, directionOffset);
|
||||||
}
|
}
|
||||||
@@ -211,32 +247,32 @@ class YG_EXPORT Style {
|
|||||||
return {*this};
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue margin(YGEdge edge) const {
|
const Edges& margin() const {
|
||||||
return margin_[edge];
|
return margin_;
|
||||||
}
|
}
|
||||||
void setMargin(YGEdge edge, CompactValue value) {
|
IdxRef<YGEdge, &Style::margin_> margin() {
|
||||||
margin_[edge] = value;
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue position(YGEdge edge) const {
|
const Edges& position() const {
|
||||||
return position_[edge];
|
return position_;
|
||||||
}
|
}
|
||||||
void setPosition(YGEdge edge, CompactValue value) {
|
IdxRef<YGEdge, &Style::position_> position() {
|
||||||
position_[edge] = value;
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue padding(YGEdge edge) const {
|
const Edges& padding() const {
|
||||||
return padding_[edge];
|
return padding_;
|
||||||
}
|
}
|
||||||
void setPadding(YGEdge edge, CompactValue value) {
|
IdxRef<YGEdge, &Style::padding_> padding() {
|
||||||
padding_[edge] = value;
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue border(YGEdge edge) const {
|
const Edges& border() const {
|
||||||
return border_[edge];
|
return border_;
|
||||||
}
|
}
|
||||||
void setBorder(YGEdge edge, CompactValue value) {
|
IdxRef<YGEdge, &Style::border_> border() {
|
||||||
border_[edge] = value;
|
return {*this};
|
||||||
}
|
}
|
||||||
|
|
||||||
CompactValue gap(Gutter gutter) const {
|
CompactValue gap(Gutter gutter) const {
|
||||||
|
Reference in New Issue
Block a user