Merge branch 'master' into yoga_thread_safety_master

This commit is contained in:
Hieu Rocker
2018-07-24 09:44:50 +07:00
committed by GitHub
54 changed files with 3091 additions and 1526 deletions

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Yoga'
spec.version = '1.8.1'
spec.version = '1.9.0'
spec.license = { :type => 'MIT', :file => "LICENSE" }
spec.homepage = 'https://yogalayout.com/'
spec.documentation_url = 'https://yogalayout.com/docs'
@@ -11,11 +11,14 @@ Pod::Spec.new do |spec|
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => '1.8.0',
:tag => spec.version.to_s,
}
spec.platforms = { :ios => "8.0", :tvos => "10.0" }
spec.module_name = 'yoga'
spec.requires_arc = false
spec.pod_target_xcconfig = {
'DEFINES_MODULE' => 'YES'
}
spec.compiler_flags = [
'-fno-omit-frame-pointer',
'-fexceptions',

View File

@@ -1,6 +1,6 @@
podspec = Pod::Spec.new do |spec|
spec.name = 'YogaKit'
spec.version = '1.8.1'
spec.version = '1.9.0'
spec.license = { :type => 'MIT', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/yogakit/'
@@ -11,14 +11,14 @@ podspec = Pod::Spec.new do |spec|
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => '1.7.0',
:tag => spec.version.to_s,
}
spec.platform = :ios
spec.ios.deployment_target = '8.0'
spec.ios.frameworks = 'UIKit'
spec.dependency 'Yoga', '~> 1.8.1'
spec.dependency 'Yoga', '~> 1.9'
spec.source_files = 'YogaKit/Source/*.{h,m,swift}'
spec.public_header_files = 'YogaKit/Source/{YGLayout,UIView+Yoga}.h'
spec.private_header_files = 'YogaKit/Source/YGLayout+Private.h'

View File

@@ -5,10 +5,72 @@
* LICENSE file in the root directory of this source tree.
*/
#include "YGBenchmark.h"
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <yoga/Yoga.h>
#define NUM_REPETITIONS 1000
#define YGBENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __endTimes[NUM_REPETITIONS]; \
{ BLOCK } \
return 0; \
}
#define YGBENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
{ BLOCK } \
__endTimes[__i] = clock(); \
} \
__printBenchmarkResult(NAME, __start, __endTimes);
static int __compareDoubles(const void *a, const void *b) {
double arg1 = *(const double *) a;
double arg2 = *(const double *) b;
if (arg1 < arg2) {
return -1;
}
if (arg1 > arg2) {
return 1;
}
return 0;
}
static void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) {
double timesInMs[NUM_REPETITIONS];
double mean = 0;
clock_t lastEnd = start;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000;
lastEnd = endTimes[i];
mean += timesInMs[i];
}
mean /= NUM_REPETITIONS;
qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles);
double median = timesInMs[NUM_REPETITIONS / 2];
double variance = 0;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
variance += pow(timesInMs[i] - mean, 2);
}
variance /= NUM_REPETITIONS;
double stddev = sqrt(variance);
printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev);
}
static YGSize _measure(YGNodeRef node,
float width,
YGMeasureMode widthMode,
@@ -97,7 +159,7 @@ YGBENCHMARKS({
YGNodeStyleSetHeight(grandGrandChild, 10);
YGNodeInsertChild(grandChild, grandGrandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
for (uint32_t iiii = 0; iiii < 10; iiii++) {
const YGNodeRef grandGrandGrandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);

View File

@@ -1,71 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_REPETITIONS 1000
#define YGBENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __endTimes[NUM_REPETITIONS]; \
{ BLOCK } \
return 0; \
}
#define YGBENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
{ BLOCK } \
__endTimes[__i] = clock(); \
} \
__printBenchmarkResult(NAME, __start, __endTimes);
int __compareDoubles(const void *a, const void *b) {
double arg1 = *(const double *) a;
double arg2 = *(const double *) b;
if (arg1 < arg2) {
return -1;
}
if (arg1 > arg2) {
return 1;
}
return 0;
}
void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) {
double timesInMs[NUM_REPETITIONS];
double mean = 0;
clock_t lastEnd = start;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000;
lastEnd = endTimes[i];
mean += timesInMs[i];
}
mean /= NUM_REPETITIONS;
qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles);
double median = timesInMs[NUM_REPETITIONS / 2];
double variance = 0;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
variance += pow(timesInMs[i] - mean, 2);
}
variance /= NUM_REPETITIONS;
double stddev = sqrt(variance);
printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev);
}

View File

@@ -3,7 +3,14 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "BASE_COMPILER_FLAGS", "is_apple_platform", "yoga_cxx_library", "yoga_dep")
load(
"//:yoga_defs.bzl",
"BASE_COMPILER_FLAGS",
"is_apple_platform",
"yoga_cxx_library",
"yoga_dep",
"yoga_apple_binary",
)
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
@@ -32,41 +39,4 @@ yoga_cxx_library(
deps = [yoga_dep(":yoga")],
)
if is_apple_platform():
yoganet_ios_srcs = []
for arch in [
"iphonesimulator-x86_64",
"iphoneos-arm64",
]:
name = "yoganet-" + arch
yoganet_ios_srcs.append(":" + name)
genrule(
name = name,
srcs = [
yoga_dep(":yogaApple#%s,static" % arch),
yoga_dep("YogaKit:YogaKitApple#%s,static" % arch),
yoga_dep("csharp:yoganetApple#%s,static" % arch),
],
out = "libyoga-%s.a" % arch,
cmd = "libtool -static -o $OUT $SRCS",
visibility = [yoga_dep("csharp:yoganet-ios")],
)
genrule(
name = "yoganet-ios",
srcs = yoganet_ios_srcs,
out = "libyoga.a",
cmd = "lipo $SRCS -create -output $OUT",
visibility = ["PUBLIC"],
)
yoganet_macosx_target = "csharp:yoganetAppleMac#macosx-%s,dynamic"
genrule(
name = "yoganet-macosx",
srcs = [
yoga_dep(yoganet_macosx_target % "x86_64"),
],
out = "libyoga.dylib",
cmd = "lipo $SRCS -create -output $OUT",
visibility = ["PUBLIC"],
)
yoga_apple_binary()

View File

@@ -2,7 +2,7 @@
org.gradle.jvmargs=-Xmx1536M
VERSION_NAME=1.8.1-SNAPSHOT
VERSION_NAME=1.9.1-SNAPSHOT
POM_URL=https://github.com/facebook/yoga
POM_SCM_URL=https://github.com/facebook/yoga.git
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git

View File

@@ -52,7 +52,7 @@ android {
dependencies {
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
compileOnly project(':yoga:proguard-annotations')
implementation 'com.facebook.soloader:soloader:0.2.0'
implementation 'com.facebook.soloader:soloader:0.5.1'
testImplementation 'junit:junit:4.12'
}

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
public class YogaConstants {

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
/**

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
public interface YogaNodeProperties {
YogaNodeProperties clone(YogaNode node);
long getNativePointer();
void onAfterCalculateLayout();
void reset();
boolean hasNewLayout();
boolean isDirty();
void markLayoutSeen();
YogaDirection getStyleDirection();
void setDirection(YogaDirection direction);
YogaFlexDirection getFlexDirection();
void setFlexDirection(YogaFlexDirection flexDirection);
YogaJustify getJustifyContent();
void setJustifyContent(YogaJustify justifyContent);
YogaAlign getAlignItems();
void setAlignItems(YogaAlign alignItems);
YogaAlign getAlignSelf();
void setAlignSelf(YogaAlign alignSelf);
YogaAlign getAlignContent();
void setAlignContent(YogaAlign alignContent);
YogaPositionType getPositionType();
void setPositionType(YogaPositionType positionType);
void setWrap(YogaWrap flexWrap);
YogaOverflow getOverflow();
void setOverflow(YogaOverflow overflow);
YogaDisplay getDisplay();
void setDisplay(YogaDisplay display);
void setFlex(float flex);
float getFlexGrow();
void setFlexGrow(float flexGrow);
float getFlexShrink();
void setFlexShrink(float flexShrink);
YogaValue getFlexBasis();
void setFlexBasis(float flexBasis);
void setFlexBasisPercent(float percent);
void setFlexBasisAuto();
YogaValue getMargin(YogaEdge edge);
void setMargin(YogaEdge edge, float margin);
void setMarginPercent(YogaEdge edge, float percent);
void setMarginAuto(YogaEdge edge);
YogaValue getPadding(YogaEdge edge);
void setPadding(YogaEdge edge, float padding);
void setPaddingPercent(YogaEdge edge, float percent);
float getBorder(YogaEdge edge);
void setBorder(YogaEdge edge, float border);
YogaValue getPosition(YogaEdge edge);
void setPosition(YogaEdge edge, float position);
void setPositionPercent(YogaEdge edge, float percent);
YogaValue getWidth();
void setWidth(float width);
void setWidthPercent(float percent);
void setWidthAuto();
YogaValue getHeight();
void setHeight(float height);
void setHeightPercent(float percent);
void setHeightAuto();
YogaValue getMinWidth();
void setMinWidth(float minWidth);
void setMinWidthPercent(float percent);
YogaValue getMinHeight();
void setMinHeight(float minHeight);
void setMinHeightPercent(float percent);
YogaValue getMaxWidth();
void setMaxWidth(float maxWidth);
void setMaxWidthPercent(float percent);
YogaValue getMaxHeight();
void setMaxHeight(float maxheight);
void setMaxHeightPercent(float percent);
float getAspectRatio();
void setAspectRatio(float aspectRatio);
float getLayoutX();
float getLayoutY();
float getLayoutWidth();
float getLayoutHeight();
boolean getDoesLegacyStretchFlagAffectsLayout();
float getLayoutMargin(YogaEdge edge);
float getLayoutPadding(YogaEdge edge);
float getLayoutBorder(YogaEdge edge);
YogaDirection getLayoutDirection();
}

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -1,10 +1,10 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;

View File

@@ -37,38 +37,63 @@ static inline weak_ref<JYogaNode> *YGNodeJobject(YGNodeRef node) {
return reinterpret_cast<weak_ref<JYogaNode>*>(node->getContext());
}
static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNode) {
static auto layoutDirectionField = javaNode->getClass()->getField<jint>("mLayoutDirection");
javaNode->setFieldValue(layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
static void YGTransferLayoutDirection(
YGNodeRef node,
alias_ref<jobject> javaNode) {
static auto layoutDirectionField =
javaNode->getClass()->getField<jint>("mLayoutDirection");
javaNode->setFieldValue(
layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
}
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if (root->getHasNewLayout()) {
if (auto obj = YGNodeJobject(root)->lockLocal()) {
if (!root->getHasNewLayout()) {
return;
}
auto obj = YGNodeJobject(root)->lockLocal();
if (!obj) {
YGLog(
root,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
return;
}
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
static auto topField = obj->getClass()->getField<jfloat>("mTop");
static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginLeftField =
obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");
static auto marginRightField =
obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField =
obj->getClass()->getField<jfloat>("mMarginBottom");
static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto paddingLeftField =
obj->getClass()->getField<jfloat>("mPaddingLeft");
static auto paddingTopField =
obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingRightField =
obj->getClass()->getField<jfloat>("mPaddingRight");
static auto paddingBottomField =
obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderLeftField =
obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
static auto borderRightField =
obj->getClass()->getField<jfloat>("mBorderRight");
static auto borderBottomField =
obj->getClass()->getField<jfloat>("mBorderBottom");
static auto edgeSetFlagField = obj->getClass()->getField<jint>("mEdgeSetFlag");
static auto hasNewLayoutField = obj->getClass()->getField<jboolean>("mHasNewLayout");
static auto doesLegacyStretchBehaviour =
obj->getClass()->getField<jboolean>(
static auto edgeSetFlagField =
obj->getClass()->getField<jint>("mEdgeSetFlag");
static auto hasNewLayoutField =
obj->getClass()->getField<jboolean>("mHasNewLayout");
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
"mDoesLegacyStretchFlagAffectsLayout");
/* Those flags needs be in sync with YogaNode.java */
@@ -89,8 +114,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
obj->setFieldValue(
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue(
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue(
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue(
@@ -98,17 +122,24 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
}
if ((hasEdgeSetFlag & PADDING) == PADDING) {
obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
obj->setFieldValue(
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
obj->setFieldValue(
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue(
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue(
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
}
if ((hasEdgeSetFlag & BORDER) == BORDER) {
obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue(
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
obj->setFieldValue(
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue(
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
}
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
@@ -118,23 +149,23 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
}
} else {
YGLog(root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
}
}
}
static void YGPrint(YGNodeRef node) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
cout << obj->toString() << endl;
} else {
YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
YGLog(
node,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
}
}
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
static auto baselineFunc =
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jfloat(jfloat, jfloat)>("baseline");
return baselineFunc(obj, width, height);
} else {
@@ -150,20 +181,17 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
}
static YGNodeRef YGJNIOnNodeClonedFunc(
YGNodeRef oldNode,
YGNodeRef owner,
int childIndex) {
static YGNodeRef
YGJNIOnNodeClonedFunc(YGNodeRef oldNode, YGNodeRef owner, int childIndex) {
auto config = oldNode->getConfig();
if (!config) {
return nullptr;
}
static auto onNodeClonedFunc = findClassStatic("com/facebook/yoga/YogaConfig")
static auto onNodeClonedFunc =
findClassStatic("com/facebook/yoga/YogaConfig")
->getMethod<alias_ref<JYogaNode>(
local_ref<JYogaNode>,
local_ref<JYogaNode>,
jint)>("cloneNode");
local_ref<JYogaNode>, local_ref<JYogaNode>, jint)>("cloneNode");
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
auto javaConfig = context->config;
@@ -174,15 +202,12 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
YGNodeJobject(owner)->lockLocal(),
childIndex);
static auto replaceChild = findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(
local_ref<JYogaNode>,
jint)>("replaceChild");
static auto replaceChild =
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(local_ref<JYogaNode>, jint)>("replaceChild");
jlong newNodeNativePointer = replaceChild(
YGNodeJobject(owner)->lockLocal(),
newNode,
childIndex);
jlong newNodeNativePointer =
replaceChild(YGNodeJobject(owner)->lockLocal(), newNode, childIndex);
return _jlong2YGNodeRef(newNodeNativePointer);
}
@@ -194,13 +219,16 @@ static YGSize YGJNIMeasureFunc(
float height,
YGMeasureMode heightMode) {
if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto measureFunc = findClassStatic("com/facebook/yoga/YogaNode")
static auto measureFunc =
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
YGTransferLayoutDirection(node, obj);
const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode);
const auto measureResult =
measureFunc(obj, width, widthMode, height, heightMode);
static_assert(sizeof(measureResult) == 8,
static_assert(
sizeof(measureResult) == 8,
"Expected measureResult to be 8 bytes, or two 32 bit ints");
int32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
@@ -211,7 +239,10 @@ static YGSize YGJNIMeasureFunc(
return YGSize{*measuredWidth, *measuredHeight};
} else {
YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
YGLog(
node,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
return YGSize{
widthMode == YGMeasureModeUndefined ? 0 : width,
heightMode == YGMeasureModeUndefined ? 0 : height,
@@ -223,7 +254,8 @@ struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
};
static int YGJNILogFunc(const YGConfigRef config,
static int YGJNILogFunc(
const YGConfigRef config,
const YGNodeRef node,
YGLogLevel level,
const char* format,
@@ -234,13 +266,16 @@ static int YGJNILogFunc(const YGConfigRef config,
static auto logFunc =
findClassStatic("com/facebook/yoga/YogaLogger")
->getMethod<void(local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
->getMethod<void(
local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
static auto logLevelFromInt =
JYogaLogLevel::javaClassStatic()->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
JYogaLogLevel::javaClassStatic()
->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
if (auto obj = YGNodeJobject(node)->lockLocal()) {
auto jlogger = reinterpret_cast<global_ref<jobject> *>(YGConfigGetContext(config));
auto jlogger =
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
logFunc(
jlogger->get(),
obj,
@@ -309,13 +344,19 @@ void jni_YGNodeReset(alias_ref<jobject> thiz, jlong nativePointer) {
void jni_YGNodePrint(alias_ref<jobject> thiz, jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodePrint(node,
(YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout |
YGPrintOptionsChildren));
YGNodePrint(
node,
(YGPrintOptions)(
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
}
void jni_YGNodeInsertChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer, jint index) {
YGNodeInsertChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
void jni_YGNodeInsertChild(
alias_ref<jobject>,
jlong nativePointer,
jlong childPointer,
jint index) {
YGNodeInsertChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
}
void jni_YGNodeInsertSharedChild(
@@ -327,16 +368,22 @@ void jni_YGNodeInsertSharedChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
}
void jni_YGNodeRemoveChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer) {
YGNodeRemoveChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
void jni_YGNodeRemoveChild(
alias_ref<jobject>,
jlong nativePointer,
jlong childPointer) {
YGNodeRemoveChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
}
void jni_YGNodeCalculateLayout(alias_ref<jobject>,
void jni_YGNodeCalculateLayout(
alias_ref<jobject>,
jlong nativePointer,
jfloat width,
jfloat height) {
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
YGNodeCalculateLayout(root,
YGNodeCalculateLayout(
root,
static_cast<float>(width),
static_cast<float>(height),
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)));
@@ -357,20 +404,28 @@ jboolean jni_YGNodeIsDirty(alias_ref<jobject>, jlong nativePointer) {
return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty();
}
void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasMeasureFunc) {
void jni_YGNodeSetHasMeasureFunc(
alias_ref<jobject>,
jlong nativePointer,
jboolean hasMeasureFunc) {
_jlong2YGNodeRef(nativePointer)
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
}
void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
void jni_YGNodeSetHasBaselineFunc(
alias_ref<jobject>,
jlong nativePointer,
jboolean hasBaselineFunc) {
_jlong2YGNodeRef(nativePointer)
->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
}
void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNativePointer) {
YGNodeCopyStyle(_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
void jni_YGNodeCopyStyle(
alias_ref<jobject>,
jlong dstNativePointer,
jlong srcNativePointer) {
YGNodeCopyStyle(
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
}
struct JYogaValue : public JavaClass<JYogaValue> {
@@ -393,66 +448,75 @@ struct JYogaValue : public JavaClass<JYogaValue> {
}
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \
return JYogaValue::create(YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
local_ref<jobject> jni_YGNodeStyleGet##name( \
alias_ref<jobject>, jlong nativePointer) { \
return JYogaValue::create( \
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
} \
\
void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
void jni_YGNodeStyleSet##name( \
alias_ref<jobject>, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
} \
\
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
void jni_YGNodeStyleSet##name##Percent( \
alias_ref<jobject>, jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
}
#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer) { \
void jni_YGNodeStyleSet##name##Auto( \
alias_ref<jobject>, jlong nativePointer) { \
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \
}
#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \
javatype jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer, jint edge) { \
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge)); \
javatype jni_YGNodeStyleGet##name( \
alias_ref<jobject>, jlong nativePointer, jint edge) { \
return (javatype)YGNodeStyleGet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
} \
\
void jni_YGNodeStyleSet##name(alias_ref<jobject>, \
jlong nativePointer, \
jint edge, \
javatype value) { \
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
void jni_YGNodeStyleSet##name( \
alias_ref<jobject>, jlong nativePointer, jint edge, javatype value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<type>(value)); \
}
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, \
jlong nativePointer, \
jint edge) { \
return JYogaValue::create( \
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
local_ref<jobject> jni_YGNodeStyleGet##name( \
alias_ref<jobject>, jlong nativePointer, jint edge) { \
return JYogaValue::create(YGNodeStyleGet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
} \
\
void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
void jni_YGNodeStyleSet##name( \
alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
} \
\
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, \
jlong nativePointer, \
jint edge, \
jfloat value) { \
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), \
void jni_YGNodeStyleSet##name##Percent( \
alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
}
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer, jint edge) { \
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
void jni_YGNodeStyleSet##name##Auto( \
alias_ref<jobject>, jlong nativePointer, jint edge) { \
YGNodeStyleSet##name##Auto( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
}
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
@@ -466,8 +530,12 @@ YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
void jni_YGNodeStyleSetFlex(alias_ref<jobject>, jlong nativePointer, jfloat value) {
YGNodeStyleSetFlex(_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
void jni_YGNodeStyleSetFlex(
alias_ref<jobject>,
jlong nativePointer,
jfloat value) {
YGNodeStyleSetFlex(
_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
}
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
@@ -501,14 +569,14 @@ void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
YGConfigFree(config);
}
void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>,
void jni_YGConfigSetExperimentalFeatureEnabled(
alias_ref<jobject>,
jlong nativePointer,
jint feature,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetExperimentalFeatureEnabled(config,
static_cast<YGExperimentalFeature>(feature),
enabled);
YGConfigSetExperimentalFeatureEnabled(
config, static_cast<YGExperimentalFeature>(feature), enabled);
}
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
@@ -519,21 +587,24 @@ void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
}
void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>,
void jni_YGConfigSetUseWebDefaults(
alias_ref<jobject>,
jlong nativePointer,
jboolean useWebDefaults) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseWebDefaults(config, useWebDefaults);
}
void jni_YGConfigSetPointScaleFactor(alias_ref<jobject>,
void jni_YGConfigSetPointScaleFactor(
alias_ref<jobject>,
jlong nativePointer,
jfloat pixelsInPoint) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPointScaleFactor(config, pixelsInPoint);
}
void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref<jobject>,
void jni_YGConfigSetUseLegacyStretchBehaviour(
alias_ref<jobject>,
jlong nativePointer,
jboolean useLegacyStretchBehaviour) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);

View File

@@ -0,0 +1,983 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
package com.facebook.yoga;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class YogaNodeStylePropertiesTest {
private static final float UNDEFINED = YogaValue.UNDEFINED.value;
@Test
public void testDirectionDefault() {
final YogaNode node = new YogaNode();
assertEquals(node.getStyleDirection(), YogaDirection.INHERIT);
assertEquals(node.getLayoutDirection(), YogaDirection.INHERIT);
}
@Test
public void testDirectionAssignment() {
final YogaNode node = new YogaNode();
node.setDirection(YogaDirection.LTR);
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(YogaDirection.LTR, node.getStyleDirection());
assertEquals(YogaDirection.LTR, node.getLayoutDirection());
}
@Test
public void testDirectionAffectsLayout() {
final YogaNode node =
style().direction(YogaDirection.RTL).width(200).children(style().widthPercent(40)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(120, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testFlexDirectionDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaFlexDirection.COLUMN, node.getFlexDirection());
}
@Test
public void testFlexDirectionAssignment() {
final YogaNode node = style().flexDirection(YogaFlexDirection.COLUMN_REVERSE).node();
assertEquals(YogaFlexDirection.COLUMN_REVERSE, node.getFlexDirection());
}
@Test
public void testFlexDirectionAffectsLayout() {
final YogaNode node =
style()
.flexDirection(YogaFlexDirection.ROW_REVERSE)
.width(200)
.children(style().widthPercent(40))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(120, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testJustifyContentDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaJustify.FLEX_START, node.getJustifyContent());
}
@Test
public void testJustifyContentAssignment() {
final YogaNode node = new YogaNode();
node.setJustifyContent(YogaJustify.SPACE_EVENLY);
assertEquals(YogaJustify.SPACE_EVENLY, node.getJustifyContent());
}
@Test
public void testJustifyContentAffectsLayout() {
final YogaNode node =
style()
.justifyContent(YogaJustify.CENTER)
.height(200)
.children(style().heightPercent(40))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(60, node.getChildAt(0).getLayoutY(), 0);
}
@Test
public void testAlignItemsDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaAlign.STRETCH, node.getAlignItems());
}
@Test
public void testAlignItemsAssignment() {
final YogaNode node = new YogaNode();
node.setAlignItems(YogaAlign.SPACE_AROUND);
assertEquals(YogaAlign.SPACE_AROUND, node.getAlignItems());
}
@Test
public void testAlignItemsAffectsLayout() {
final YogaNode node =
style().alignItems(YogaAlign.CENTER).height(200).children(style().widthPercent(40)).node();
node.calculateLayout(200, UNDEFINED);
assertEquals(60, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testAlignSelfDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaAlign.AUTO, node.getAlignSelf());
}
@Test
public void testAlignSelfAssignment() {
final YogaNode node = new YogaNode();
node.setAlignSelf(YogaAlign.FLEX_END);
assertEquals(YogaAlign.FLEX_END, node.getAlignSelf());
}
@Test
public void testAlignSelfAffectsLayout() {
final YogaNode node =
style().height(200).children(style().alignSelf(YogaAlign.CENTER).widthPercent(40)).node();
node.calculateLayout(200, UNDEFINED);
assertEquals(60, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testAlignContentDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaAlign.FLEX_START, node.getAlignContent());
}
@Test
public void testAlignContentAssignment() {
final YogaNode node = new YogaNode();
node.setAlignContent(YogaAlign.BASELINE);
assertEquals(YogaAlign.BASELINE, node.getAlignContent());
}
@Test
public void testAlignContentAffectsLayout() {
final YogaNode node =
style()
.alignContent(YogaAlign.SPACE_AROUND)
.flexWrap(YogaWrap.WRAP)
.height(200)
.width(200)
.children(
style().widthPercent(20).heightPercent(60),
style().widthPercent(20).heightPercent(60))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(30, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testPositionTypeDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaPositionType.RELATIVE, node.getPositionType());
}
@Test
public void testPositionTypeAssignment() {
final YogaNode node = new YogaNode();
node.setPositionType(YogaPositionType.ABSOLUTE);
assertEquals(YogaPositionType.ABSOLUTE, node.getPositionType());
}
@Test
public void testPositionTypeAffectsLayout() {
final YogaNode node =
style()
.height(200)
.children(
style().height(100), style().height(100).positionType(YogaPositionType.ABSOLUTE))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(0, node.getChildAt(1).getLayoutY(), 0);
}
@Test
public void testWrapAffectsLayout() {
final YogaNode node =
style()
.width(200)
.height(200)
.flexWrap(YogaWrap.WRAP_REVERSE)
.children(style().width(10).heightPercent(60), style().heightPercent(60))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(190, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testOverflowDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaOverflow.VISIBLE, node.getOverflow());
}
@Test
public void testOverflowAssignment() {
final YogaNode node = new YogaNode();
node.setOverflow(YogaOverflow.SCROLL);
assertEquals(YogaOverflow.SCROLL, node.getOverflow());
}
// TODO add testOverflowAffectsLayout()
@Test
public void testDisplayDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaDisplay.FLEX, node.getDisplay());
}
@Test
public void testDisplayAssignment() {
final YogaNode node = new YogaNode();
node.setDisplay(YogaDisplay.NONE);
assertEquals(YogaDisplay.NONE, node.getDisplay());
}
@Test
public void testDisplayAffectsLayout() {
final YogaNode node =
style().children(style().flexGrow(1).display(YogaDisplay.NONE), style().flexGrow(1)).node();
node.calculateLayout(200, 200);
assertEquals(200, node.getChildAt(1).getLayoutHeight(), 0);
}
@Test
public void testFlexAffectsLayoutGrowing() {
final YogaNode node = style().height(200).children(style().height(100).flex(1.25f)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testFlexAffectsLayoutShrinking() {
final YogaNode node = style().height(200).children(style().height(300).flex(1.25f)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testFlexGrowDefault() {
final YogaNode node = new YogaNode();
assertEquals(0, node.getFlexGrow(), 0);
}
@Test
public void testFlexGrowAssignment() {
final YogaNode node = new YogaNode();
node.setFlexGrow(2.5f);
assertEquals(2.5f, node.getFlexGrow(), 0);
}
@Test
public void testFlexGrowAffectsLayout() {
final YogaNode node =
style().height(200).children(style().height(50).flexGrow(1), style().height(50)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(150, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testFlexShrinkDefault() {
final YogaNode node = new YogaNode();
assertEquals(0, node.getFlexShrink(), 0);
}
@Test
public void testFlexShrinkAssignment() {
final YogaNode node = new YogaNode();
node.setFlexShrink(2.5f);
assertEquals(2.5f, node.getFlexShrink(), 0);
}
@Test
public void testFlexShrinkAffectsLayout() {
final YogaNode node =
style().height(200).children(style().height(150).flexShrink(1), style().height(150)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(50, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testFlexBasisDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.AUTO, node.getFlexBasis());
}
@Test
public void testFlexBasisAssignment() {
final YogaNode node = new YogaNode();
node.setFlexBasis(50);
assertEquals(new YogaValue(50, YogaUnit.POINT), node.getFlexBasis());
node.setFlexBasisPercent(20);
assertEquals(new YogaValue(20, YogaUnit.PERCENT), node.getFlexBasis());
node.setFlexBasisAuto();
assertEquals(YogaValue.AUTO, node.getFlexBasis());
}
@Test
public void testFlexBasisAffectsLayout() {
final YogaNode node =
style()
.height(200)
.children(style().flexBasis(150).flexShrink(1), style().flexBasis(150).flexShrink(1))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(100, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testFlexBasisPercentAffectsLayout() {
final YogaNode node =
style()
.height(200)
.children(style().flexBasisPercent(60), style().flexBasisPercent(40))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(80, node.getChildAt(1).getLayoutHeight(), 0);
}
@Test
public void testMarginDefault() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
assertEquals(YogaValue.UNDEFINED, node.getMargin(edge));
}
}
@Test
public void testMarginAssignment() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
node.setMargin(edge, 25);
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getMargin(edge));
node.setMarginPercent(edge, 5);
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getMargin(edge));
node.setMarginAuto(edge);
assertEquals(YogaValue.AUTO, node.getMargin(edge));
}
}
@Test
public void testMarginPointAffectsLayout() {
final YogaNode node = style().margin(YogaEdge.TOP, 42).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(42, node.getLayoutY(), 0);
}
@Test
public void testMarginPercentAffectsLayout() {
final YogaNode node =
style().height(200).children(style().flexGrow(1).marginPercent(YogaEdge.TOP, 20)).node();
node.calculateLayout(200, 200);
assertEquals(40, node.getChildAt(0).getLayoutY(), 0);
}
@Test
public void testMarginAutoAffectsLayout() {
final YogaNode node =
style()
.width(200)
.flexDirection(YogaFlexDirection.ROW)
.children(style().marginAuto(YogaEdge.LEFT).marginAuto(YogaEdge.RIGHT).width(100))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(50, node.getChildAt(0).getLayoutX(), 0);
}
@Test
public void testPaddingDefault() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
assertEquals(YogaValue.UNDEFINED, node.getPadding(edge));
}
}
@Test
public void testPaddingAssignment() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
node.setPadding(edge, 25);
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPadding(edge));
node.setPaddingPercent(edge, 5);
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getPadding(edge));
}
}
@Test
public void testPaddingPointAffectsLayout() {
final YogaNode node = style().padding(YogaEdge.TOP, 42).children(style()).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(42, node.getChildAt(0).getLayoutY(), 0);
}
@Test
public void testPaddingPercentAffectsLayout() {
final YogaNode node =
style().height(200).paddingPercent(YogaEdge.TOP, 20).children(style().flexGrow(1)).node();
node.calculateLayout(200, 200);
assertEquals(40, node.getChildAt(0).getLayoutY(), 0);
}
@Test
public void testBorderDefault() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
assertEquals(UNDEFINED, node.getBorder(edge), 0);
}
}
@Test
public void testBorderAssignment() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
node.setBorder(edge, 2.5f);
assertEquals(2.5f, node.getBorder(edge), 0);
}
}
@Test
public void testBorderAffectsLayout() {
final YogaNode node = style().border(YogaEdge.TOP, 42).children(style()).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(42, node.getChildAt(0).getLayoutY(), 0);
}
@Test
public void testPositionDefault() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
assertEquals(YogaValue.UNDEFINED, node.getPosition(edge));
}
}
@Test
public void testPositionAssignment() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
node.setPosition(edge, 25);
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPosition(edge));
node.setPositionPercent(edge, 5);
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getPosition(edge));
}
}
@Test
public void testPositionAffectsLayout() {
final YogaNode node =
style()
.height(100)
.children(
style()
.positionType(YogaPositionType.ABSOLUTE)
.position(YogaEdge.TOP, 11)
.position(YogaEdge.BOTTOM, 22))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(67, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testPositionPercentAffectsLayout() {
final YogaNode node =
style()
.width(100)
.children(
style()
.positionType(YogaPositionType.ABSOLUTE)
.positionPercent(YogaEdge.LEFT, 11)
.positionPercent(YogaEdge.RIGHT, 22))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(67, node.getChildAt(0).getLayoutWidth(), 0);
}
@Test
public void testWidthDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.AUTO, node.getWidth());
}
@Test
public void testWidthAssignment() {
final YogaNode node = new YogaNode();
node.setWidth(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getWidth());
node.setWidthPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getWidth());
}
@Test
public void testWidthAffectsLayout() {
final YogaNode node = style().width(123).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getLayoutWidth(), 0);
}
@Test
public void testWidthPercentAffectsLayout() {
final YogaNode node = style().widthPercent(75).node();
node.calculateLayout(200, UNDEFINED);
assertEquals(150, node.getLayoutWidth(), 0);
}
// TODO: testWidthAutoAffectsLayout
@Test
public void testHeightDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.AUTO, node.getHeight());
}
@Test
public void testHeightAssignment() {
final YogaNode node = new YogaNode();
node.setHeight(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getHeight());
node.setHeightPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getHeight());
}
@Test
public void testHeightAffectsLayout() {
final YogaNode node = style().height(123).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getLayoutHeight(), 0);
}
@Test
public void testHeightPercentAffectsLayout() {
final YogaNode node = style().heightPercent(75).node();
node.calculateLayout(UNDEFINED, 200);
assertEquals(150, node.getLayoutHeight(), 0);
}
// TODO: testHeightAutoAffectsLayout
@Test
public void testMinWidthDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.UNDEFINED, node.getMinWidth());
}
@Test
public void testMinWidthAssignment() {
final YogaNode node = new YogaNode();
node.setMinWidth(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinWidth());
node.setMinWidthPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMinWidth());
}
@Test
public void testMinWidthAffectsLayout() {
final YogaNode node = style().minWidth(123).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getLayoutWidth(), 0);
}
@Test
public void testMinWidthPercentAffectsLayout() {
final YogaNode node = style().minWidthPercent(120).node();
node.calculateLayout(200, UNDEFINED);
assertEquals(240, node.getLayoutWidth(), 0);
}
@Test
public void testMinHeightDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.UNDEFINED, node.getMinHeight());
}
@Test
public void testMinHeightAssignment() {
final YogaNode node = new YogaNode();
node.setMinHeight(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinHeight());
node.setMinHeightPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMinHeight());
}
@Test
public void testMinHeightAffectsLayout() {
final YogaNode node = style().minHeight(123).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getLayoutHeight(), 0);
}
@Test
public void testMinHeightPercentAffectsLayout() {
final YogaNode node = style().minHeightPercent(120).node();
node.calculateLayout(UNDEFINED, 200);
assertEquals(240, node.getLayoutHeight(), 0);
}
@Test
public void testMaxWidthDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.UNDEFINED, node.getMaxWidth());
}
@Test
public void testMaxWidthAssignment() {
final YogaNode node = new YogaNode();
node.setMaxWidth(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxWidth());
node.setMaxWidthPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMaxWidth());
}
@Test
public void testMaxWidthAffectsLayout() {
final YogaNode node = style().width(200).children(style().maxWidth(123)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getChildAt(0).getLayoutWidth(), 0);
}
@Test
public void testMaxWidthPercentAffectsLayout() {
final YogaNode node = style().width(200).children(style().maxWidthPercent(80)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(160, node.getChildAt(0).getLayoutWidth(), 0);
}
@Test
public void testMaxHeightDefault() {
final YogaNode node = new YogaNode();
assertEquals(YogaValue.UNDEFINED, node.getMaxHeight());
}
@Test
public void testMaxHeightAssignment() {
final YogaNode node = new YogaNode();
node.setMaxHeight(123);
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxHeight());
node.setMaxHeightPercent(45);
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMaxHeight());
}
@Test
public void testMaxHeightAffectsLayout() {
final YogaNode node =
style()
.height(200)
.flexDirection(YogaFlexDirection.ROW)
.children(style().maxHeight(123))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(123, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testMaxHeightPercentAffectsLayout() {
final YogaNode node =
style()
.flexDirection(YogaFlexDirection.ROW)
.height(200)
.children(style().maxHeightPercent(80))
.node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(160, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void testAspectRatioDefault() {
final YogaNode node = new YogaNode();
assertEquals(UNDEFINED, node.getAspectRatio(), 0);
}
@Test
public void testAspectRatioAssignment() {
final YogaNode node = new YogaNode();
node.setAspectRatio(2.75f);
assertEquals(2.75f, node.getAspectRatio(), 0);
}
@Test
public void aspectRatioAffectsLayoutWithGivenWidth() {
final YogaNode node = style().children(style().width(300).aspectRatio(1.5f)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
}
@Test
public void aspectRatioAffectsLayoutWithGivenHeight() {
final YogaNode node = style().children(style().height(300).aspectRatio(1.5f)).node();
node.calculateLayout(UNDEFINED, UNDEFINED);
assertEquals(450, node.getChildAt(0).getLayoutWidth(), 0);
}
private static StyledNode style() {
return new StyledNode();
}
private static class StyledNode {
private YogaNode mNode = new YogaNode();
YogaNode node() {
return mNode;
}
StyledNode children(StyledNode... children) {
for (int i = mNode.getChildCount(); --i >= 0; ) {
mNode.removeChildAt(i);
}
for (int i = 0; i < children.length; i++) {
mNode.addChildAt(children[i].node(), i);
}
return this;
}
StyledNode direction(YogaDirection direction) {
mNode.setDirection(direction);
return this;
}
StyledNode width(float width) {
mNode.setWidth(width);
return this;
}
StyledNode widthPercent(float width) {
mNode.setWidthPercent(width);
return this;
}
StyledNode flexDirection(YogaFlexDirection direction) {
mNode.setFlexDirection(direction);
return this;
}
StyledNode justifyContent(YogaJustify justify) {
mNode.setJustifyContent(justify);
return this;
}
StyledNode height(float height) {
mNode.setHeight(height);
return this;
}
StyledNode heightPercent(float height) {
mNode.setHeightPercent(height);
return this;
}
StyledNode alignItems(YogaAlign align) {
mNode.setAlignItems(align);
return this;
}
StyledNode alignSelf(YogaAlign align) {
mNode.setAlignSelf(align);
return this;
}
StyledNode alignContent(YogaAlign align) {
mNode.setAlignContent(align);
return this;
}
StyledNode flexWrap(YogaWrap wrap) {
mNode.setWrap(wrap);
return this;
}
StyledNode positionType(YogaPositionType positionType) {
mNode.setPositionType(positionType);
return this;
}
StyledNode overflow(YogaOverflow overflow) {
mNode.setOverflow(overflow);
return this;
}
StyledNode flexShrink(float flexShrink) {
mNode.setFlexShrink(flexShrink);
return this;
}
StyledNode display(YogaDisplay display) {
mNode.setDisplay(display);
return this;
}
StyledNode flexGrow(float flexGrow) {
mNode.setFlexGrow(flexGrow);
return this;
}
StyledNode flex(float flex) {
mNode.setFlex(flex);
return this;
}
StyledNode flexBasis(float flexBasis) {
mNode.setFlexBasis(flexBasis);
return this;
}
StyledNode flexBasisPercent(float flexBasis) {
mNode.setFlexBasisPercent(flexBasis);
return this;
}
StyledNode margin(YogaEdge edge, float margin) {
mNode.setMargin(edge, margin);
return this;
}
StyledNode marginPercent(YogaEdge edge, float margin) {
mNode.setMarginPercent(edge, margin);
return this;
}
StyledNode marginAuto(YogaEdge edge) {
mNode.setMarginAuto(edge);
return this;
}
StyledNode padding(YogaEdge edge, float padding) {
mNode.setPadding(edge, padding);
return this;
}
StyledNode paddingPercent(YogaEdge edge, float padding) {
mNode.setPaddingPercent(edge, padding);
return this;
}
StyledNode border(YogaEdge edge, float border) {
mNode.setBorder(edge, border);
return this;
}
StyledNode position(YogaEdge edge, float position) {
mNode.setPosition(edge, position);
return this;
}
StyledNode positionPercent(YogaEdge edge, float position) {
mNode.setPositionPercent(edge, position);
return this;
}
StyledNode minWidth(float minWidth) {
mNode.setMinWidth(minWidth);
return this;
}
StyledNode minWidthPercent(float minWidth) {
mNode.setMinWidthPercent(minWidth);
return this;
}
StyledNode minHeight(float minHeight) {
mNode.setMinHeight(minHeight);
return this;
}
StyledNode minHeightPercent(float minHeight) {
mNode.setMinHeightPercent(minHeight);
return this;
}
StyledNode maxWidth(float maxWidth) {
mNode.setMaxWidth(maxWidth);
return this;
}
StyledNode maxWidthPercent(float maxWidth) {
mNode.setMaxWidthPercent(maxWidth);
return this;
}
StyledNode maxHeight(float maxHeight) {
mNode.setMaxHeight(maxHeight);
return this;
}
StyledNode maxHeightPercent(float maxHeight) {
mNode.setMaxHeightPercent(maxHeight);
return this;
}
StyledNode aspectRatio(float aspectRatio) {
mNode.setAspectRatio(aspectRatio);
return this;
}
}
}

View File

@@ -26,7 +26,7 @@ android {
}
dependencies {
implementation 'com.facebook.soloader:soloader:0.2.0'
implementation 'com.facebook.soloader:soloader:0.5.1'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
compileOnly project(':yoga:proguard-annotations')
}

View File

@@ -7,6 +7,6 @@ load("//:yoga_defs.bzl", "YOGA_ROOTS")
android_prebuilt_aar(
name = "soloader",
aar = "soloader-0.1.0.aar",
aar = "soloader-0.5.1.aar",
visibility = YOGA_ROOTS,
)

Binary file not shown.

Binary file not shown.

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
#include <gtest/gtest.h>
@@ -64,6 +64,90 @@ TEST(YogaTest, flex_basis_flex_grow_column) {
YGConfigFree(config);
}
TEST(YogaTest, flex_shrink_flex_grow_row) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0);
YGNodeStyleSetFlexShrink(root_child0, 1);
YGNodeStyleSetWidth(root_child0, 500);
YGNodeStyleSetHeight(root_child0, 100);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 0);
YGNodeStyleSetFlexShrink(root_child1, 1);
YGNodeStyleSetWidth(root_child1, 500);
YGNodeStyleSetHeight(root_child1, 100);
YGNodeInsertChild(root, root_child1, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, flex_shrink_flex_grow_child_flex_shrink_other_child) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 500);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child0, 0);
YGNodeStyleSetFlexShrink(root_child0, 1);
YGNodeStyleSetWidth(root_child0, 500);
YGNodeStyleSetHeight(root_child0, 100);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexGrow(root_child1, 1);
YGNodeStyleSetFlexShrink(root_child1, 1);
YGNodeStyleSetWidth(root_child1, 500);
YGNodeStyleSetHeight(root_child1, 100);
YGNodeInsertChild(root, root_child1, 1);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(250, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, flex_basis_flex_grow_row) {
const YGConfigRef config = YGConfigNew();

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* 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/YGNode.h>
#include <yoga/Yoga.h>

View File

@@ -5,8 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html
#include <gtest/gtest.h>
#include <yoga/Yoga.h>

View File

@@ -1,12 +1,14 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include "Utils.h"
using namespace facebook;
YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction) {
@@ -16,18 +18,18 @@ YGFlexDirection YGFlexDirectionCross(
}
float YGFloatMax(const float a, const float b) {
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fmaxf(a, b);
}
return YGFloatIsUndefined(a) ? b : a;
return yoga::isUndefined(a) ? b : a;
}
float YGFloatMin(const float a, const float b) {
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fminf(a, b);
}
return YGFloatIsUndefined(a) ? b : a;
return yoga::isUndefined(a) ? b : a;
}
bool YGValueEqual(const YGValue a, const YGValue b) {
@@ -36,7 +38,7 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
}
if (a.unit == YGUnitUndefined ||
(YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) {
(yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) {
return true;
}
@@ -44,14 +46,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
}
bool YGFloatsEqual(const float a, const float b) {
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
return fabs(a - b) < 0.0001f;
}
return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
return yoga::isUndefined(a) && yoga::isUndefined(b);
}
float YGFloatSanitize(const float& val) {
return YGFloatIsUndefined(val) ? 0 : val;
return yoga::isUndefined(val) ? 0 : val;
}
float YGUnwrapFloatOptional(const YGFloatOptional& op) {

View File

@@ -1,17 +1,20 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include "YGFloatOptional.h"
#include <cstdlib>
#include <iostream>
#include "Yoga.h"
#include "Yoga-internal.h"
YGFloatOptional::YGFloatOptional(const float& value) {
if (YGFloatIsUndefined(value)) {
using namespace facebook;
YGFloatOptional::YGFloatOptional(float value) {
if (yoga::isUndefined(value)) {
isUndefined_ = true;
value_ = 0;
} else {
@@ -20,9 +23,7 @@ YGFloatOptional::YGFloatOptional(const float& value) {
}
}
YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
const float& YGFloatOptional::getValue() const {
float YGFloatOptional::getValue() const {
if (isUndefined_) {
// Abort, accessing a value of an undefined float optional
std::cerr << "Tried to get value of an undefined YGFloatOptional\n";
@@ -31,18 +32,9 @@ const float& YGFloatOptional::getValue() const {
return value_;
}
void YGFloatOptional::setValue(const float& val) {
value_ = val;
isUndefined_ = false;
}
const bool& YGFloatOptional::isUndefined() const {
return isUndefined_;
}
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
if (isUndefined_ == op.isUndefined()) {
return isUndefined_ ? true : value_ == op.getValue();
return isUndefined_ || value_ == op.getValue();
}
return false;
}
@@ -51,14 +43,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
return !(*this == op);
}
bool YGFloatOptional::operator==(const float& val) const {
if (YGFloatIsUndefined(val) == isUndefined_) {
return isUndefined_ ? true : val == value_;
bool YGFloatOptional::operator==(float val) const {
if (yoga::isUndefined(val) == isUndefined_) {
return isUndefined_ || val == value_;
}
return false;
}
bool YGFloatOptional::operator!=(const float& val) const {
bool YGFloatOptional::operator!=(float val) const {
return !(*this == val);
}
@@ -84,9 +76,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
}
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
return *this == op ? true : *this > op;
return *this == op || *this > op;
}
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
return *this == op ? true : *this < op;
return *this == op || *this < op;
}

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
struct YGFloatOptional {
@@ -13,18 +13,23 @@ struct YGFloatOptional {
bool isUndefined_;
public:
explicit YGFloatOptional(const float& value);
explicit YGFloatOptional();
explicit YGFloatOptional(float value);
explicit YGFloatOptional() : value_(0), isUndefined_(true) {}
// Program will terminate if the value of an undefined is accessed. Please
// make sure to check if the optional is defined before calling this function.
// To check if float optional is defined, use `isUndefined()`.
const float& getValue() const;
float getValue() const;
// Sets the value of float optional, and thus isUndefined is assigned false.
void setValue(const float& val);
void setValue(float val) {
value_ = val;
isUndefined_ = false;
}
const bool& isUndefined() const;
bool isUndefined() const {
return isUndefined_;
}
YGFloatOptional operator+(const YGFloatOptional& op);
bool operator>(const YGFloatOptional& op) const;
@@ -34,6 +39,6 @@ struct YGFloatOptional {
bool operator==(const YGFloatOptional& op) const;
bool operator!=(const YGFloatOptional& op) const;
bool operator==(const float& val) const;
bool operator!=(const float& val) const;
bool operator==(float val) const;
bool operator!=(float val) const;
};

View File

@@ -1,13 +1,15 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include "YGLayout.h"
#include "Utils.h"
using namespace facebook;
const std::array<float, 2> kYGDefaultDimensionValues = {
{YGUndefined, YGUndefined}};
@@ -46,20 +48,16 @@ bool YGLayout::operator==(YGLayout layout) const {
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
}
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
if (!yoga::isUndefined(measuredDimensions[0]) ||
!yoga::isUndefined(layout.measuredDimensions[0])) {
isEqual =
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
}
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
if (!yoga::isUndefined(measuredDimensions[1]) ||
!yoga::isUndefined(layout.measuredDimensions[1])) {
isEqual =
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
}
return isEqual;
}
bool YGLayout::operator!=(YGLayout layout) const {
return !(*this == layout);
}

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
@@ -38,5 +38,7 @@ struct YGLayout {
YGLayout();
bool operator==(YGLayout layout) const;
bool operator!=(YGLayout layout) const;
bool operator!=(YGLayout layout) const {
return !(*this == layout);
}
};

View File

@@ -1,93 +1,15 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include "YGNode.h"
#include <iostream>
#include "Utils.h"
void* YGNode::getContext() const {
return context_;
}
YGPrintFunc YGNode::getPrintFunc() const {
return print_;
}
bool YGNode::getHasNewLayout() const {
return hasNewLayout_;
}
YGNodeType YGNode::getNodeType() const {
return nodeType_;
}
YGMeasureFunc YGNode::getMeasure() const {
return measure_;
}
YGBaselineFunc YGNode::getBaseline() const {
return baseline_;
}
YGDirtiedFunc YGNode::getDirtied() const {
return dirtied_;
}
YGStyle& YGNode::getStyle() {
return style_;
}
YGLayout& YGNode::getLayout() {
return layout_;
}
uint32_t YGNode::getLineIndex() const {
return lineIndex_;
}
YGNodeRef YGNode::getOwner() const {
return owner_;
}
YGNodeRef YGNode::getParent() const {
return getOwner();
}
YGVector YGNode::getChildren() const {
return children_;
}
uint32_t YGNode::getChildrenCount() const {
return static_cast<uint32_t>(children_.size());
}
YGNodeRef YGNode::getChild(uint32_t index) const {
return children_.at(index);
}
YGNodeRef YGNode::getNextChild() const {
return nextChild_;
}
YGConfigRef YGNode::getConfig() const {
return config_;
}
bool YGNode::isDirty() const {
return isDirty_;
}
YGValue YGNode::getResolvedDimension(int index) {
return resolvedDimensions_[index];
}
std::array<YGValue, 2> YGNode::getResolvedDimensions() const {
return resolvedDimensions_;
}
using namespace facebook;
YGFloatOptional YGNode::getLeadingPosition(
const YGFlexDirection& axis,
@@ -177,30 +99,6 @@ YGFloatOptional YGNode::getMarginForAxis(
// Setters
void YGNode::setContext(void* context) {
context_ = context;
}
void YGNode::setPrintFunc(YGPrintFunc printFunc) {
print_ = printFunc;
}
void YGNode::setHasNewLayout(bool hasNewLayout) {
hasNewLayout_ = hasNewLayout;
}
void YGNode::setNodeType(YGNodeType nodeType) {
nodeType_ = nodeType;
}
void YGNode::setStyleFlexDirection(YGFlexDirection direction) {
style_.flexDirection = direction;
}
void YGNode::setStyleAlignContent(YGAlign alignContent) {
style_.alignContent = alignContent;
}
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
if (measureFunc == nullptr) {
measure_ = nullptr;
@@ -221,38 +119,6 @@ void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
measure_ = measureFunc;
}
void YGNode::setBaseLineFunc(YGBaselineFunc baseLineFunc) {
baseline_ = baseLineFunc;
}
void YGNode::setDirtiedFunc(YGDirtiedFunc dirtiedFunc) {
dirtied_ = dirtiedFunc;
}
void YGNode::setStyle(const YGStyle& style) {
style_ = style;
}
void YGNode::setLayout(const YGLayout& layout) {
layout_ = layout;
}
void YGNode::setLineIndex(uint32_t lineIndex) {
lineIndex_ = lineIndex;
}
void YGNode::setOwner(YGNodeRef owner) {
owner_ = owner;
}
void YGNode::setChildren(const YGVector& children) {
children_ = children;
}
void YGNode::setNextChild(YGNodeRef nextChild) {
nextChild_ = nextChild;
}
void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
children_[index] = child;
setChildRoot(child);
@@ -268,10 +134,6 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
setChildRoot(child);
}
void YGNode::setConfig(YGConfigRef config) {
config_ = config;
}
void YGNode::setDirty(bool isDirty) {
if (isDirty == isDirty_) {
return;
@@ -395,80 +257,6 @@ void YGNode::setPosition(
trailing[crossAxis]);
}
YGNode::YGNode()
: context_(nullptr),
print_(nullptr),
hasNewLayout_(true),
nodeType_(YGNodeTypeDefault),
measure_(nullptr),
baseline_(nullptr),
dirtied_(nullptr),
style_(YGStyle()),
layout_(YGLayout()),
lineIndex_(0),
owner_(nullptr),
children_(YGVector()),
nextChild_(nullptr),
config_(nullptr),
isDirty_(false),
resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {}
YGNode::YGNode(const YGNode& node)
: context_(node.context_),
print_(node.print_),
hasNewLayout_(node.hasNewLayout_),
nodeType_(node.nodeType_),
measure_(node.measure_),
baseline_(node.baseline_),
dirtied_(node.dirtied_),
style_(node.style_),
layout_(node.layout_),
lineIndex_(node.lineIndex_),
owner_(node.owner_),
children_(node.children_),
nextChild_(node.nextChild_),
config_(node.config_),
isDirty_(node.isDirty_),
resolvedDimensions_(node.resolvedDimensions_) {}
YGNode::YGNode(const YGConfigRef newConfig) : YGNode() {
config_ = newConfig;
}
YGNode::YGNode(
void* context,
YGPrintFunc print,
bool hasNewLayout,
YGNodeType nodeType,
YGMeasureFunc measure,
YGBaselineFunc baseline,
YGDirtiedFunc dirtied,
YGStyle style,
const YGLayout& layout,
uint32_t lineIndex,
YGNodeRef owner,
const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config,
bool isDirty,
std::array<YGValue, 2> resolvedDimensions)
: context_(context),
print_(print),
hasNewLayout_(hasNewLayout),
nodeType_(nodeType),
measure_(measure),
baseline_(baseline),
dirtied_(dirtied),
style_(style),
layout_(layout),
lineIndex_(lineIndex),
owner_(owner),
children_(children),
nextChild_(nextChild),
config_(config),
isDirty_(isDirty),
resolvedDimensions_(resolvedDimensions) {}
YGNode& YGNode::operator=(const YGNode& node) {
if (&node == this) {
return *this;
@@ -490,7 +278,6 @@ YGNode& YGNode::operator=(const YGNode& node) {
lineIndex_ = node.getLineIndex();
owner_ = node.getOwner();
children_ = node.getChildren();
nextChild_ = node.getNextChild();
config_ = node.getConfig();
isDirty_ = node.isDirty();
resolvedDimensions_ = node.getResolvedDimensions();
@@ -553,11 +340,6 @@ void YGNode::clearChildren() {
children_.shrink_to_fit();
}
YGNode::~YGNode() {
// All the member variables are deallocated externally, so no need to
// deallocate here
}
// Other Methods
void YGNode::cloneChildrenIfNeeded() {
@@ -648,7 +430,7 @@ bool YGNode::isNodeFlexible() {
float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
if (YGFlexDirectionIsRow(axis) &&
style_.border[YGEdgeStart].unit != YGUnitUndefined &&
!YGFloatIsUndefined(style_.border[YGEdgeStart].value) &&
!yoga::isUndefined(style_.border[YGEdgeStart].value) &&
style_.border[YGEdgeStart].value >= 0.0f) {
return style_.border[YGEdgeStart].value;
}
@@ -661,7 +443,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const {
if (YGFlexDirectionIsRow(flexDirection) &&
style_.border[YGEdgeEnd].unit != YGUnitUndefined &&
!YGFloatIsUndefined(style_.border[YGEdgeEnd].value) &&
!yoga::isUndefined(style_.border[YGEdgeEnd].value) &&
style_.border[YGEdgeEnd].value >= 0.0f) {
return style_.border[YGEdgeEnd].value;
}

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
#include <stdio.h>
#include "YGConfig.h"
@@ -14,83 +14,126 @@
struct YGNode {
private:
void* context_;
YGPrintFunc print_;
bool hasNewLayout_;
YGNodeType nodeType_;
YGMeasureFunc measure_;
YGBaselineFunc baseline_;
YGDirtiedFunc dirtied_;
YGStyle style_;
YGLayout layout_;
uint32_t lineIndex_;
YGNodeRef owner_;
YGVector children_;
YGNodeRef nextChild_;
YGConfigRef config_;
bool isDirty_;
std::array<YGValue, 2> resolvedDimensions_;
void* context_ = nullptr;
YGPrintFunc print_ = nullptr;
bool hasNewLayout_ = true;
YGNodeType nodeType_ = YGNodeTypeDefault;
YGMeasureFunc measure_ = nullptr;
YGBaselineFunc baseline_ = nullptr;
YGDirtiedFunc dirtied_ = nullptr;
YGStyle style_ = {};
YGLayout layout_ = {};
uint32_t lineIndex_ = 0;
YGNodeRef owner_ = nullptr;
YGVector children_ = {};
YGConfigRef config_ = nullptr;
bool isDirty_ = false;
std::array<YGValue, 2> resolvedDimensions_ = {
{YGValueUndefined, YGValueUndefined}};
YGFloatOptional relativePosition(
const YGFlexDirection& axis,
const float& axisSize) const;
public:
YGNode();
~YGNode();
explicit YGNode(const YGConfigRef newConfig);
YGNode(const YGNode& node);
YGNode() = default;
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
explicit YGNode(const YGConfigRef newConfig) : config_(newConfig){};
YGNode(const YGNode& node) = default;
YGNode& operator=(const YGNode& node);
YGNode(
void* context,
YGPrintFunc print,
bool hasNewLayout,
YGNodeType nodeType,
YGMeasureFunc measure,
YGBaselineFunc baseline,
YGDirtiedFunc dirtied,
YGStyle style,
const YGLayout& layout,
uint32_t lineIndex,
YGNodeRef owner,
const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config,
bool isDirty,
std::array<YGValue, 2> resolvedDimensions);
// Getters
void* getContext() const;
YGPrintFunc getPrintFunc() const;
bool getHasNewLayout() const;
YGNodeType getNodeType() const;
YGMeasureFunc getMeasure() const;
YGBaselineFunc getBaseline() const;
YGDirtiedFunc getDirtied() const;
void* getContext() const {
return context_;
}
YGPrintFunc getPrintFunc() const {
return print_;
}
bool getHasNewLayout() const {
return hasNewLayout_;
}
YGNodeType getNodeType() const {
return nodeType_;
}
YGMeasureFunc getMeasure() const {
return measure_;
}
YGBaselineFunc getBaseline() const {
return baseline_;
}
YGDirtiedFunc getDirtied() const {
return dirtied_;
}
// For Performance reasons passing as reference.
YGStyle& getStyle();
YGStyle& getStyle() {
return style_;
}
const YGStyle& getStyle() const {
return style_;
}
// For Performance reasons passing as reference.
YGLayout& getLayout();
uint32_t getLineIndex() const;
YGLayout& getLayout() {
return layout_;
}
const YGLayout& getLayout() const {
return layout_;
}
uint32_t getLineIndex() const {
return lineIndex_;
}
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
// the YogaTree that a YGNode belongs to.
// This method will return the parent of the YGNode when a YGNode only belongs
// to one YogaTree or nullptr when the YGNode is shared between two or more
// YogaTrees.
YGNodeRef getOwner() const;
YGNodeRef getOwner() const {
return owner_;
}
// Deprecated, use getOwner() instead.
YGNodeRef getParent() const;
YGVector getChildren() const;
uint32_t getChildrenCount() const;
YGNodeRef getChild(uint32_t index) const;
YGNodeRef getNextChild() const;
YGConfigRef getConfig() const;
bool isDirty() const;
std::array<YGValue, 2> getResolvedDimensions() const;
YGValue getResolvedDimension(int index);
YGNodeRef getParent() const {
return getOwner();
}
const YGVector& getChildren() const {
return children_;
}
YGNodeRef getChild(uint32_t index) const {
return children_.at(index);
}
YGConfigRef getConfig() const {
return config_;
}
bool isDirty() const {
return isDirty_;
}
std::array<YGValue, 2> getResolvedDimensions() const {
return resolvedDimensions_;
}
YGValue getResolvedDimension(int index) const {
return resolvedDimensions_[index];
}
// Methods related to positions, margin, padding and border
YGFloatOptional getLeadingPosition(const YGFlexDirection& axis,
YGFloatOptional getLeadingPosition(
const YGFlexDirection& axis,
const float& axisSize) const;
bool isLeadingPositionDefined(const YGFlexDirection& axis) const;
bool isTrailingPosDefined(const YGFlexDirection& axis) const;
@@ -122,22 +165,66 @@ struct YGNode {
const float& widthSize) const;
// Setters
void setContext(void* context);
void setPrintFunc(YGPrintFunc printFunc);
void setHasNewLayout(bool hasNewLayout);
void setNodeType(YGNodeType nodeTye);
void setContext(void* context) {
context_ = context;
}
void setPrintFunc(YGPrintFunc printFunc) {
print_ = printFunc;
}
void setHasNewLayout(bool hasNewLayout) {
hasNewLayout_ = hasNewLayout;
}
void setNodeType(YGNodeType nodeType) {
nodeType_ = nodeType;
}
void setStyleFlexDirection(YGFlexDirection direction) {
style_.flexDirection = direction;
}
void setStyleAlignContent(YGAlign alignContent) {
style_.alignContent = alignContent;
}
void setMeasureFunc(YGMeasureFunc measureFunc);
void setBaseLineFunc(YGBaselineFunc baseLineFunc);
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc);
void setStyle(const YGStyle& style);
void setStyleFlexDirection(YGFlexDirection direction);
void setStyleAlignContent(YGAlign alignContent);
void setLayout(const YGLayout& layout);
void setLineIndex(uint32_t lineIndex);
void setOwner(YGNodeRef owner);
void setChildren(const YGVector& children);
void setNextChild(YGNodeRef nextChild);
void setConfig(YGConfigRef config);
void setBaseLineFunc(YGBaselineFunc baseLineFunc) {
baseline_ = baseLineFunc;
}
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) {
dirtied_ = dirtiedFunc;
}
void setStyle(const YGStyle& style) {
style_ = style;
}
void setLayout(const YGLayout& layout) {
layout_ = layout;
}
void setLineIndex(uint32_t lineIndex) {
lineIndex_ = lineIndex;
}
void setOwner(YGNodeRef owner) {
owner_ = owner;
}
void setChildren(const YGVector& children) {
children_ = children;
}
// TODO: rvalue override for setChildren
void setConfig(YGConfigRef config) {
config_ = config;
}
void setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction);
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis);

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#include "YGStyle.h"
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
@@ -98,9 +98,3 @@ bool YGStyle::operator==(const YGStyle& style) {
return areNonFloatValuesEqual;
}
bool YGStyle::operator!=(YGStyle style) {
return !(*this == style);
}
YGStyle::~YGStyle() {}

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
#include "YGFloatOptional.h"
#include "Yoga-internal.h"
@@ -32,12 +32,14 @@ struct YGStyle {
std::array<YGValue, 2> dimensions;
std::array<YGValue, 2> minDimensions;
std::array<YGValue, 2> maxDimensions;
// Yoga specific properties, not compatible with flexbox specification
YGFloatOptional aspectRatio;
YGStyle();
// Yoga specific properties, not compatible with flexbox specification
bool operator==(const YGStyle& style);
bool operator!=(YGStyle style);
~YGStyle();
bool operator!=(YGStyle style) {
return !(*this == style);
}
~YGStyle() = default;
};

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
#include <algorithm>
#include <array>
@@ -16,13 +16,34 @@ using YGVector = std::vector<YGNodeRef>;
YG_EXTERN_C_BEGIN
WIN_EXPORT float YGRoundValueToPixelGrid(const float value,
WIN_EXPORT float YGRoundValueToPixelGrid(
const float value,
const float pointScaleFactor,
const bool forceCeil,
const bool forceFloor);
YG_EXTERN_C_END
namespace facebook {
namespace yoga {
inline bool isUndefined(float value) {
// Value of a float in the case of it being not defined is 10.1E20. Earlier
// it used to be NAN, the benefit of which was that if NAN is involved in any
// mathematical expression the result was NAN. But since we want to have
// `-ffast-math` flag being used by compiler which assumes that the floating
// point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But
// now if YGUndefined is involved in any mathematical operations this
// value(10.1E20) would change. So the following check makes sure that if the
// value is outside a range (-10E8, 10E8) then it is undefined.
return value >= 10E8 || value <= -10E8;
}
} // namespace yoga
} // namespace facebook
using namespace facebook;
extern const std::array<YGEdge, 4> trailing;
extern const std::array<YGEdge, 4> leading;
extern bool YGValueEqual(const YGValue a, const YGValue b);
@@ -62,20 +83,20 @@ struct YGCachedMeasurement {
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
heightMeasureMode == measurement.heightMeasureMode;
if (!YGFloatIsUndefined(availableWidth) ||
!YGFloatIsUndefined(measurement.availableWidth)) {
if (!yoga::isUndefined(availableWidth) ||
!yoga::isUndefined(measurement.availableWidth)) {
isEqual = isEqual && availableWidth == measurement.availableWidth;
}
if (!YGFloatIsUndefined(availableHeight) ||
!YGFloatIsUndefined(measurement.availableHeight)) {
if (!yoga::isUndefined(availableHeight) ||
!yoga::isUndefined(measurement.availableHeight)) {
isEqual = isEqual && availableHeight == measurement.availableHeight;
}
if (!YGFloatIsUndefined(computedWidth) ||
!YGFloatIsUndefined(measurement.computedWidth)) {
if (!yoga::isUndefined(computedWidth) ||
!yoga::isUndefined(measurement.computedWidth)) {
isEqual = isEqual && computedWidth == measurement.computedWidth;
}
if (!YGFloatIsUndefined(computedHeight) ||
!YGFloatIsUndefined(measurement.computedHeight)) {
if (!yoga::isUndefined(computedHeight) ||
!yoga::isUndefined(measurement.computedHeight)) {
isEqual = isEqual && computedHeight == measurement.computedHeight;
}
@@ -87,7 +108,6 @@ struct YGCachedMeasurement {
// layouts should not require more than 16 entries to fit within the cache.
#define YG_MAX_CACHED_RESULT_COUNT 16
static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f;
static const float kWebDefaultFlexShrink = 1.0f;

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,10 @@
/**
/*
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
*
*/
#pragma once
#include <assert.h>
@@ -45,19 +45,29 @@ typedef struct YGValue {
extern const YGValue YGValueUndefined;
extern const YGValue YGValueAuto;
#ifdef __cplusplus
extern bool operator==(const YGValue& lhs, const YGValue& rhs);
extern bool operator!=(const YGValue& lhs, const YGValue& rhs);
#endif
typedef struct YGConfig* YGConfigRef;
typedef struct YGNode* YGNodeRef;
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
typedef YGSize (*YGMeasureFunc)(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode);
typedef float (*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
typedef float (
*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
typedef void (*YGDirtiedFunc)(YGNodeRef node);
typedef void (*YGPrintFunc)(YGNodeRef node);
typedef int (*YGLogger)(const YGConfigRef config,
typedef int (*YGLogger)(
const YGConfigRef config,
const YGNodeRef node,
YGLogLevel level,
const char* format,
@@ -74,7 +84,8 @@ WIN_EXPORT void YGNodeFreeRecursive(const YGNodeRef node);
WIN_EXPORT void YGNodeReset(const YGNodeRef node);
WIN_EXPORT int32_t YGNodeGetInstanceCount(void);
WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
WIN_EXPORT void YGNodeInsertChild(
const YGNodeRef node,
const YGNodeRef child,
const uint32_t index);
@@ -99,7 +110,8 @@ WIN_EXPORT void YGNodeSetChildren(
const YGNodeRef children[],
const uint32_t count);
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
WIN_EXPORT void YGNodeCalculateLayout(
const YGNodeRef node,
const float availableWidth,
const float availableHeight,
const YGDirection ownerDirection);
@@ -112,15 +124,18 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
// marking manually.
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
// This function marks the current node and all its descendants as dirty. This function is added to test yoga benchmarks.
// This function is not expected to be used in production as calling `YGCalculateLayout` will cause the recalculation of each and every node.
// This function marks the current node and all its descendants as dirty. This
// function is added to test yoga benchmarks. This function is not expected to
// be used in production as calling `YGCalculateLayout` will cause the
// recalculation of each and every node.
WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node);
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
WIN_EXPORT bool YGFloatIsUndefined(const float value);
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
const YGMeasureMode widthMode,
const float width,
const YGMeasureMode heightMode,
const float height,
@@ -134,48 +149,9 @@ WIN_EXPORT bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
const float marginColumn,
const YGConfigRef config);
WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode);
#define YG_NODE_PROPERTY(type, name, paramName) \
WIN_EXPORT void YGNodeSet##name(const YGNodeRef node, type paramName); \
WIN_EXPORT type YGNodeGet##name(const YGNodeRef node);
#define YG_NODE_STYLE_PROPERTY(type, name, paramName) \
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const type paramName); \
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
#define YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const float paramName); \
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, const float paramName); \
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO(type, name, paramName) \
YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node);
#define YG_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
const YGEdge edge, \
const type paramName); \
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT(type, name, paramName) \
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
const YGEdge edge, \
const float paramName); \
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, \
const YGEdge edge, \
const float paramName); \
WIN_EXPORT WIN_STRUCT(type) YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(type, name) \
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge);
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
#define YG_NODE_LAYOUT_EDGE_PROPERTY(type, name) \
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT void YGNodeCopyStyle(
const YGNodeRef dstNode,
const YGNodeRef srcNode);
void* YGNodeGetContext(YGNodeRef node);
void YGNodeSetContext(YGNodeRef node, void* context);
@@ -194,89 +170,239 @@ void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
bool YGNodeIsDirty(YGNodeRef node);
bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node);
YG_NODE_STYLE_PROPERTY(YGDirection, Direction, direction);
YG_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);
YG_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent);
YG_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent);
YG_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems);
YG_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf);
YG_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType);
YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
YG_NODE_STYLE_PROPERTY(float, Flex, flex);
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis);
WIN_EXPORT void YGNodeStyleSetDirection(
const YGNodeRef node,
const YGDirection direction);
WIN_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeRef node);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Position, position);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Margin, margin);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(YGValue, Margin);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Padding, padding);
YG_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
WIN_EXPORT void YGNodeStyleSetFlexDirection(
const YGNodeRef node,
const YGFlexDirection flexDirection);
WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Width, width);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Height, height);
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinWidth, minWidth);
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinHeight, minHeight);
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxWidth, maxWidth);
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxHeight, maxHeight);
WIN_EXPORT void YGNodeStyleSetJustifyContent(
const YGNodeRef node,
const YGJustify justifyContent);
WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetAlignContent(
const YGNodeRef node,
const YGAlign alignContent);
WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetAlignItems(
const YGNodeRef node,
const YGAlign alignItems);
WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetAlignSelf(
const YGNodeRef node,
const YGAlign alignSelf);
WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetPositionType(
const YGNodeRef node,
const YGPositionType positionType);
WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetFlexWrap(
const YGNodeRef node,
const YGWrap flexWrap);
WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetOverflow(
const YGNodeRef node,
const YGOverflow overflow);
WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetDisplay(
const YGNodeRef node,
const YGDisplay display);
WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
WIN_EXPORT float YGNodeStyleGetFlex(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetFlexGrow(
const YGNodeRef node,
const float flexGrow);
WIN_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetFlexShrink(
const YGNodeRef node,
const float flexShrink);
WIN_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetFlexBasis(
const YGNodeRef node,
const float flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node,
const float flexBasis);
WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetPosition(
const YGNodeRef node,
const YGEdge edge,
const float position);
WIN_EXPORT void YGNodeStyleSetPositionPercent(
const YGNodeRef node,
const YGEdge edge,
const float position);
WIN_EXPORT WIN_STRUCT(YGValue)
YGNodeStyleGetPosition(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT void YGNodeStyleSetMargin(
const YGNodeRef node,
const YGEdge edge,
const float margin);
WIN_EXPORT void YGNodeStyleSetMarginPercent(
const YGNodeRef node,
const YGEdge edge,
const float margin);
WIN_EXPORT void YGNodeStyleSetMarginAuto(
const YGNodeRef node,
const YGEdge edge);
WIN_EXPORT YGValue
YGNodeStyleGetMargin(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT void YGNodeStyleSetPadding(
const YGNodeRef node,
const YGEdge edge,
const float padding);
WIN_EXPORT void YGNodeStyleSetPaddingPercent(
const YGNodeRef node,
const YGEdge edge,
const float padding);
WIN_EXPORT YGValue
YGNodeStyleGetPadding(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT void YGNodeStyleSetBorder(
const YGNodeRef node,
const YGEdge edge,
const float border);
WIN_EXPORT float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT void YGNodeStyleSetWidth(const YGNodeRef node, const float width);
WIN_EXPORT void YGNodeStyleSetWidthPercent(
const YGNodeRef node,
const float width);
WIN_EXPORT void YGNodeStyleSetWidthAuto(const YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetWidth(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetHeight(const YGNodeRef node, const float height);
WIN_EXPORT void YGNodeStyleSetHeightPercent(
const YGNodeRef node,
const float height);
WIN_EXPORT void YGNodeStyleSetHeightAuto(const YGNodeRef node);
WIN_EXPORT YGValue YGNodeStyleGetHeight(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetMinWidth(
const YGNodeRef node,
const float minWidth);
WIN_EXPORT void YGNodeStyleSetMinWidthPercent(
const YGNodeRef node,
const float minWidth);
WIN_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetMinHeight(
const YGNodeRef node,
const float minHeight);
WIN_EXPORT void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node,
const float minHeight);
WIN_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetMaxWidth(
const YGNodeRef node,
const float maxWidth);
WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(
const YGNodeRef node,
const float maxWidth);
WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeRef node);
WIN_EXPORT void YGNodeStyleSetMaxHeight(
const YGNodeRef node,
const float maxHeight);
WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node,
const float maxHeight);
WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeRef node);
// Yoga specific properties, not compatible with flexbox specification
// Aspect ratio control the size of the undefined dimension of a node.
// Aspect ratio is encoded as a floating point value width/height. e.g. A value of 2 leads to a node
// with a width twice the size of its height while a value of 0.5 gives the opposite effect.
// Aspect ratio is encoded as a floating point value width/height. e.g. A value
// of 2 leads to a node with a width twice the size of its height while a value
// of 0.5 gives the opposite effect.
//
// - On a node with a set width/height aspect ratio control the size of the unset dimension
// - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if
// unset
// - On a node with a measure function aspect ratio works as though the measure function measures
// the flex basis
// - On a node with flex grow/shrink aspect ratio controls the size of the node in the cross axis if
// unset
// - On a node with a set width/height aspect ratio control the size of the
// unset dimension
// - On a node with a set flex basis aspect ratio controls the size of the node
// in the cross axis if unset
// - On a node with a measure function aspect ratio works as though the measure
// function measures the flex basis
// - On a node with flex grow/shrink aspect ratio controls the size of the node
// in the cross axis if unset
// - Aspect ratio takes min/max dimensions into account
YG_NODE_STYLE_PROPERTY(float, AspectRatio, aspectRatio);
WIN_EXPORT void YGNodeStyleSetAspectRatio(
const YGNodeRef node,
const float aspectRatio);
WIN_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeRef node);
YG_NODE_LAYOUT_PROPERTY(float, Left);
YG_NODE_LAYOUT_PROPERTY(float, Top);
YG_NODE_LAYOUT_PROPERTY(float, Right);
YG_NODE_LAYOUT_PROPERTY(float, Bottom);
YG_NODE_LAYOUT_PROPERTY(float, Width);
YG_NODE_LAYOUT_PROPERTY(float, Height);
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
YG_NODE_LAYOUT_PROPERTY(bool, HadOverflow);
WIN_EXPORT float YGNodeLayoutGetLeft(const YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetTop(const YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetRight(const YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetBottom(const YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetWidth(const YGNodeRef node);
WIN_EXPORT float YGNodeLayoutGetHeight(const YGNodeRef node);
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(const YGNodeRef node);
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(const YGNodeRef node);
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node);
// Get the computed values for these nodes after performing layout. If they were set using
// point values then the returned value will be the same as YGNodeStyleGetXXX. However if
// they were set using a percentage value then the returned value is the computed value used
// during layout.
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
// Get the computed values for these nodes after performing layout. If they were
// set using point values then the returned value will be the same as
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
// returned value is the computed value used during layout.
WIN_EXPORT float YGNodeLayoutGetMargin(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT float YGNodeLayoutGetBorder(const YGNodeRef node, const YGEdge edge);
WIN_EXPORT float YGNodeLayoutGetPadding(
const YGNodeRef node,
const YGEdge edge);
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
WIN_EXPORT void YGLog(const YGNodeRef node, YGLogLevel level, const char *message, ...);
WIN_EXPORT void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...);
WIN_EXPORT void
YGLog(const YGNodeRef node, YGLogLevel level, const char* message, ...);
WIN_EXPORT void YGLogWithConfig(
const YGConfigRef config,
YGLogLevel level,
const char* format,
...);
WIN_EXPORT void YGAssert(const bool condition, const char* message);
WIN_EXPORT void YGAssertWithNode(const YGNodeRef node, const bool condition, const char *message);
WIN_EXPORT void YGAssertWithConfig(const YGConfigRef config,
WIN_EXPORT void YGAssertWithNode(
const YGNodeRef node,
const bool condition,
const char* message);
WIN_EXPORT void YGAssertWithConfig(
const YGConfigRef config,
const bool condition,
const char* message);
// Set this to number of pixels in 1 point to round calculation results
// If you want to avoid rounding - set PointScaleFactor to 0
WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint);
WIN_EXPORT void YGConfigSetPointScaleFactor(
const YGConfigRef config,
const float pixelsInPoint);
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
const YGConfigRef config,
const bool shouldDiffLayout);
// Yoga previously had an error where containers would take the maximum space possible instead of
// the minimum
// like they are supposed to. In practice this resulted in implicit behaviour similar to align-self:
// stretch;
// Because this was such a long-standing bug we must allow legacy users to switch back to this
// behaviour.
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config,
// Yoga previously had an error where containers would take the maximum space
// possible instead of the minimum like they are supposed to. In practice this
// resulted in implicit behaviour similar to align-self: stretch; Because this
// was such a long-standing bug we must allow legacy users to switch back to
// this behaviour.
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
const YGConfigRef config,
const bool useLegacyStretchBehaviour);
// YGConfig
@@ -285,18 +411,23 @@ WIN_EXPORT void YGConfigFree(const YGConfigRef config);
WIN_EXPORT void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src);
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature,
const bool enabled);
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature);
// Using the web defaults is the prefered configuration for new projects.
// Usage of non web defaults should be considered as legacy.
WIN_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled);
WIN_EXPORT void YGConfigSetUseWebDefaults(
const YGConfigRef config,
const bool enabled);
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
WIN_EXPORT void YGConfigSetCloneNodeFunc(const YGConfigRef config,
WIN_EXPORT void YGConfigSetCloneNodeFunc(
const YGConfigRef config,
const YGCloneNodeFunc callback);
// Export only for C#
@@ -319,7 +450,9 @@ YG_EXTERN_C_END
#include <vector>
// Calls f on each node in the tree including the given node argument.
extern void YGTraversePreOrder(YGNodeRef const node, std::function<void(YGNodeRef node)>&& f);
extern void YGTraversePreOrder(
YGNodeRef const node,
std::function<void(YGNodeRef node)>&& f);
extern void YGNodeSetChildren(
YGNodeRef const owner,

View File

@@ -190,3 +190,43 @@ def yoga_prebuilt_jar(*args, **kwargs):
def is_apple_platform():
return True
def yoga_apple_binary():
if is_apple_platform():
yoganet_ios_srcs = []
for arch in [
"iphonesimulator-x86_64",
"iphoneos-arm64",
]:
name = "yoganet-" + arch
yoganet_ios_srcs.append(":" + name)
native.genrule(
name = name,
srcs = [
yoga_dep(":yogaApple#%s,static" % arch),
yoga_dep("YogaKit:YogaKitApple#%s,static" % arch),
yoga_dep("csharp:yoganetApple#%s,static" % arch),
],
out = "libyoga-%s.a" % arch,
cmd = "libtool -static -o $OUT $SRCS",
visibility = [yoga_dep("csharp:yoganet-ios")],
)
native.genrule(
name = "yoganet-ios",
srcs = yoganet_ios_srcs,
out = "libyoga.a",
cmd = "lipo $SRCS -create -output $OUT",
visibility = ["PUBLIC"],
)
yoganet_macosx_target = "csharp:yoganetAppleMac#macosx-%s,dynamic"
native.genrule(
name = "yoganet-macosx",
srcs = [
yoga_dep(yoganet_macosx_target % "x86_64"),
],
out = "libyoga.dylib",
cmd = "lipo $SRCS -create -output $OUT",
visibility = ["PUBLIC"],
)