Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ Pod::Spec.new do |spec|
'-std=c++17',
'-fPIC'
]
spec.source_files = 'yoga/**/*.{h,cpp}'
spec.public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGValue}.h'

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
4 changes: 3 additions & 1 deletion java/jni/YGJNIVanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// API and use that
#include <yoga/YGNode.h>

using namespace facebook;
using namespace facebook::yoga;
using namespace facebook::yoga::vanillajni;

static inline ScopedLocalRef<jobject> YGNodeJobject(
Expand Down Expand Up @@ -194,7 +196,7 @@ static void jni_YGConfigSetLoggerJNI(
}

*context = newGlobalRef(env, logger);
config->setLogger(YGJNILogFunc);
static_cast<yoga::Config*>(config)->setLogger(YGJNILogFunc);
} else {
if (context != nullptr) {
delete context;
Expand Down
4 changes: 2 additions & 2 deletions tests/CompactValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#define YOGA_COMPACT_VALUE_TEST

#include <yoga/CompactValue.h>
#include <yoga/style/CompactValue.h>
#include <gtest/gtest.h>
#include <cmath>

using facebook::yoga::detail::CompactValue;
using facebook::yoga::CompactValue;

const auto tooSmall = nextafterf(CompactValue::LOWER_BOUND, -INFINITY);
const auto tooLargePoints =
Expand Down
31 changes: 14 additions & 17 deletions tests/YGStyleAccessorsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#include <cstdint>
#include <type_traits>
#include <gtest/gtest.h>
#include <yoga/YGEnums.h>
#include <yoga/YGStyle.h>
#include <yoga/YGValue.h>
#include <yoga/Yoga.h>
#include <yoga/style/Style.h>

#define ACCESSOR_TESTS_1(NAME, X) \
style.NAME() = X; \
Expand All @@ -31,14 +30,14 @@
#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 = YGStyle{}; \
style.NAME()[IDX] = X; \
ASSERT_EQ(style.NAME()[IDX], X); \
auto asArray = decltype(std::declval<const YGStyle&>().NAME()){X}; \
style.NAME() = asArray; \
ASSERT_EQ(static_cast<decltype(asArray)>(style.NAME()), asArray); \
#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) \
Expand All @@ -64,22 +63,20 @@

// test macro for up to 5 values. If more are needed, extend the macros above.
#define ACCESSOR_TEST(NAME, DEFAULT_VAL, ...) \
TEST(YGStyle, style_##NAME##_access) { \
auto style = YGStyle{}; \
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(YGStyle, style_##NAME##_access) { \
ASSERT_EQ(YGStyle{}.NAME()[IDX], DEFAULT_VAL); \
TEST(Style, style_##NAME##_access) { \
ASSERT_EQ(Style{}.NAME()[IDX], DEFAULT_VAL); \
INDEX_ACCESSOR_TESTS(__VA_ARGS__)(NAME, IDX, __VA_ARGS__) \
}

namespace facebook::yoga {

using CompactValue = detail::CompactValue;

// TODO: MSVC doesn't like the macros
#ifndef _MSC_VER

Expand Down
8 changes: 5 additions & 3 deletions tests/generated/YGConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@

#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/YGConfig.h>
#include <yoga/config/Config.h>
#include <yoga/YGNode.h>

#include <functional>
#include <memory>

using namespace facebook;

struct ConfigCloningTest : public ::testing::Test {
std::unique_ptr<YGConfig, std::function<void(YGConfig*)>> config;
std::unique_ptr<yoga::Config, std::function<void(yoga::Config*)>> config;
void SetUp() override;
void TearDown() override;

Expand Down Expand Up @@ -56,7 +58,7 @@ TEST_F(ConfigCloningTest, can_clone_with_context) {
}

void ConfigCloningTest::SetUp() {
config = {YGConfigNew(), YGConfigFree};
config = {static_cast<yoga::Config*>(YGConfigNew()), YGConfigFree};
}

void ConfigCloningTest::TearDown() {
Expand Down
12 changes: 6 additions & 6 deletions yoga/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#pragma once

#include "YGNode.h"
#include "Yoga-internal.h"
#include "CompactValue.h"
#include <yoga/Yoga-internal.h>
#include <yoga/style/CompactValue.h>

// 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.
Expand Down Expand Up @@ -56,8 +56,8 @@ struct YGCollectFlexItemsRowValues {

bool YGValueEqual(const YGValue& a, const YGValue& b);
inline bool YGValueEqual(
facebook::yoga::detail::CompactValue a,
facebook::yoga::detail::CompactValue b) {
facebook::yoga::CompactValue a,
facebook::yoga::CompactValue b) {
return YGValueEqual((YGValue) a, (YGValue) b);
}

Expand Down Expand Up @@ -115,7 +115,7 @@ inline YGFloatOptional YGResolveValue(
}

inline YGFloatOptional YGResolveValue(
facebook::yoga::detail::CompactValue value,
facebook::yoga::CompactValue value,
float ownerSize) {
return YGResolveValue((YGValue) value, ownerSize);
}
Expand All @@ -140,7 +140,7 @@ inline YGFlexDirection YGResolveFlexDirection(
}

inline YGFloatOptional YGResolveValueMargin(
facebook::yoga::detail::CompactValue value,
facebook::yoga::CompactValue value,
const float ownerSize) {
return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize);
}
2 changes: 1 addition & 1 deletion yoga/YGFloatOptional.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <cmath>
#include <limits>
#include "Yoga-internal.h"
#include <yoga/Yoga-internal.h>

struct YGFloatOptional {
private:
Expand Down
6 changes: 3 additions & 3 deletions yoga/YGLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include "BitUtils.h"
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
#include <yoga/BitUtils.h>
#include <yoga/YGFloatOptional.h>
#include <yoga/Yoga-internal.h>

struct YGLayout {
std::array<float, 4> position = {};
Expand Down
17 changes: 9 additions & 8 deletions yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include "Utils.h"

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(yoga::Config* config) : config_{config} {
YGAssert(
config != nullptr, "Attempting to construct YGNode with null config");

Expand Down Expand Up @@ -53,7 +54,7 @@ void YGNode::print(void* printContext) {
}

CompactValue YGNode::computeEdgeValueForRow(
const YGStyle::Edges& edges,
const Style::Edges& edges,
YGEdge rowEdge,
YGEdge edge,
CompactValue defaultValue) {
Expand All @@ -71,7 +72,7 @@ CompactValue YGNode::computeEdgeValueForRow(
}

CompactValue YGNode::computeEdgeValueForColumn(
const YGStyle::Edges& edges,
const Style::Edges& edges,
YGEdge edge,
CompactValue defaultValue) {
if (!edges[edge].isUndefined()) {
Expand All @@ -86,7 +87,7 @@ CompactValue YGNode::computeEdgeValueForColumn(
}

CompactValue YGNode::computeRowGap(
const YGStyle::Gutters& gutters,
const Style::Gutters& gutters,
CompactValue defaultValue) {
if (!gutters[YGGutterRow].isUndefined()) {
return gutters[YGGutterRow];
Expand All @@ -98,7 +99,7 @@ CompactValue YGNode::computeRowGap(
}

CompactValue YGNode::computeColumnGap(
const YGStyle::Gutters& gutters,
const Style::Gutters& gutters,
CompactValue defaultValue) {
if (!gutters[YGGutterColumn].isUndefined()) {
return gutters[YGGutterColumn];
Expand Down Expand Up @@ -263,7 +264,7 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
children_.insert(children_.begin() + index, child);
}

void YGNode::setConfig(YGConfigRef config) {
void YGNode::setConfig(yoga::Config* config) {
YGAssert(config != nullptr, "Attempting to set a null config on a YGNode");
YGAssertWithConfig(
config,
Expand Down Expand Up @@ -431,7 +432,7 @@ YGValue YGNode::resolveFlexBasisPtr() const {

void YGNode::resolveDimension() {
using namespace yoga;
const YGStyle& style = getStyle();
const Style& style = getStyle();
for (auto dim : {YGDimensionWidth, YGDimensionHeight}) {
if (!style.maxDimensions()[dim].isUndefined() &&
YGValueEqual(style.maxDimensions()[dim], style.minDimensions()[dim])) {
Expand Down
40 changes: 21 additions & 19 deletions yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@

#include <cstdint>
#include <stdio.h>
#include "CompactValue.h"
#include "YGConfig.h"
#include <yoga/config/Config.h>
#include "YGLayout.h"
#include "YGStyle.h"
#include "Yoga-internal.h"
#include <yoga/Yoga-internal.h>

YGConfigRef YGConfigGetDefault();
#include <yoga/style/CompactValue.h>
#include <yoga/style/Style.h>

#pragma pack(push)
#pragma pack(1)
Expand Down Expand Up @@ -52,12 +51,12 @@ struct YOGA_EXPORT YGNode {
PrintWithContextFn withContext;
} print_ = {nullptr};
YGDirtiedFunc dirtied_ = nullptr;
YGStyle style_ = {};
facebook::yoga::Style style_ = {};
YGLayout layout_ = {};
uint32_t lineIndex_ = 0;
YGNodeRef owner_ = nullptr;
YGVector children_ = {};
YGConfigRef config_;
facebook::yoga::Config* config_;
std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}};

Expand All @@ -80,11 +79,14 @@ struct YOGA_EXPORT YGNode {
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
YGNode& operator=(YGNode&&) = default;

using CompactValue = facebook::yoga::detail::CompactValue;
using CompactValue = facebook::yoga::CompactValue;

public:
YGNode() : YGNode{YGConfigGetDefault()} { flags_.hasNewLayout = true; }
explicit YGNode(const YGConfigRef config);
YGNode()
: YGNode{static_cast<facebook::yoga::Config*>(YGConfigGetDefault())} {
flags_.hasNewLayout = true;
}
explicit YGNode(facebook::yoga::Config* config);
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree

YGNode(YGNode&&);
Expand Down Expand Up @@ -123,9 +125,9 @@ struct YOGA_EXPORT YGNode {
YGDirtiedFunc getDirtied() const { return dirtied_; }

// 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.
YGLayout& getLayout() { return layout_; }
Expand Down Expand Up @@ -165,7 +167,7 @@ struct YOGA_EXPORT YGNode {

YGNodeRef getChild(uint32_t index) const { return children_.at(index); }

YGConfigRef getConfig() const { return config_; }
facebook::yoga::Config* getConfig() const { return config_; }

bool isDirty() const { return flags_.isDirty; }

Expand All @@ -178,22 +180,22 @@ struct YOGA_EXPORT YGNode {
}

static CompactValue computeEdgeValueForColumn(
const YGStyle::Edges& edges,
const facebook::yoga::Style::Edges& edges,
YGEdge edge,
CompactValue defaultValue);

static CompactValue computeEdgeValueForRow(
const YGStyle::Edges& edges,
const facebook::yoga::Style::Edges& edges,
YGEdge rowEdge,
YGEdge edge,
CompactValue defaultValue);

static CompactValue computeRowGap(
const YGStyle::Gutters& gutters,
const facebook::yoga::Style::Gutters& gutters,
CompactValue defaultValue);

static CompactValue computeColumnGap(
const YGStyle::Gutters& gutters,
const facebook::yoga::Style::Gutters& gutters,
CompactValue defaultValue);

// Methods related to positions, margin, padding and border
Expand Down Expand Up @@ -273,7 +275,7 @@ struct YOGA_EXPORT YGNode {

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; }

Expand All @@ -289,7 +291,7 @@ struct YOGA_EXPORT YGNode {

// TODO: rvalue override for setChildren

void setConfig(YGConfigRef config);
void setConfig(facebook::yoga::Config* config);

void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction);
Expand Down
Loading