Compare commits

..

1 Commits

Author SHA1 Message Date
yxping
8bea26d0a0 Fix test failure about zero_size_with_child
A test about parent has zero width and height can not pass.
2018-03-30 15:12:50 +08:00
98 changed files with 15520 additions and 4014 deletions

View File

@@ -1,58 +1,16 @@
language: java language: node_js
node_js:
env: - "8"
- TARGET: website
- TARGET: android
install: install:
- cd website - cd website
- yarn --ignore-scripts - yarn --ignore-scripts
- cd .. - cd ..
cache:
directories:
- $HOME/buck
- $HOME/.gradle
before_install:
- |
if [[ -n "$encrypted_d27e803291ff_iv" ]]; then
openssl aes-256-cbc -K $encrypted_d27e803291ff_key -iv $encrypted_d27e803291ff_iv -in scripts/setup-keys.enc -d >> gradle.properties;
fi
# Android
- |
if [[ $TARGET = "android" ]]; then
pushd $HOME
git clone --depth 1 https://github.com/facebook/buck.git
cd buck
ant
popd
export PATH=$PATH:$HOME/buck/bin/
buck --version
export TERMINAL=dumb
source scripts/android-setup.sh && installAndroidSDK
export ANDROID_SDK=$ANDROID_HOME
export ANDROID_NDK_REPOSITORY=$HOME/android-ndk
export ANDROID_NDK_HOME=$ANDROID_NDK_REPOSITORY/android-ndk-r15c
fi
# Website
- |
if [[ $TARGET = "website" ]]; then
nvm install 8
nvm use 8
fi
script: script:
- | - cd website
if [[ $TARGET = "android" ]]; then - yarn build
./gradlew testDebugUnit && scripts/publish-snapshot.sh - cd ..
fi
- |
if [[ $TARGET = "website" ]]; then
pushd website
yarn build
popd
fi
deploy: deploy:
provider: pages provider: pages
@@ -65,4 +23,3 @@ deploy:
keep-history: true keep-history: true
on: on:
branch: master branch: master
condition: $TARGET = website

21
BUCK
View File

@@ -2,7 +2,8 @@
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "LIBRARY_COMPILER_FLAGS", "subdir_glob", "yoga_cxx_library", "yoga_cxx_test", "yoga_dep")
load("//:yoga_defs.bzl", "LIBRARY_COMPILER_FLAGS", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "yoga_dep", "cxx_library", "cxx_test")
GMOCK_OVERRIDE_FLAGS = [ GMOCK_OVERRIDE_FLAGS = [
# gmock does not mark mocked methods as override, ignore the warnings in tests # gmock does not mark mocked methods as override, ignore the warnings in tests
@@ -17,7 +18,7 @@ TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
"-std=c++1y", "-std=c++1y",
] ]
yoga_cxx_library( cxx_library(
name = "yoga", name = "yoga",
srcs = glob(["yoga/*.cpp"]), srcs = glob(["yoga/*.cpp"]),
header_namespace = "", header_namespace = "",
@@ -31,7 +32,21 @@ yoga_cxx_library(
], ],
) )
yoga_cxx_test( cxx_library(
name = "yogafastmath",
srcs = glob(["yoga/*.cpp"]),
header_namespace = "",
exported_headers = subdir_glob([("", "yoga/*.h")]),
compiler_flags = COMPILER_FLAGS + ["-ffast-math"],
soname = "libyogafastmathcore.$(ext)",
tests = [":YogaTests"],
visibility = ["PUBLIC"],
deps = [
yoga_dep("lib/fb:ndklog"),
],
)
cxx_test(
name = "YogaTests", name = "YogaTests",
srcs = glob(["tests/*.cpp"]), srcs = glob(["tests/*.cpp"]),
compiler_flags = TEST_COMPILER_FLAGS, compiler_flags = TEST_COMPILER_FLAGS,

View File

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

View File

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

View File

@@ -2,7 +2,8 @@
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "subdir_glob", "yoga_apple_library", "yoga_apple_test", "yoga_dep")
load("//:yoga_defs.bzl", "yoga_dep", "apple_library", "apple_test")
COMPILER_FLAGS = [ COMPILER_FLAGS = [
"-fobjc-arc", "-fobjc-arc",
@@ -24,7 +25,7 @@ COMPILER_FLAGS = [
"-Wunused-value", "-Wunused-value",
] ]
yoga_apple_library( apple_library(
name = "YogaKit", name = "YogaKit",
srcs = glob(["Source/**/*.m"]), srcs = glob(["Source/**/*.m"]),
header_namespace = "", header_namespace = "",
@@ -48,7 +49,7 @@ yoga_apple_library(
], ],
) )
yoga_apple_test( apple_test(
name = "YogaKitTests", name = "YogaKitTests",
srcs = glob(["Tests/**/*.m"]), srcs = glob(["Tests/**/*.m"]),
compiler_flags = COMPILER_FLAGS, compiler_flags = COMPILER_FLAGS,

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "yoga_android_aar", "yoga_android_resource") load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "android_aar", "android_resource")
yoga_android_aar( android_aar(
name = "android", name = "android",
manifest_skeleton = "src/main/AndroidManifest.xml", manifest_skeleton = "src/main/AndroidManifest.xml",
visibility = [ visibility = [
@@ -20,7 +20,7 @@ yoga_android_aar(
], ],
) )
yoga_android_resource( android_resource(
name = "res", name = "res",
package = "com.facebook.yoga.android", package = "com.facebook.yoga.android",
res = "src/main/res", res = "src/main/res",

View File

@@ -4,9 +4,9 @@
# This source code is licensed under the license found in the # This source code is licensed under the license found in the
# LICENSE-examples file in the root directory of this source tree. # LICENSE-examples file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_RES_TARGET", "ANDROID_SAMPLE_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "yoga_android_binary", "yoga_android_resource") load("//:yoga_defs.bzl", "ANDROID_SAMPLE_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "ANDROID_RES_TARGET", "android_binary", "android_resource")
yoga_android_binary( android_binary(
name = "sample", name = "sample",
keystore = ":debug_keystore", keystore = ":debug_keystore",
manifest = "AndroidManifest.xml", manifest = "AndroidManifest.xml",
@@ -16,7 +16,7 @@ yoga_android_binary(
], ],
) )
yoga_android_resource( android_resource(
name = "res", name = "res",
package = "com.facebook.samples.yoga", package = "com.facebook.samples.yoga",
res = "res", res = "res",

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the license found in the # This source code is licensed under the license found in the
# LICENSE-examples file in the root directory of this source tree. # LICENSE-examples file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "ANDROID_SUPPORT_TARGET", "APPCOMPAT_TARGET", "SOLOADER_TARGET", "yoga_android_library") load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "ANDROID_SUPPORT_TARGET", "APPCOMPAT_TARGET", "SOLOADER_TARGET", "android_library")
yoga_android_library( android_library(
name = "yoga", name = "yoga",
srcs = glob(["**/*.java"]), srcs = glob(["**/*.java"]),
visibility = [ visibility = [

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "JSR_305_TARGET", "SOLOADER_TARGET", "yoga_android_library") load("//:yoga_defs.bzl", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "JSR_305_TARGET", "SOLOADER_TARGET", "android_library")
yoga_android_library( android_library(
name = "android", name = "android",
srcs = glob(["**/*.java"]), srcs = glob(["**/*.java"]),
visibility = [ visibility = [

View File

@@ -46,14 +46,14 @@ import java.util.Map;
* <YogaLayout * <YogaLayout
* xmlns:android="http://schemas.android.com/apk/res/android" * xmlns:android="http://schemas.android.com/apk/res/android"
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android" * xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
* android:layout_width="match_owner" * android:layout_width="match_parent"
* android:layout_height="match_owner" * android:layout_height="match_parent"
* yoga:flex_direction="row" * yoga:flex_direction="row"
* yoga:padding_all="10dp" * yoga:padding_all="10dp"
* > * >
* <TextView * <TextView
* android:layout_width="match_owner" * android:layout_width="match_parent"
* android:layout_height="match_owner" * android:layout_height="match_parent"
* android:text="Hello, World!" * android:text="Hello, World!"
* yoga:flex="1" * yoga:flex="1"
* /> * />
@@ -262,11 +262,11 @@ public class YogaLayout extends ViewGroup {
return; return;
} }
final YogaNode owner = node.getOwner(); final YogaNode parent = node.getParent();
for (int i = 0; i < owner.getChildCount(); i++) { for (int i = 0; i < parent.getChildCount(); i++) {
if (owner.getChildAt(i).equals(node)) { if (parent.getChildAt(i).equals(node)) {
owner.removeChildAt(i); parent.removeChildAt(i);
break; break;
} }
} }
@@ -315,7 +315,7 @@ public class YogaLayout extends ViewGroup {
@Override @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
// Either we are a root of a tree, or this function is called by our owner's onLayout, in which // Either we are a root of a tree, or this function is called by our parent's onLayout, in which
// case our r-l and b-t are the size of our node. // case our r-l and b-t are the size of our node.
if (!(getParent() instanceof YogaLayout)) { if (!(getParent() instanceof YogaLayout)) {
createLayout( createLayout(
@@ -699,7 +699,7 @@ public class YogaLayout extends ViewGroup {
/** /**
* Constructs a set of layout params, given width and height specs. In this case, we can set * Constructs a set of layout params, given width and height specs. In this case, we can set
* the {@code yoga:width} and {@code yoga:height} if we are given them explicitly. If other * the {@code yoga:width} and {@code yoga:height} if we are given them explicitly. If other
* options (such as {@code match_owner} or {@code wrap_content} are given, then the owner * options (such as {@code match_parent} or {@code wrap_content} are given, then the parent
* LayoutParams will store them, and we deal with them during layout. (see * LayoutParams will store them, and we deal with them during layout. (see
* {@link YogaLayout#createLayout}) * {@link YogaLayout#createLayout})
* *
@@ -773,9 +773,9 @@ public class YogaLayout extends ViewGroup {
* {@code View}'s measure function. * {@code View}'s measure function.
* *
* @param node The yoga node to measure * @param node The yoga node to measure
* @param width The suggested width from the owner * @param width The suggested width from the parent
* @param widthMode The type of suggestion for the width * @param widthMode The type of suggestion for the width
* @param height The suggested height from the owner * @param height The suggested height from the parent
* @param heightMode The type of suggestion for the height * @param heightMode The type of suggestion for the height
* @return A measurement output ({@code YogaMeasureOutput}) for the node * @return A measurement output ({@code YogaMeasureOutput}) for the node
*/ */

View File

@@ -2,9 +2,10 @@
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "subdir_glob", "yoga_cxx_binary", "yoga_dep")
yoga_cxx_binary( load("//:yoga_defs.bzl", "yoga_dep")
cxx_binary(
name = "benchmark", name = "benchmark",
srcs = glob(["*.c"]), srcs = glob(["*.c"]),
headers = subdir_glob([("", "*.h")]), headers = subdir_glob([("", "*.h")]),

View File

@@ -5,72 +5,10 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#include <math.h> #include "YGBenchmark.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <yoga/Yoga.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, static YGSize _measure(YGNodeRef node,
float width, float width,
YGMeasureMode widthMode, YGMeasureMode widthMode,
@@ -159,7 +97,7 @@ YGBENCHMARKS({
YGNodeStyleSetHeight(grandGrandChild, 10); YGNodeStyleSetHeight(grandGrandChild, 10);
YGNodeInsertChild(grandChild, grandGrandChild, 0); YGNodeInsertChild(grandChild, grandGrandChild, 0);
for (uint32_t iiii = 0; iiii < 10; iiii++) { for (uint32_t iii = 0; iii < 10; iii++) {
const YGNodeRef grandGrandGrandChild = YGNodeNew(); const YGNodeRef grandGrandGrandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow); YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1); YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);

71
benchmark/YGBenchmark.h Normal file
View File

@@ -0,0 +1,71 @@
/**
* 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,7 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # 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", "yoga_dep", "cxx_library", "is_apple_platform")
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"] COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
@@ -21,7 +21,7 @@ csharp_library(
framework_ver = "net45", framework_ver = "net45",
) )
yoga_cxx_library( cxx_library(
name = "yoganet", name = "yoganet",
srcs = glob(["Yoga/YGInterop.cpp"]), srcs = glob(["Yoga/YGInterop.cpp"]),
compiler_flags = COMPILER_FLAGS, compiler_flags = COMPILER_FLAGS,
@@ -35,38 +35,37 @@ yoga_cxx_library(
if is_apple_platform(): if is_apple_platform():
yoganet_ios_srcs = [] yoganet_ios_srcs = []
for arch in [ for arch in [
"iphonesimulator-x86_64", 'iphonesimulator-x86_64', 'iphoneos-arm64'
"iphoneos-arm64",
]: ]:
name = "yoganet-" + arch name = 'yoganet-' + arch
yoganet_ios_srcs.append(":" + name) yoganet_ios_srcs.append(':' + name)
genrule( genrule(
name = name, name = name,
srcs = [ srcs = [
yoga_dep(":yogaApple#%s,static" % arch), yoga_dep(':yoga#%s,static' % arch),
yoga_dep("YogaKit:YogaKitApple#%s,static" % arch), yoga_dep('YogaKit:YogaKit#%s,static' % arch),
yoga_dep("csharp:yoganetApple#%s,static" % arch), yoga_dep('csharp:yoganet#%s,static' % arch),
], ],
out = "libyoga-%s.a" % arch, out = 'libyoga-%s.a' % arch,
cmd = "libtool -static -o $OUT $SRCS", cmd = 'libtool -static -o $OUT $SRCS',
visibility = [yoga_dep("csharp:yoganet-ios")], visibility = [yoga_dep('csharp:yoganet-ios')],
) )
genrule( genrule(
name = "yoganet-ios", name = 'yoganet-ios',
srcs = yoganet_ios_srcs, srcs = yoganet_ios_srcs,
out = "libyoga.a", out = 'libyoga.a',
cmd = "lipo $SRCS -create -output $OUT", cmd = 'lipo $SRCS -create -output $OUT',
visibility = ["PUBLIC"], visibility = ['PUBLIC'],
) )
yoganet_macosx_target = "csharp:yoganetAppleMac#macosx-%s,dynamic" yoganet_macosx_target = 'csharp:yoganet#macosx-%s,dynamic'
genrule( genrule(
name = "yoganet-macosx", name = 'yoganet-macosx',
srcs = [ srcs = [
yoga_dep(yoganet_macosx_target % "x86_64"), yoga_dep(yoganet_macosx_target % 'x86_64')
], ],
out = "libyoga.dylib", out = 'libyoga.dylib',
cmd = "lipo $SRCS -create -output $OUT", cmd = 'lipo $SRCS -create -output $OUT',
visibility = ["PUBLIC"], visibility = ['PUBLIC'],
) )

View File

@@ -227,31 +227,19 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\yoga\Utils.h" />
<ClInclude Include="..\..\yoga\YGConfig.h" />
<ClInclude Include="..\..\yoga\YGEnums.h" />
<ClInclude Include="..\..\yoga\YGFloatOptional.h" />
<ClInclude Include="..\..\yoga\YGLayout.h" />
<ClInclude Include="..\..\yoga\YGMacros.h" />
<ClInclude Include="..\..\yoga\YGNode.h" />
<ClInclude Include="..\..\yoga\YGNodePrint.h" />
<ClInclude Include="..\..\yoga\YGStyle.h" />
<ClInclude Include="..\..\yoga\Yoga-internal.h" />
<ClInclude Include="..\..\yoga\Yoga.h" /> <ClInclude Include="..\..\yoga\Yoga.h" />
<ClInclude Include="..\..\yoga\YGEnums.h" />
<ClInclude Include="..\..\yoga\YGMacros.h" />
<ClInclude Include="..\..\yoga\YGNodeList.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="YGInterop.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\yoga\Utils.cpp" /> <ClCompile Include="..\..\yoga\Yoga.c" />
<ClCompile Include="..\..\yoga\YGConfig.cpp" /> <ClCompile Include="..\..\yoga\YGEnums.c" />
<ClCompile Include="..\..\yoga\YGEnums.cpp" /> <ClCompile Include="..\..\yoga\YGNodeList.c" />
<ClCompile Include="..\..\yoga\YGFloatOptional.cpp" />
<ClCompile Include="..\..\yoga\YGLayout.cpp" />
<ClCompile Include="..\..\yoga\YGNode.cpp" />
<ClCompile Include="..\..\yoga\YGNodePrint.cpp" />
<ClCompile Include="..\..\yoga\YGStyle.cpp" />
<ClCompile Include="..\..\yoga\Yoga.cpp" />
<ClCompile Include="YGInterop.cpp" /> <ClCompile Include="YGInterop.cpp" />
<ClCompile Include="dllmain.cpp"> <ClCompile Include="dllmain.cpp">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged> <CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>

View File

@@ -21,40 +21,19 @@
<ClInclude Include="targetver.h"> <ClInclude Include="targetver.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="resource.h"> <ClInclude Include="..\..\yoga\Yoga.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGEnums.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGFloatOptional.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGLayout.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\yoga\YGMacros.h"> <ClInclude Include="..\..\yoga\YGMacros.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\yoga\YGNode.h"> <ClInclude Include="..\..\yoga\YGNodeList.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\yoga\YGNodePrint.h"> <ClInclude Include="YGInterop.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\yoga\YGStyle.h"> <ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga-internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGConfig.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
@@ -65,36 +44,15 @@
<ClCompile Include="dllmain.cpp"> <ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\yoga\Yoga.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNodeList.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="YGInterop.cpp"> <ClCompile Include="YGInterop.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\yoga\Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGEnums.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGFloatOptional.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGLayout.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNodePrint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGStyle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\Yoga.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="Yoga.rc"> <ResourceCompile Include="Yoga.rc">

View File

@@ -104,5 +104,58 @@ namespace Facebook.Yoga
Assert.AreEqual(100f, root_child0_child0.LayoutHeight); Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
} }
[Test]
public void Test_zero_size_with_child()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
YogaNode root_child0 = new YogaNode(config);
root_child0.Width = 0;
root_child0.Height = 0;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 100;
root_child0_child0.Height = 100;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(0f, root.LayoutWidth);
Assert.AreEqual(0f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(0f, root_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(0f, root.LayoutWidth);
Assert.AreEqual(0f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(0f, root_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0.LayoutHeight);
Assert.AreEqual(-100f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
}
} }
} }

View File

@@ -7,3 +7,9 @@
<div style="width: 100px; height: 100px;"></div> <div style="width: 100px; height: 100px;"></div>
</div> </div>
</div> </div>
<div id="zero_size_with_child">
<div style="width: 0px; height: 0px;">
<div style="width: 100px; height: 100px;"></div>
</div>
</div>

View File

@@ -411,6 +411,8 @@ function getDefaultStyleValue(style) {
case 'bottom': case 'bottom':
case 'start': case 'start':
case 'end': case 'end':
case 'width':
case 'height':
return 'undefined'; return 'undefined';
} }
var node = document.getElementById('default'); var node = document.getElementById('default');

View File

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

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "FBJNI_JAVA_TARGET", "FBJNI_TARGET", "INFER_ANNOTATIONS_TARGET", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_cxx_library", "yoga_dep", "yoga_java_binary", "yoga_java_library", "yoga_java_test") load("//:yoga_defs.bzl", "FBJNI_TARGET", "JNI_TARGET", "INFER_ANNOTATIONS_TARGET", "JSR_305_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "JUNIT_TARGET", "FBJNI_JAVA_TARGET", "CXX_LIBRARY_WHITELIST", "ANDROID", "yoga_dep", "cxx_library", "java_library", "java_test", "java_binary")
yoga_cxx_library( cxx_library(
name = "jni", name = "jni",
srcs = glob(["jni/*.cpp"]), srcs = glob(["jni/*.cpp"]),
header_namespace = "", header_namespace = "",
@@ -28,7 +28,30 @@ yoga_cxx_library(
], ],
) )
yoga_java_library( cxx_library(
name = "jniFastMath",
srcs = glob(["jni/*.cpp"]),
header_namespace = "",
compiler_flags = [
"-fno-omit-frame-pointer",
"-fexceptions",
"-fPIC",
"-Wall",
"-Werror",
"-O3",
"-std=c++11",
],
platforms = ANDROID,
soname = "libyogafastmath.$(ext)",
visibility = ["PUBLIC"],
deps = [
FBJNI_TARGET,
JNI_TARGET,
yoga_dep(":yogafastmath"),
],
)
java_library(
name = "java", name = "java",
srcs = glob(["com/facebook/yoga/*.java"]), srcs = glob(["com/facebook/yoga/*.java"]),
required_for_source_only_abi = True, required_for_source_only_abi = True,
@@ -40,6 +63,7 @@ yoga_java_library(
visibility = ["PUBLIC"], visibility = ["PUBLIC"],
deps = [ deps = [
":jni", ":jni",
":jniFastMath",
INFER_ANNOTATIONS_TARGET, INFER_ANNOTATIONS_TARGET,
JSR_305_TARGET, JSR_305_TARGET,
PROGRUARD_ANNOTATIONS_TARGET, PROGRUARD_ANNOTATIONS_TARGET,
@@ -47,7 +71,7 @@ yoga_java_library(
], ],
) )
yoga_java_test( java_test(
name = "tests", name = "tests",
srcs = glob(["tests/**/*.java"]), srcs = glob(["tests/**/*.java"]),
cxx_library_whitelist = CXX_LIBRARY_WHITELIST, cxx_library_whitelist = CXX_LIBRARY_WHITELIST,
@@ -59,7 +83,7 @@ yoga_java_test(
], ],
) )
yoga_java_binary( java_binary(
name = "yoga", name = "yoga",
deps = [ deps = [
":java", ":java",

View File

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

View File

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

View File

@@ -1,10 +1,10 @@
/* /*
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
package com.facebook.yoga; package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.proguard.annotations.DoNotStrip;
@@ -16,12 +16,16 @@ public class YogaConfig {
public static int SPACING_TYPE = 1; public static int SPACING_TYPE = 1;
static { static {
if (YogaConstants.shouldUseFastMath) {
SoLoader.loadLibrary("yogafastmath");
} else {
SoLoader.loadLibrary("yoga"); SoLoader.loadLibrary("yoga");
} }
}
long mNativePointer; long mNativePointer;
private YogaLogger mLogger; private YogaLogger mLogger;
private YogaNodeCloneFunction mYogaNodeCloneFunction; private YogaNodeClonedFunction mNodeClonedFunction;
private native long jni_YGConfigNew(); private native long jni_YGConfigNew();
public YogaConfig() { public YogaConfig() {
@@ -93,15 +97,16 @@ public class YogaConfig {
return mLogger; return mLogger;
} }
private native void jni_YGConfigSetHasCloneNodeFunc(long nativePointer, boolean hasClonedFunc); private native void jni_YGConfigSetHasNodeClonedFunc(long nativePointer, boolean hasClonedFunc);
public void setOnCloneNode(YogaNodeCloneFunction cloneYogaNodeFunction) { public void setOnNodeCloned(YogaNodeClonedFunction nodeClonedFunction) {
mYogaNodeCloneFunction = cloneYogaNodeFunction; mNodeClonedFunction = nodeClonedFunction;
jni_YGConfigSetHasCloneNodeFunc(mNativePointer, cloneYogaNodeFunction != null); jni_YGConfigSetHasNodeClonedFunc(mNativePointer, nodeClonedFunction != null);
} }
@DoNotStrip @DoNotStrip
private final YogaNode cloneNode(YogaNode oldNode, YogaNode parent, int childIndex) { public final void onNodeCloned(
return mYogaNodeCloneFunction.cloneNode(oldNode, parent, childIndex); YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex) {
mNodeClonedFunction.onNodeCloned(oldNode, newNode, parent, childIndex);
} }
} }

View File

@@ -1,10 +1,10 @@
/* /*
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
package com.facebook.yoga; package com.facebook.yoga;
public class YogaConstants { public class YogaConstants {
@@ -18,6 +18,8 @@ public class YogaConstants {
*/ */
public static final float UNDEFINED = (float) (10E20); public static final float UNDEFINED = (float) (10E20);
public static boolean shouldUseFastMath = false;
public static boolean isUndefined(float value) { public static boolean isUndefined(float value) {
// Value of a float in the case of it being not defined is 10.1E20. Earlier it used to be NAN, // 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 // the benefit of which

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,8 @@
/* /*
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
package com.facebook.yoga; package com.facebook.yoga;
@@ -18,16 +17,20 @@ import javax.annotation.Nullable;
public class YogaNode implements Cloneable { public class YogaNode implements Cloneable {
static { static {
if (YogaConstants.shouldUseFastMath) {
SoLoader.loadLibrary("yogafastmath");
} else {
SoLoader.loadLibrary("yoga"); SoLoader.loadLibrary("yoga");
} }
}
/** /**
* Get native instance count. Useful for testing only. * Get native instance count. Useful for testing only.
*/ */
static native int jni_YGNodeGetInstanceCount(); static native int jni_YGNodeGetInstanceCount();
private YogaNode mOwner; private YogaNode mParent;
@Nullable private List<YogaNode> mChildren; private List<YogaNode> mChildren;
private YogaMeasureFunction mMeasureFunction; private YogaMeasureFunction mMeasureFunction;
private YogaBaselineFunction mBaselineFunction; private YogaBaselineFunction mBaselineFunction;
private long mNativePointer; private long mNativePointer;
@@ -144,15 +147,12 @@ public class YogaNode implements Cloneable {
} }
public YogaNode getChildAt(int i) { public YogaNode getChildAt(int i) {
if (mChildren == null) {
throw new IllegalStateException("YogaNode does not have children");
}
return mChildren.get(i); return mChildren.get(i);
} }
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index); private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
public void addChildAt(YogaNode child, int i) { public void addChildAt(YogaNode child, int i) {
if (child.mOwner != null) { if (child.mParent != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first."); throw new IllegalStateException("Child already has a parent, it must be removed first.");
} }
@@ -160,105 +160,35 @@ public class YogaNode implements Cloneable {
mChildren = new ArrayList<>(4); mChildren = new ArrayList<>(4);
} }
mChildren.add(i, child); mChildren.add(i, child);
child.mOwner = this; child.mParent = this;
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i); jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
} }
private native void jni_YGNodeInsertSharedChild(long nativePointer, long childPointer, int index);
public void addSharedChildAt(YogaNode child, int i) {
if (mChildren == null) {
mChildren = new ArrayList<>(4);
}
mChildren.add(i, child);
child.mOwner = null;
jni_YGNodeInsertSharedChild(mNativePointer, child.mNativePointer, i);
}
private native void jni_YGNodeSetOwner(long nativePointer, long newOwnerNativePointer);
private native long jni_YGNodeClone(long nativePointer, Object newNode); private native long jni_YGNodeClone(long nativePointer, Object newNode);
@Override @Override
public YogaNode clone() { public YogaNode clone() throws CloneNotSupportedException {
try {
YogaNode clonedYogaNode = (YogaNode) super.clone(); YogaNode clonedYogaNode = (YogaNode) super.clone();
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode); long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
if (mChildren != null) {
for (YogaNode child : mChildren) {
child.jni_YGNodeSetOwner(child.mNativePointer, 0);
child.mOwner = null;
}
}
clonedYogaNode.mNativePointer = clonedNativePointer; clonedYogaNode.mNativePointer = clonedNativePointer;
clonedYogaNode.mOwner = null;
clonedYogaNode.mChildren = clonedYogaNode.mChildren =
mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null; mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null;
if (clonedYogaNode.mChildren != null) {
for (YogaNode child : clonedYogaNode.mChildren) {
child.mOwner = null;
}
}
return clonedYogaNode; return clonedYogaNode;
} catch (CloneNotSupportedException ex) {
// This class implements Cloneable, this should not happen
throw new RuntimeException(ex);
}
}
public YogaNode cloneWithNewChildren() {
try {
YogaNode clonedYogaNode = (YogaNode) super.clone();
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
clonedYogaNode.mOwner = null;
clonedYogaNode.mNativePointer = clonedNativePointer;
clonedYogaNode.clearChildren();
return clonedYogaNode;
} catch (CloneNotSupportedException ex) {
// This class implements Cloneable, this should not happen
throw new RuntimeException(ex);
}
}
private native void jni_YGNodeClearChildren(long nativePointer);
private void clearChildren() {
mChildren = null;
jni_YGNodeClearChildren(mNativePointer);
} }
private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer); private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
public YogaNode removeChildAt(int i) { public YogaNode removeChildAt(int i) {
if (mChildren == null) {
throw new IllegalStateException(
"Trying to remove a child of a YogaNode that does not have children");
}
final YogaNode child = mChildren.remove(i); final YogaNode child = mChildren.remove(i);
child.mOwner = null; child.mParent = null;
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer); jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
return child; return child;
} }
/**
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
* to.
* This method will return the parent of the {@link YogaNode} when the
* {@link YogaNode} only belongs to one YogaTree or null when the
* {@link YogaNode} is shared between two or more YogaTrees.
*/
@Nullable @Nullable
public YogaNode getOwner() { public
return mOwner; YogaNode getParent() {
} return mParent;
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
@Deprecated
@Nullable
public YogaNode getParent() {
return getOwner();
} }
public int indexOf(YogaNode child) { public int indexOf(YogaNode child) {
@@ -767,22 +697,4 @@ public class YogaNode implements Cloneable {
public void print() { public void print() {
jni_YGNodePrint(mNativePointer); jni_YGNodePrint(mNativePointer);
} }
/**
* This method replaces the child at childIndex position with the newNode received by parameter.
* This is different than calling removeChildAt and addChildAt because this method ONLY replaces
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
*
* @return the nativePointer of the newNode {@linl YogaNode}
*/
@DoNotStrip
private final long replaceChild(YogaNode newNode, int childIndex) {
if (mChildren == null) {
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
}
mChildren.remove(childIndex);
mChildren.add(childIndex, newNode);
newNode.mOwner = this;
return newNode.mNativePointer;
}
} }

View File

@@ -1,17 +0,0 @@
/*
* 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.
*
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaNodeCloneFunction {
@DoNotStrip
YogaNode cloneNode(YogaNode oldNode, YogaNode parent, int childIndex);
}

View File

@@ -0,0 +1,17 @@
/*
* 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.
*/
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaNodeClonedFunction {
@DoNotStrip
void onNodeCloned(YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +1,10 @@
/* /**
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
#include <fb/fbjni.h> #include <fb/fbjni.h>
#include <yoga/YGNode.h> #include <yoga/YGNode.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>
@@ -33,67 +33,42 @@ struct YGConfigContext {
} }
}; };
static inline weak_ref<JYogaNode>* YGNodeJobject(YGNodeRef node) { static inline weak_ref<JYogaNode> *YGNodeJobject(YGNodeRef node) {
return reinterpret_cast<weak_ref<JYogaNode>*>(node->getContext()); return reinterpret_cast<weak_ref<JYogaNode>*>(node->getContext());
} }
static void YGTransferLayoutDirection( static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNode) {
YGNodeRef node, static auto layoutDirectionField = javaNode->getClass()->getField<jint>("mLayoutDirection");
alias_ref<jobject> javaNode) { javaNode->setFieldValue(layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
static auto layoutDirectionField =
javaNode->getClass()->getField<jint>("mLayoutDirection");
javaNode->setFieldValue(
layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
} }
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) { static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if (!root->getHasNewLayout()) { if (root->getHasNewLayout()) {
return; if (auto obj = YGNodeJobject(root)->lockLocal()) {
}
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 widthField = obj->getClass()->getField<jfloat>("mWidth");
static auto heightField = obj->getClass()->getField<jfloat>("mHeight"); static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
static auto leftField = obj->getClass()->getField<jfloat>("mLeft"); static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
static auto topField = obj->getClass()->getField<jfloat>("mTop"); static auto topField = obj->getClass()->getField<jfloat>("mTop");
static auto marginLeftField = static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop"); static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
obj->getClass()->getField<jfloat>("mMarginRight"); static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");
static auto marginBottomField =
obj->getClass()->getField<jfloat>("mMarginBottom");
static auto paddingLeftField = static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
obj->getClass()->getField<jfloat>("mPaddingLeft"); static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingTopField = static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
obj->getClass()->getField<jfloat>("mPaddingTop"); static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto paddingRightField =
obj->getClass()->getField<jfloat>("mPaddingRight");
static auto paddingBottomField =
obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto borderLeftField = static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop"); static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
static auto borderRightField = static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
obj->getClass()->getField<jfloat>("mBorderRight"); static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
static auto borderBottomField =
obj->getClass()->getField<jfloat>("mBorderBottom");
static auto edgeSetFlagField = static auto edgeSetFlagField = obj->getClass()->getField<jint>("mEdgeSetFlag");
obj->getClass()->getField<jint>("mEdgeSetFlag"); static auto hasNewLayoutField = obj->getClass()->getField<jboolean>("mHasNewLayout");
static auto hasNewLayoutField = static auto doesLegacyStretchBehaviour =
obj->getClass()->getField<jboolean>("mHasNewLayout"); obj->getClass()->getField<jboolean>(
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
"mDoesLegacyStretchFlagAffectsLayout"); "mDoesLegacyStretchFlagAffectsLayout");
/* Those flags needs be in sync with YogaNode.java */ /* Those flags needs be in sync with YogaNode.java */
@@ -101,7 +76,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
const int PADDING = 2; const int PADDING = 2;
const int BORDER = 4; const int BORDER = 4;
int hasEdgeSetFlag = (int)obj->getFieldValue(edgeSetFlagField); int hasEdgeSetFlag = (int) obj->getFieldValue(edgeSetFlagField);
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root)); obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root)); obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
@@ -114,7 +89,8 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if ((hasEdgeSetFlag & MARGIN) == MARGIN) { if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
obj->setFieldValue( obj->setFieldValue(
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft)); marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop)); obj->setFieldValue(
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight)); marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue( obj->setFieldValue(
@@ -122,24 +98,17 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
} }
if ((hasEdgeSetFlag & PADDING) == PADDING) { if ((hasEdgeSetFlag & PADDING) == PADDING) {
obj->setFieldValue( obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft)); obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop)); obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
obj->setFieldValue(
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue(
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
} }
if ((hasEdgeSetFlag & BORDER) == BORDER) { if ((hasEdgeSetFlag & BORDER) == BORDER) {
obj->setFieldValue( obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop)); obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
obj->setFieldValue( obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight)); obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
obj->setFieldValue(
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
} }
obj->setFieldValue<jboolean>(hasNewLayoutField, true); obj->setFieldValue<jboolean>(hasNewLayoutField, true);
@@ -149,23 +118,23 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) { for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i)); YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
} }
} else {
YGLog(root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
}
}
} }
static void YGPrint(YGNodeRef node) { static void YGPrint(YGNodeRef node) {
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
cout << obj->toString() << endl; cout << obj->toString() << endl;
} else { } else {
YGLog( YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
node,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
} }
} }
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) { static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto baselineFunc = static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jfloat(jfloat, jfloat)>("baseline"); ->getMethod<jfloat(jfloat, jfloat)>("baseline");
return baselineFunc(obj, width, height); return baselineFunc(obj, width, height);
} else { } else {
@@ -173,43 +142,31 @@ static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
} }
} }
static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { static void YGJNIOnNodeClonedFunc(
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(addr)); YGNodeRef oldNode,
} YGNodeRef newNode,
YGNodeRef parent,
static inline YGConfigRef _jlong2YGConfigRef(jlong addr) { int childIndex) {
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
}
static YGNodeRef
YGJNIOnNodeClonedFunc(YGNodeRef oldNode, YGNodeRef owner, int childIndex) {
auto config = oldNode->getConfig(); auto config = oldNode->getConfig();
if (!config) { if (!config) {
return nullptr; return;
} }
static auto onNodeClonedFunc = findClassStatic("com/facebook/yoga/YogaConfig")
static auto onNodeClonedFunc = ->getMethod<void(
findClassStatic("com/facebook/yoga/YogaConfig") local_ref<JYogaNode>,
->getMethod<alias_ref<JYogaNode>( local_ref<JYogaNode>,
local_ref<JYogaNode>, local_ref<JYogaNode>, jint)>("cloneNode"); local_ref<JYogaNode>,
jint)>("onNodeCloned");
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config)); auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
auto javaConfig = context->config; auto javaConfig = context->config;
auto newNode = onNodeClonedFunc( onNodeClonedFunc(
javaConfig->get(), javaConfig->get(),
YGNodeJobject(oldNode)->lockLocal(), YGNodeJobject(oldNode)->lockLocal(),
YGNodeJobject(owner)->lockLocal(), YGNodeJobject(newNode)->lockLocal(),
YGNodeJobject(parent)->lockLocal(),
childIndex); childIndex);
static auto replaceChild =
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(local_ref<JYogaNode>, jint)>("replaceChild");
jlong newNodeNativePointer =
replaceChild(YGNodeJobject(owner)->lockLocal(), newNode, childIndex);
return _jlong2YGNodeRef(newNodeNativePointer);
} }
static YGSize YGJNIMeasureFunc( static YGSize YGJNIMeasureFunc(
@@ -219,30 +176,24 @@ static YGSize YGJNIMeasureFunc(
float height, float height,
YGMeasureMode heightMode) { YGMeasureMode heightMode) {
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
static auto measureFunc = static auto measureFunc = findClassStatic("com/facebook/yoga/YogaNode")
findClassStatic("com/facebook/yoga/YogaNode")
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure"); ->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
YGTransferLayoutDirection(node, obj); YGTransferLayoutDirection(node, obj);
const auto measureResult = const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode);
measureFunc(obj, width, widthMode, height, heightMode);
static_assert( static_assert(sizeof(measureResult) == 8,
sizeof(measureResult) == 8,
"Expected measureResult to be 8 bytes, or two 32 bit ints"); "Expected measureResult to be 8 bytes, or two 32 bit ints");
int32_t wBits = 0xFFFFFFFF & (measureResult >> 32); int32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
int32_t hBits = 0xFFFFFFFF & measureResult; int32_t hBits = 0xFFFFFFFF & measureResult;
const float* measuredWidth = reinterpret_cast<float*>(&wBits); const float *measuredWidth = reinterpret_cast<float *>(&wBits);
const float* measuredHeight = reinterpret_cast<float*>(&hBits); const float *measuredHeight = reinterpret_cast<float *>(&hBits);
return YGSize{*measuredWidth, *measuredHeight}; return YGSize{*measuredWidth, *measuredHeight};
} else { } else {
YGLog( YGLog(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
node,
YGLogLevelError,
"Java YGNode was GCed during layout calculation\n");
return YGSize{ return YGSize{
widthMode == YGMeasureModeUndefined ? 0 : width, widthMode == YGMeasureModeUndefined ? 0 : width,
heightMode == YGMeasureModeUndefined ? 0 : height, heightMode == YGMeasureModeUndefined ? 0 : height,
@@ -254,11 +205,10 @@ struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;"; static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
}; };
static int YGJNILogFunc( static int YGJNILogFunc(const YGConfigRef config,
const YGConfigRef config,
const YGNodeRef node, const YGNodeRef node,
YGLogLevel level, YGLogLevel level,
const char* format, const char *format,
va_list args) { va_list args) {
int result = vsnprintf(NULL, 0, format, args); int result = vsnprintf(NULL, 0, format, args);
std::vector<char> buffer(1 + result); std::vector<char> buffer(1 + result);
@@ -266,16 +216,13 @@ static int YGJNILogFunc(
static auto logFunc = static auto logFunc =
findClassStatic("com/facebook/yoga/YogaLogger") findClassStatic("com/facebook/yoga/YogaLogger")
->getMethod<void( ->getMethod<void(local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
static auto logLevelFromInt = static auto logLevelFromInt =
JYogaLogLevel::javaClassStatic() JYogaLogLevel::javaClassStatic()->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
if (auto obj = YGNodeJobject(node)->lockLocal()) { if (auto obj = YGNodeJobject(node)->lockLocal()) {
auto jlogger = auto jlogger = reinterpret_cast<global_ref<jobject> *>(YGConfigGetContext(config));
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
logFunc( logFunc(
jlogger->get(), jlogger->get(),
obj, obj,
@@ -287,6 +234,14 @@ static int YGJNILogFunc(
return result; return result;
} }
static inline YGNodeRef _jlong2YGNodeRef(jlong addr) {
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(addr));
}
static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
}
jlong jni_YGNodeNew(alias_ref<jobject> thiz) { jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
const YGNodeRef node = YGNodeNew(); const YGNodeRef node = YGNodeNew();
node->setContext(new weak_ref<jobject>(make_weak(thiz))); node->setContext(new weak_ref<jobject>(make_weak(thiz)));
@@ -303,16 +258,6 @@ jlong jni_YGNodeNewWithConfig(alias_ref<jobject> thiz, jlong configPointer) {
return reinterpret_cast<jlong>(node); return reinterpret_cast<jlong>(node);
} }
void jni_YGNodeSetOwner(
alias_ref<jobject> thiz,
jlong nativePointer,
jlong newOwnerNativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
const YGNodeRef newOwnerNode = _jlong2YGNodeRef(newOwnerNativePointer);
node->setOwner(newOwnerNode);
}
jlong jni_YGNodeClone( jlong jni_YGNodeClone(
alias_ref<jobject> thiz, alias_ref<jobject> thiz,
jlong nativePointer, jlong nativePointer,
@@ -329,11 +274,6 @@ void jni_YGNodeFree(alias_ref<jobject> thiz, jlong nativePointer) {
YGNodeFree(node); YGNodeFree(node);
} }
void jni_YGNodeClearChildren(alias_ref<jobject> thiz, jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
node->clearChildren();
}
void jni_YGNodeReset(alias_ref<jobject> thiz, jlong nativePointer) { void jni_YGNodeReset(alias_ref<jobject> thiz, jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer); const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
void* context = node->getContext(); void* context = node->getContext();
@@ -344,46 +284,25 @@ void jni_YGNodeReset(alias_ref<jobject> thiz, jlong nativePointer) {
void jni_YGNodePrint(alias_ref<jobject> thiz, jlong nativePointer) { void jni_YGNodePrint(alias_ref<jobject> thiz, jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer); const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodePrint( YGNodePrint(node,
node, (YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout |
(YGPrintOptions)( YGPrintOptionsChildren));
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
} }
void jni_YGNodeInsertChild( void jni_YGNodeInsertChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer, jint index) {
alias_ref<jobject>, YGNodeInsertChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
jlong nativePointer,
jlong childPointer,
jint index) {
YGNodeInsertChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
} }
void jni_YGNodeInsertSharedChild( void jni_YGNodeRemoveChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer) {
alias_ref<jobject>, YGNodeRemoveChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
jlong nativePointer,
jlong childPointer,
jint index) {
YGNodeInsertSharedChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
} }
void jni_YGNodeRemoveChild( void jni_YGNodeCalculateLayout(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer,
jlong childPointer) {
YGNodeRemoveChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
}
void jni_YGNodeCalculateLayout(
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jfloat width, jfloat width,
jfloat height) { jfloat height) {
const YGNodeRef root = _jlong2YGNodeRef(nativePointer); const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
YGNodeCalculateLayout( YGNodeCalculateLayout(root,
root,
static_cast<float>(width), static_cast<float>(width),
static_cast<float>(height), static_cast<float>(height),
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer))); YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)));
@@ -404,28 +323,20 @@ jboolean jni_YGNodeIsDirty(alias_ref<jobject>, jlong nativePointer) {
return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty(); return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty();
} }
void jni_YGNodeSetHasMeasureFunc( void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasMeasureFunc) {
alias_ref<jobject>,
jlong nativePointer,
jboolean hasMeasureFunc) {
_jlong2YGNodeRef(nativePointer) _jlong2YGNodeRef(nativePointer)
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr); ->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
} }
void jni_YGNodeSetHasBaselineFunc( void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jboolean hasBaselineFunc) { jboolean hasBaselineFunc) {
_jlong2YGNodeRef(nativePointer) _jlong2YGNodeRef(nativePointer)
->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr); ->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
} }
void jni_YGNodeCopyStyle( void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNativePointer) {
alias_ref<jobject>, YGNodeCopyStyle(_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
jlong dstNativePointer,
jlong srcNativePointer) {
YGNodeCopyStyle(
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
} }
struct JYogaValue : public JavaClass<JYogaValue> { struct JYogaValue : public JavaClass<JYogaValue> {
@@ -448,75 +359,66 @@ struct JYogaValue : public JavaClass<JYogaValue> {
} }
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \ #define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
local_ref<jobject> jni_YGNodeStyleGet##name( \ local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \
alias_ref<jobject>, jlong nativePointer) { \ return JYogaValue::create(YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
return JYogaValue::create( \
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
} \ } \
\ \
void jni_YGNodeStyleSet##name( \ void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
alias_ref<jobject>, jlong nativePointer, jfloat value) { \ YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
} \ } \
\ \
void jni_YGNodeStyleSet##name##Percent( \ void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
alias_ref<jobject>, jlong nativePointer, jfloat value) { \ YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
} }
#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \ #define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_UNIT_PROP(name) \ YG_NODE_JNI_STYLE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto( \ void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer) { \
alias_ref<jobject>, jlong nativePointer) { \
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \ YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \
} }
#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \ #define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \
javatype jni_YGNodeStyleGet##name( \ javatype jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer, jint edge) { \
alias_ref<jobject>, jlong nativePointer, jint edge) { \ return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \
return (javatype)YGNodeStyleGet##name( \ static_cast<YGEdge>(edge)); \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
} \ } \
\ \
void jni_YGNodeStyleSet##name( \ void jni_YGNodeStyleSet##name(alias_ref<jobject>, \
alias_ref<jobject>, jlong nativePointer, jint edge, javatype value) { \ jlong nativePointer, \
YGNodeStyleSet##name( \ jint edge, \
_jlong2YGNodeRef(nativePointer), \ javatype value) { \
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \ static_cast<YGEdge>(edge), \
static_cast<type>(value)); \ static_cast<type>(value)); \
} }
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \ #define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
local_ref<jobject> jni_YGNodeStyleGet##name( \ local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, \
alias_ref<jobject>, jlong nativePointer, jint edge) { \ jlong nativePointer, \
return JYogaValue::create(YGNodeStyleGet##name( \ jint edge) { \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \ return JYogaValue::create( \
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
} \ } \
\ \
void jni_YGNodeStyleSet##name( \ void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \ YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \ static_cast<YGEdge>(edge), \
static_cast<float>(value)); \ static_cast<float>(value)); \
} \ } \
\ \
void jni_YGNodeStyleSet##name##Percent( \ void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, \
alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \ jlong nativePointer, \
YGNodeStyleSet##name##Percent( \ jint edge, \
_jlong2YGNodeRef(nativePointer), \ jfloat value) { \
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \ static_cast<YGEdge>(edge), \
static_cast<float>(value)); \ static_cast<float>(value)); \
} }
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(name) \ #define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \ YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto( \ void jni_YGNodeStyleSet##name##Auto(alias_ref<jobject>, jlong nativePointer, jint edge) { \
alias_ref<jobject>, jlong nativePointer, jint edge) { \ YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
YGNodeStyleSet##name##Auto( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
} }
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction); YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
@@ -530,12 +432,8 @@ YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow); YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display); YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
void jni_YGNodeStyleSetFlex( void jni_YGNodeStyleSetFlex(alias_ref<jobject>, jlong nativePointer, jfloat value) {
alias_ref<jobject>, YGNodeStyleSetFlex(_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
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, FlexGrow);
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink); YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
@@ -569,14 +467,14 @@ void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
YGConfigFree(config); YGConfigFree(config);
} }
void jni_YGConfigSetExperimentalFeatureEnabled( void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jint feature, jint feature,
jboolean enabled) { jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer); const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetExperimentalFeatureEnabled( YGConfigSetExperimentalFeatureEnabled(config,
config, static_cast<YGExperimentalFeature>(feature), enabled); static_cast<YGExperimentalFeature>(feature),
enabled);
} }
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
@@ -587,34 +485,31 @@ void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled); YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
} }
void jni_YGConfigSetUseWebDefaults( void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jboolean useWebDefaults) { jboolean useWebDefaults) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer); const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseWebDefaults(config, useWebDefaults); YGConfigSetUseWebDefaults(config, useWebDefaults);
} }
void jni_YGConfigSetPointScaleFactor( void jni_YGConfigSetPointScaleFactor(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jfloat pixelsInPoint) { jfloat pixelsInPoint) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer); const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPointScaleFactor(config, pixelsInPoint); YGConfigSetPointScaleFactor(config, pixelsInPoint);
} }
void jni_YGConfigSetUseLegacyStretchBehaviour( void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref<jobject>,
alias_ref<jobject>,
jlong nativePointer, jlong nativePointer,
jboolean useLegacyStretchBehaviour) { jboolean useLegacyStretchBehaviour) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer); const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour); YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
} }
void jni_YGConfigSetHasCloneNodeFunc( void jni_YGConfigSetHasNodeClonedFunc(
alias_ref<jobject> thiz, alias_ref<jobject> thiz,
jlong nativePointer, jlong nativePointer,
jboolean hasCloneNodeFunc) { jboolean hasNodeClonedFunc) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer); const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config)); auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
if (context && context->config) { if (context && context->config) {
@@ -622,15 +517,15 @@ void jni_YGConfigSetHasCloneNodeFunc(
context->config = nullptr; context->config = nullptr;
} }
if (hasCloneNodeFunc) { if (hasNodeClonedFunc) {
if (!context) { if (!context) {
context = new YGConfigContext(); context = new YGConfigContext();
YGConfigSetContext(config, context); YGConfigSetContext(config, context);
} }
context->config = new global_ref<jobject>(make_global(thiz)); context->config = new global_ref<jobject>(make_global(thiz));
YGConfigSetCloneNodeFunc(config, YGJNIOnNodeClonedFunc); YGConfigSetNodeClonedFunc(config, YGJNIOnNodeClonedFunc);
} else { } else {
YGConfigSetCloneNodeFunc(config, nullptr); YGConfigSetNodeClonedFunc(config, nullptr);
} }
} }
@@ -663,7 +558,7 @@ jint jni_YGNodeGetInstanceCount(alias_ref<jclass> clazz) {
#define YGMakeNativeMethod(name) makeNativeMethod(#name, name) #define YGMakeNativeMethod(name) makeNativeMethod(#name, name)
jint JNI_OnLoad(JavaVM* vm, void*) { jint JNI_OnLoad(JavaVM *vm, void *) {
return initialize(vm, [] { return initialize(vm, [] {
registerNatives( registerNatives(
"com/facebook/yoga/YogaNode", "com/facebook/yoga/YogaNode",
@@ -672,9 +567,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
YGMakeNativeMethod(jni_YGNodeNewWithConfig), YGMakeNativeMethod(jni_YGNodeNewWithConfig),
YGMakeNativeMethod(jni_YGNodeFree), YGMakeNativeMethod(jni_YGNodeFree),
YGMakeNativeMethod(jni_YGNodeReset), YGMakeNativeMethod(jni_YGNodeReset),
YGMakeNativeMethod(jni_YGNodeClearChildren),
YGMakeNativeMethod(jni_YGNodeInsertChild), YGMakeNativeMethod(jni_YGNodeInsertChild),
YGMakeNativeMethod(jni_YGNodeInsertSharedChild),
YGMakeNativeMethod(jni_YGNodeRemoveChild), YGMakeNativeMethod(jni_YGNodeRemoveChild),
YGMakeNativeMethod(jni_YGNodeCalculateLayout), YGMakeNativeMethod(jni_YGNodeCalculateLayout),
YGMakeNativeMethod(jni_YGNodeMarkDirty), YGMakeNativeMethod(jni_YGNodeMarkDirty),
@@ -748,7 +641,6 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
YGMakeNativeMethod(jni_YGNodeGetInstanceCount), YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
YGMakeNativeMethod(jni_YGNodePrint), YGMakeNativeMethod(jni_YGNodePrint),
YGMakeNativeMethod(jni_YGNodeClone), YGMakeNativeMethod(jni_YGNodeClone),
YGMakeNativeMethod(jni_YGNodeSetOwner),
}); });
registerNatives( registerNatives(
"com/facebook/yoga/YogaConfig", "com/facebook/yoga/YogaConfig",
@@ -760,7 +652,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor), YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour), YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
YGMakeNativeMethod(jni_YGConfigSetLogger), YGMakeNativeMethod(jni_YGConfigSetLogger),
YGMakeNativeMethod(jni_YGConfigSetHasCloneNodeFunc), YGMakeNativeMethod(jni_YGConfigSetHasNodeClonedFunc),
YGMakeNativeMethod( YGMakeNativeMethod(
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour), jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
}); });

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "yoga_java_library") load("//:yoga_defs.bzl", "YOGA_ROOTS", "java_library")
yoga_java_library( java_library(
name = "annotations", name = "annotations",
srcs = glob(["*.java"]), srcs = glob(["*.java"]),
source = "1.7", source = "1.7",

View File

@@ -101,4 +101,56 @@ public class YGDimensionTest {
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f); assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
} }
@Test
public void test_zero_size_with_child() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setWidth(0f);
root_child0.setHeight(0f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setWidth(100f);
root_child0_child0.setHeight(100f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(0f, root.getLayoutWidth(), 0.0f);
assertEquals(0f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(0f, root.getLayoutWidth(), 0.0f);
assertEquals(0f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(-100f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0_child0.getLayoutHeight(), 0.0f);
}
} }

View File

@@ -10,7 +10,6 @@ package com.facebook.yoga;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@@ -252,58 +251,16 @@ public class YogaNodeTest {
assertEquals(1, clonedChild.getChildCount()); assertEquals(1, clonedChild.getChildCount());
} }
@Test
public void testCloneWithNewChildren() throws Exception {
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
YogaNode child = new YogaNode(config);
YogaNode grandChild = new YogaNode(config);
root.addChildAt(child, 0);
child.addChildAt(grandChild, 0);
child.setFlexDirection(YogaFlexDirection.ROW);
YogaNode clonedChild = child.cloneWithNewChildren();
assertNotSame(clonedChild, child);
assertEquals(YogaFlexDirection.ROW, clonedChild.getFlexDirection());
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
assertEquals(0, clonedChild.getChildCount());
assertEquals(1, child.getChildCount());
}
@Test
public void testAddSharedChildCloneWithNewChildren() throws Exception {
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
YogaNode child = new YogaNode(config);
YogaNode grandChild = new YogaNode(config);
root.addChildAt(child, 0);
child.addChildAt(grandChild, 0);
child.setFlexDirection(YogaFlexDirection.ROW);
YogaNode clonedChild = child.cloneWithNewChildren();
assertNotSame(clonedChild, child);
assertEquals(YogaFlexDirection.ROW, clonedChild.getFlexDirection());
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
assertEquals(0, clonedChild.getChildCount());
assertEquals(1, child.getChildCount());
clonedChild.addSharedChildAt(grandChild, 0);
assertEquals(1, clonedChild.getChildCount());
assertNull(grandChild.getOwner());
}
@Test @Test
public void testCloneNodeListener() throws Exception { public void testCloneNodeListener() throws Exception {
final AtomicBoolean onNodeClonedExecuted = new AtomicBoolean(false); final AtomicBoolean onNodeClonedExecuted = new AtomicBoolean(false);
YogaConfig config = new YogaConfig(); YogaConfig config = new YogaConfig();
config.setOnCloneNode( config.setOnNodeCloned(
new YogaNodeCloneFunction() { new YogaNodeClonedFunction() {
@Override @Override
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) { public void onNodeCloned(
YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex) {
onNodeClonedExecuted.set(true); onNodeClonedExecuted.set(true);
return oldNode.clone();
} }
}); });
YogaNode root = new YogaNode(config); YogaNode root = new YogaNode(config);
@@ -311,7 +268,6 @@ public class YogaNodeTest {
root.setHeight(100f); root.setHeight(100f);
YogaNode child0 = new YogaNode(config); YogaNode child0 = new YogaNode(config);
root.addChildAt(child0, 0); root.addChildAt(child0, 0);
child0.setWidth(50f);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
// Force a clone to happen. // Force a clone to happen.
@@ -320,24 +276,20 @@ public class YogaNodeTest {
root2.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); root2.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertTrue(onNodeClonedExecuted.get()); assertTrue(onNodeClonedExecuted.get());
assertEquals(1, root2.getChildCount());
YogaNode clonedNode = root2.getChildAt(0);
assertNotSame(child0, clonedNode);
assertEquals(child0.getWidth(), clonedNode.getWidth());
assertEquals(50f, clonedNode.getWidth().value, 0.01f);
} }
@Test @Test
public void testOnNodeClonedLeak() throws Exception { public void testOnNodeClonedLeak() throws Exception {
YogaConfig config = new YogaConfig(); YogaConfig config = new YogaConfig();
config.setOnCloneNode( config.setOnNodeCloned(
new YogaNodeCloneFunction() { new YogaNodeClonedFunction() {
@Override @Override
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) { public void onNodeCloned(
return oldNode.clone(); YogaNode oldNode, YogaNode newNode, YogaNode parent, int childIndex) {
// Do nothing
} }
}); });
config.setOnCloneNode(null); config.setOnNodeCloned(null);
WeakReference<Object> ref = new WeakReference<Object>(config); WeakReference<Object> ref = new WeakReference<Object>(config);
// noinspection UnusedAssignment // noinspection UnusedAssignment
config = null; config = null;

View File

@@ -104,3 +104,59 @@ it("wrap_grandchild", function () {
config.free(); config.free();
} }
}); });
it("zero_size_with_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
var root_child0 = Yoga.Node.create(config);
root_child0.setWidth(0);
root_child0.setHeight(0);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setWidth(100);
root_child0_child0.setHeight(100);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(100 === root_child0_child0.getComputedHeight(), "100 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(0 === root.getComputedHeight(), "0 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(-100 === root_child0_child0.getComputedLeft(), "-100 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(100 === root_child0_child0.getComputedWidth(), "100 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(100 === root_child0_child0.getComputedHeight(), "100 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -61,7 +61,7 @@ for (let [name, results] of testResults) {
for (let [type, result] of results) { for (let [type, result] of results) {
console.log( console.log(
` - ${type}: ${result}ms (${Math.round((result / min) * 10000) / 100}%)`, ` - ${type}: ${result}ms (${Math.round(result / min * 10000) / 100}%)`,
); );
} }
} }

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "yoga_prebuilt_jar") load("//:yoga_defs.bzl", "YOGA_ROOTS", "prebuilt_jar")
yoga_prebuilt_jar( prebuilt_jar(
name = "android-support", name = "android-support",
binary_jar = "android-support-v4.jar", binary_jar = "android-support-v4.jar",
visibility = YOGA_ROOTS, visibility = YOGA_ROOTS,

View File

@@ -2,9 +2,10 @@
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID", "FBJNI_JAVA_TARGET", "JNI_TARGET", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library", "yoga_prebuilt_cxx_library")
yoga_prebuilt_cxx_library( include_defs("//yoga_defs.bzl")
prebuilt_cxx_library(
name = "ndklog", name = "ndklog",
exported_platform_linker_flags = [ exported_platform_linker_flags = [
( (
@@ -16,7 +17,7 @@ yoga_prebuilt_cxx_library(
visibility = YOGA_ROOTS, visibility = YOGA_ROOTS,
) )
yoga_cxx_library( cxx_library(
name = "fbjni", name = "fbjni",
srcs = glob(["src/main/cpp/**/*.cpp"]), srcs = glob(["src/main/cpp/**/*.cpp"]),
header_namespace = "", header_namespace = "",
@@ -34,7 +35,6 @@ yoga_cxx_library(
"-Wno-unused-parameter", "-Wno-unused-parameter",
"-std=c++11", "-std=c++11",
], ],
platforms = (ANDROID,),
visibility = ["PUBLIC"], visibility = ["PUBLIC"],
deps = [ deps = [
":ndklog", ":ndklog",

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "JSR_305_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_java_library") load("//:yoga_defs.bzl", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "JSR_305_TARGET", "java_library")
yoga_java_library( java_library(
name = "jni", name = "jni",
srcs = glob(["**/*.java"]), srcs = glob(["**/*.java"]),
proguard_config = "fbjni.pro", proguard_config = "fbjni.pro",

View File

@@ -2,14 +2,15 @@
# #
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library")
load("//:yoga_defs.bzl", "cxx_library", "YOGA_ROOTS")
COMPILER_FLAGS = [ COMPILER_FLAGS = [
"-std=c++11", "-std=c++11",
"-Wno-missing-prototypes", "-Wno-missing-prototypes",
] ]
yoga_cxx_library( cxx_library(
name = "gtest", name = "gtest",
srcs = glob(["googletest/googletest/src/*.cc"]), srcs = glob(["googletest/googletest/src/*.cc"]),
header_namespace = "", header_namespace = "",

View File

@@ -3,17 +3,17 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "yoga_java_library", "yoga_prebuilt_jar") load("//:yoga_defs.bzl", "YOGA_ROOTS", "prebuilt_jar", "java_library")
yoga_prebuilt_jar( prebuilt_jar(
name = "infer-annotations-jar", name = "infer-annotations-jar",
binary_jar = "infer-annotations-1.4.jar", binary_jar = "infer-annotations-1.4.jar",
) )
yoga_java_library( java_library(
name = "infer-annotations", name = "infer-annotations",
visibility = YOGA_ROOTS,
exported_deps = [ exported_deps = [
":infer-annotations-jar", ":infer-annotations-jar",
], ],
visibility = YOGA_ROOTS,
) )

View File

@@ -3,9 +3,9 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "yoga_cxx_library") load("//:yoga_defs.bzl", "cxx_library")
yoga_cxx_library( cxx_library(
name = "jni", name = "jni",
header_namespace = "", header_namespace = "",
exported_headers = [ exported_headers = [

View File

@@ -3,17 +3,17 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "yoga_java_library", "yoga_prebuilt_jar") load("//:yoga_defs.bzl", "YOGA_ROOTS", "prebuilt_jar", "java_library")
yoga_prebuilt_jar( prebuilt_jar(
name = "jsr305-jar", name = "jsr305-jar",
binary_jar = "jsr305.jar", binary_jar = "jsr305.jar",
) )
yoga_java_library( java_library(
name = "jsr-305", name = "jsr-305",
visibility = YOGA_ROOTS,
exported_deps = [ exported_deps = [
":jsr305-jar", ":jsr305-jar",
], ],
visibility = YOGA_ROOTS,
) )

View File

@@ -3,17 +3,17 @@
# This source code is licensed under the MIT license found in the # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree. # LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "YOGA_ROOTS", "yoga_java_library", "yoga_prebuilt_jar") load("//:yoga_defs.bzl", "YOGA_ROOTS", "prebuilt_jar", "java_library")
yoga_prebuilt_jar( prebuilt_jar(
name = "junit-jar", name = "junit-jar",
binary_jar = "junit4.jar", binary_jar = "junit4.jar",
) )
yoga_java_library( java_library(
name = "junit", name = "junit",
visibility = YOGA_ROOTS,
exported_deps = [ exported_deps = [
":junit-jar", ":junit-jar",
], ],
visibility = YOGA_ROOTS,
) )

View File

@@ -1,8 +1,7 @@
set -e
function download() { function download() {
echo "Downloading '$1' to '$2' ..."
if hash curl 2>/dev/null; then if hash curl 2>/dev/null; then
curl -s -L -o "$2" "$1" curl --retry 10 -L -o "$2" "$1"
elif hash wget 2>/dev/null; then elif hash wget 2>/dev/null; then
wget -O "$2" "$1" wget -O "$2" "$1"
else else
@@ -13,38 +12,38 @@ function download() {
function installsdk() { function installsdk() {
PROXY_ARGS="" PROXY_ARGS=""
if [[ ! -z "$HTTPS_PROXY" ]]; then if [[ ! -z "$https_proxy" ]]; then
PROXY_HOST="$(echo $HTTPS_PROXY | cut -d : -f 1,1)" PROXY_HOST="$(cut -d : "$https_proxy" -f 1,1)"
PROXY_PORT="$(echo $HTTPS_PROXY | cut -d : -f 2,2)" PROXY_PORT="$(cut -d : "$https_proxy" -f 2,2)"
PROXY_ARGS="--proxy=http --proxy_host=$PROXY_HOST --proxy_port=$PROXY_PORT" PROXY_ARGS="--proxy=http --proxy_host=$PROXY_HOST --proxy_port=$PROXY_PORT"
fi fi
echo y | "$ANDROID_HOME"/tools/bin/sdkmanager $PROXY_ARGS "$@" yes | "$ANDROID_HOME/tools/bin/sdkmanager" $PROXY_ARGS $@
} }
function installAndroidSDK { function installAndroidSDK {
if [[ ! -d "$HOME/android-sdk" ]]; then export ANDROID_HOME=$HOME/android-sdk
export ANDROID_NDK_REPOSITORY=$HOME/android-ndk
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH"
if [[ ! -f "$ANDROID_HOME/tools/bin/sdkmanager" ]]; then
TMP=/tmp/sdk$$.zip TMP=/tmp/sdk$$.zip
download 'https://dl.google.com/android/repository/tools_r25.2.3-linux.zip' $TMP download 'https://dl.google.com/android/repository/sdk-tools-darwin-3859397.zip' $TMP
unzip -qod "$HOME/android-sdk" $TMP unzip -qod "$ANDROID_HOME" "$TMP"
rm $TMP rm $TMP
fi fi
export ANDROID_NDK_REPOSITORY=$HOME/android-ndk
if [[ ! -d "$ANDROID_NDK_REPOSITORY/android-ndk-r15c" ]]; then if [[ ! -d "$ANDROID_NDK_REPOSITORY/android-ndk-r15c" ]]; then
TMP=/tmp/ndk$$.zip TMP=/tmp/ndk$$.zip
mkdir -p "$ANDROID_NDK_REPOSITORY" mkdir -p "$ANDROID_NDK_REPOSITORY"
download 'https://dl.google.com/android/repository/android-ndk-r15c-linux-x86_64.zip' $TMP download 'https://dl.google.com/android/repository/android-ndk-r15c-darwin-x86_64.zip' $TMP
unzip -qod "$ANDROID_NDK_REPOSITORY" "$TMP" unzip -qod "$ANDROID_NDK_REPOSITORY" "$TMP"
rm $TMP rm $TMP
fi fi
export ANDROID_HOME=$HOME/android-sdk mkdir -p "$ANDROID_HOME/licenses/"
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$PATH" echo > "$ANDROID_HOME/licenses/android-sdk-license"
echo -n d56f5187479451eabf01fb78af6dfcb131a6481e >> "$ANDROID_HOME/licenses/android-sdk-license"
mkdir -p $ANDROID_HOME/licenses/ installsdk 'build-tools;26.0.2' 'platform-tools' 'platforms;android-23' 'platforms;android-25' 'extras;android;m2repository'
echo > $ANDROID_HOME/licenses/android-sdk-license
echo -n d56f5187479451eabf01fb78af6dfcb131a6481e > $ANDROID_HOME/licenses/android-sdk-license
installsdk 'build-tools;25.0.3' 'build-tools;26.0.2' 'platforms;android-25' 'platforms;android-26' 'ndk-bundle' 'extras;android;m2repository'
} }

View File

@@ -98,3 +98,56 @@ TEST(YogaTest, wrap_grandchild) {
YGConfigFree(config); YGConfigFree(config);
} }
TEST(YogaTest, zero_size_with_child) {
const YGConfigRef config = YGConfigNew();
const YGNodeRef root = YGNodeNewWithConfig(config);
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0, 0);
YGNodeStyleSetHeight(root_child0, 0);
YGNodeInsertChild(root, root_child0, 0);
const YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0_child0, 100);
YGNodeStyleSetHeight(root_child0_child0, 100);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(-100, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -1,10 +1,10 @@
/* /**
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html // @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
#include <gtest/gtest.h> #include <gtest/gtest.h>
@@ -64,90 +64,6 @@ TEST(YogaTest, flex_basis_flex_grow_column) {
YGConfigFree(config); 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) { TEST(YogaTest, flex_basis_flex_grow_row) {
const YGConfigRef config = YGConfigNew(); const YGConfigRef config = YGConfigNew();

View File

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

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree. * 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 <gtest/gtest.h>
#include <yoga/Yoga.h> #include <yoga/Yoga.h>

View File

@@ -30,9 +30,9 @@ TEST(YogaTest, set_children_adds_children_to_parent) {
const std::vector<YGNodeRef> expectedChildren = {root_child0, root_child1}; const std::vector<YGNodeRef> expectedChildren = {root_child0, root_child1};
ASSERT_EQ(children, expectedChildren); ASSERT_EQ(children, expectedChildren);
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
const std::vector<YGNodeRef> expectedOwners = {root, root}; const std::vector<YGNodeRef> expectedParents = {root, root};
ASSERT_EQ(owners, expectedOwners); ASSERT_EQ(parents, expectedParents);
YGNodeFreeRecursive(root); YGNodeFreeRecursive(root);
} }
@@ -49,9 +49,9 @@ TEST(YogaTest, set_children_to_empty_removes_old_children) {
const std::vector<YGNodeRef> expectedChildren = {}; const std::vector<YGNodeRef> expectedChildren = {};
ASSERT_EQ(children, expectedChildren); ASSERT_EQ(children, expectedChildren);
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
const std::vector<YGNodeRef> expectedOwners = {nullptr, nullptr}; const std::vector<YGNodeRef> expectedParents = {nullptr, nullptr};
ASSERT_EQ(owners, expectedOwners); ASSERT_EQ(parents, expectedParents);
YGNodeFreeRecursive(root); YGNodeFreeRecursive(root);
} }
@@ -72,9 +72,9 @@ TEST(YogaTest, set_children_replaces_non_common_children) {
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child3}; const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child3};
ASSERT_EQ(children, expectedChildren); ASSERT_EQ(children, expectedChildren);
const std::vector<YGNodeRef> owners = {YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector<YGNodeRef> parents = {YGNodeGetParent(root_child0), YGNodeGetParent(root_child1)};
const std::vector<YGNodeRef> expectedOwners = {nullptr, nullptr}; const std::vector<YGNodeRef> expectedParents = {nullptr, nullptr};
ASSERT_EQ(owners, expectedOwners); ASSERT_EQ(parents, expectedParents);
YGNodeFreeRecursive(root); YGNodeFreeRecursive(root);
YGNodeFree(root_child0); YGNodeFree(root_child0);
@@ -97,14 +97,14 @@ TEST(YogaTest, set_children_keeps_and_reorders_common_children) {
const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child1, root_child3}; const std::vector<YGNodeRef> expectedChildren = {root_child2, root_child1, root_child3};
ASSERT_EQ(children, expectedChildren); ASSERT_EQ(children, expectedChildren);
const std::vector<YGNodeRef> owners = { const std::vector<YGNodeRef> parents = {
YGNodeGetOwner(root_child0), YGNodeGetParent(root_child0),
YGNodeGetOwner(root_child1), YGNodeGetParent(root_child1),
YGNodeGetOwner(root_child2), YGNodeGetParent(root_child2),
YGNodeGetOwner(root_child3) YGNodeGetParent(root_child3)
}; };
const std::vector<YGNodeRef> expectedOwners = {nullptr, root, root, root}; const std::vector<YGNodeRef> expectedParents = {nullptr, root, root, root};
ASSERT_EQ(owners, expectedOwners); ASSERT_EQ(parents, expectedParents);
YGNodeFreeRecursive(root); YGNodeFreeRecursive(root);
YGNodeFree(root_child0); YGNodeFree(root_child0);

12381
website/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,22 +4,21 @@
"version": "1.0.0", "version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>", "author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": { "dependencies": {
"antd": "^3.6.5", "antd": "^3.2.0",
"atob": "^2.1.1", "atob": "^2.0.3",
"btoa": "^1.2.1", "gatsby": "^1.9.158",
"gatsby": "^1.9.273", "gatsby-link": "^1.6.34",
"gatsby-link": "^1.6.45", "gatsby-plugin-antd": "^1.0.10",
"gatsby-plugin-antd": "^1.0.12", "gatsby-plugin-google-analytics": "^1.0.19",
"gatsby-plugin-google-analytics": "^1.0.31", "gatsby-plugin-less": "^1.1.4",
"gatsby-plugin-less": "^1.1.8", "gatsby-plugin-react-helmet": "^2.0.3",
"gatsby-plugin-react-helmet": "^2.0.11", "gatsby-plugin-react-next": "^1.0.8",
"gatsby-plugin-react-next": "^1.0.11", "gatsby-remark-prismjs": "^1.2.14",
"gatsby-remark-prismjs": "^2.0.4", "gatsby-source-filesystem": "^1.5.18",
"gatsby-source-filesystem": "^1.5.39", "gatsby-transformer-remark": "^1.7.31",
"gatsby-transformer-remark": "^1.7.44",
"immutable": "^4.0.0-rc.9", "immutable": "^4.0.0-rc.9",
"react-helmet": "^5.2.0", "react-helmet": "^5.2.0",
"react-syntax-highlighter": "^8.0.0", "react-syntax-highlighter": "^7.0.0",
"yoga-layout": "^1.9.3" "yoga-layout": "^1.9.3"
}, },
"keywords": [ "keywords": [
@@ -32,6 +31,6 @@
"develop": "gatsby develop" "develop": "gatsby develop"
}, },
"devDependencies": { "devDependencies": {
"prettier": "1.13.7" "prettier": "^1.10.2"
} }
} }

View File

@@ -10,12 +10,10 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
export default () => ( export default () => <svg viewBox="0 0 1133.9 1133.9">
<svg viewBox="0 0 1133.9 1133.9">
<g> <g>
<path d="M 498.3 3.7 c 153.6 88.9 307.3 177.7 461.1 266.2 c 7.6 4.4 10.3 9.1 10.3 17.8 c -0.3 179.1 -0.2 358.3 0 537.4 c 0 8.1 -2.4 12.8 -9.7 17.1 c -154.5 88.9 -308.8 178.1 -462.9 267.5 c -9 5.2 -15.5 5.3 -24.6 0.1 c -153.9 -89.2 -307.9 -178 -462.1 -266.8 C 3 838.8 0 833.9 0 825.1 c 0.3 -179.1 0.2 -358.3 0 -537.4 c 0 -8.6 2.6 -13.6 10.2 -18 C 164.4 180.9 318.4 92 472.4 3 C 477 -1.5 494.3 -0.7 498.3 3.7 Z M 48.8 555.3 c 0 79.9 0.2 159.9 -0.2 239.8 c -0.1 10 3 15.6 11.7 20.6 c 137.2 78.8 274.2 157.8 411 237.3 c 9.9 5.7 17 5.7 26.8 0.1 c 137.5 -79.8 275.2 -159.2 412.9 -238.5 c 7.4 -4.3 10.5 -8.9 10.5 -17.8 c -0.3 -160.2 -0.3 -320.5 0 -480.7 c 0 -8.8 -2.8 -13.6 -10.3 -18 C 772.1 218 633.1 137.8 494.2 57.4 c -6.5 -3.8 -11.5 -4.5 -18.5 -0.5 C 336.8 137.4 197.9 217.7 58.8 297.7 c -7.7 4.4 -10.2 9.2 -10.2 17.9 C 48.9 395.5 48.8 475.4 48.8 555.3 Z" /> <path d="M 498.3 3.7 c 153.6 88.9 307.3 177.7 461.1 266.2 c 7.6 4.4 10.3 9.1 10.3 17.8 c -0.3 179.1 -0.2 358.3 0 537.4 c 0 8.1 -2.4 12.8 -9.7 17.1 c -154.5 88.9 -308.8 178.1 -462.9 267.5 c -9 5.2 -15.5 5.3 -24.6 0.1 c -153.9 -89.2 -307.9 -178 -462.1 -266.8 C 3 838.8 0 833.9 0 825.1 c 0.3 -179.1 0.2 -358.3 0 -537.4 c 0 -8.6 2.6 -13.6 10.2 -18 C 164.4 180.9 318.4 92 472.4 3 C 477 -1.5 494.3 -0.7 498.3 3.7 Z M 48.8 555.3 c 0 79.9 0.2 159.9 -0.2 239.8 c -0.1 10 3 15.6 11.7 20.6 c 137.2 78.8 274.2 157.8 411 237.3 c 9.9 5.7 17 5.7 26.8 0.1 c 137.5 -79.8 275.2 -159.2 412.9 -238.5 c 7.4 -4.3 10.5 -8.9 10.5 -17.8 c -0.3 -160.2 -0.3 -320.5 0 -480.7 c 0 -8.8 -2.8 -13.6 -10.3 -18 C 772.1 218 633.1 137.8 494.2 57.4 c -6.5 -3.8 -11.5 -4.5 -18.5 -0.5 C 336.8 137.4 197.9 217.7 58.8 297.7 c -7.7 4.4 -10.2 9.2 -10.2 17.9 C 48.9 395.5 48.8 475.4 48.8 555.3 Z" />
<path d="M 184.4 555.9 c 0 -33.3 -1 -66.7 0.3 -100 c 1.9 -48 24.1 -86 64.7 -110.9 c 54.8 -33.6 110.7 -65.5 167 -96.6 c 45.7 -25.2 92.9 -24.7 138.6 1 c 54.4 30.6 108.7 61.5 162.2 93.7 c 44 26.5 67.3 66.8 68 118.4 c 0.9 63.2 0.9 126.5 0 189.7 c -0.7 50.6 -23.4 90.7 -66.6 116.9 c -55 33.4 -110.8 65.4 -167.1 96.5 c -43.4 24 -89 24.2 -132.3 0.5 c -57.5 -31.3 -114.2 -64 -170 -98.3 c -41 -25.1 -62.9 -63.7 -64.5 -112.2 C 183.5 621.9 184.3 588.9 184.4 555.9 Z M 232.9 556.3 c 0 29.5 0.5 59.1 -0.1 88.6 c -0.8 39.2 16.9 67.1 50.2 86.2 c 51.2 29.4 102.2 59.2 153.4 88.4 c 31.4 17.9 63.6 18.3 95 0.6 c 53.7 -30.3 107.1 -61.2 160.3 -92.5 c 29.7 -17.5 45 -44.5 45.3 -78.8 c 0.6 -61.7 0.5 -123.5 0 -185.2 c -0.3 -34.4 -15.3 -61.5 -44.9 -79 C 637.7 352.6 583 320.8 527.9 290 c -27.5 -15.4 -57.2 -16.1 -84.7 -0.7 c -56.9 31.6 -113.4 64 -169.1 97.6 c -26.4 15.9 -40.7 41.3 -41.1 72.9 C 232.6 491.9 232.9 524.1 232.9 556.3 Z" /> <path d="M 184.4 555.9 c 0 -33.3 -1 -66.7 0.3 -100 c 1.9 -48 24.1 -86 64.7 -110.9 c 54.8 -33.6 110.7 -65.5 167 -96.6 c 45.7 -25.2 92.9 -24.7 138.6 1 c 54.4 30.6 108.7 61.5 162.2 93.7 c 44 26.5 67.3 66.8 68 118.4 c 0.9 63.2 0.9 126.5 0 189.7 c -0.7 50.6 -23.4 90.7 -66.6 116.9 c -55 33.4 -110.8 65.4 -167.1 96.5 c -43.4 24 -89 24.2 -132.3 0.5 c -57.5 -31.3 -114.2 -64 -170 -98.3 c -41 -25.1 -62.9 -63.7 -64.5 -112.2 C 183.5 621.9 184.3 588.9 184.4 555.9 Z M 232.9 556.3 c 0 29.5 0.5 59.1 -0.1 88.6 c -0.8 39.2 16.9 67.1 50.2 86.2 c 51.2 29.4 102.2 59.2 153.4 88.4 c 31.4 17.9 63.6 18.3 95 0.6 c 53.7 -30.3 107.1 -61.2 160.3 -92.5 c 29.7 -17.5 45 -44.5 45.3 -78.8 c 0.6 -61.7 0.5 -123.5 0 -185.2 c -0.3 -34.4 -15.3 -61.5 -44.9 -79 C 637.7 352.6 583 320.8 527.9 290 c -27.5 -15.4 -57.2 -16.1 -84.7 -0.7 c -56.9 31.6 -113.4 64 -169.1 97.6 c -26.4 15.9 -40.7 41.3 -41.1 72.9 C 232.6 491.9 232.9 524.1 232.9 556.3 Z" />
<path d="M 484.9 424.4 c 69.8 -2.8 133.2 57.8 132.6 132 C 617 630 558.5 688.7 484.9 689.1 c -75.1 0.4 -132.6 -63.6 -132.7 -132.7 C 352.1 485 413.4 421.5 484.9 424.4 Z M 401.3 556.7 c -3.4 37.2 30.5 83.6 83 84.1 c 46.6 0.4 84.8 -37.6 84.9 -84 c 0.1 -46.6 -37.2 -84.4 -84.2 -84.6 C 432.2 472.1 397.9 518.3 401.3 556.7 Z" /> <path d="M 484.9 424.4 c 69.8 -2.8 133.2 57.8 132.6 132 C 617 630 558.5 688.7 484.9 689.1 c -75.1 0.4 -132.6 -63.6 -132.7 -132.7 C 352.1 485 413.4 421.5 484.9 424.4 Z M 401.3 556.7 c -3.4 37.2 30.5 83.6 83 84.1 c 46.6 0.4 84.8 -37.6 84.9 -84 c 0.1 -46.6 -37.2 -84.4 -84.2 -84.6 C 432.2 472.1 397.9 518.3 401.3 556.7 Z" />
</g> </g>
</svg> </svg>
);

View File

@@ -137,9 +137,9 @@ function getLayoutCode(
)}\n${indent}\t},`, )}\n${indent}\t},`,
), ),
); );
lines.push(indent + `}]${isRoot ? ';' : ','}`); lines.push(indent + `}]${isRoot ? ';' : ''}`);
} else { } else {
lines[lines.length - 1] += '],'; lines[lines.length - 1] += ']';
CKFlexboxComponentChild.forEach(key => { CKFlexboxComponentChild.forEach(key => {
let line = renderKey(node, key, indent); let line = renderKey(node, key, indent);
if (line) { if (line) {
@@ -165,7 +165,7 @@ function renderKey(node: Yoga$Node, key: string, indent: string): ?string {
); );
} }
['top', 'start', 'end', 'bottom'].forEach(pKey => { ['top', 'left', 'right', 'bottom'].forEach(pKey => {
if (node[key][pKey]) { if (node[key][pKey]) {
lines.push(indent + `\t.${pKey} = ${getValue(node[key][pKey])},`); lines.push(indent + `\t.${pKey} = ${getValue(node[key][pKey])},`);
} }

View File

@@ -46,9 +46,7 @@ function dipOrPercent(value) {
console.log(value); console.log(value);
return value === 'auto' return value === 'auto'
? 'Auto' ? 'Auto'
: typeof value === 'string' && /%$/.test(value) : typeof value === 'string' && /%$/.test(value) ? 'Percent' : 'Dip';
? 'Percent'
: 'Dip';
} }
function getValue(value) { function getValue(value) {

View File

@@ -33,7 +33,7 @@ export default (props: Props<*>) => {
type="text" type="text"
{...props} {...props}
onChange={e => props.onChange(props.property, e.target.value)} onChange={e => props.onChange(props.property, e.target.value)}
placeholder={props.placeholder || 'undefined'} placeholder="undefined"
onFocus={e => e.target.select()} onFocus={e => e.target.select()}
value={Number.isNaN(props.value) ? '' : props.value} value={Number.isNaN(props.value) ? '' : props.value}
/> />

View File

@@ -89,7 +89,6 @@ export default class Editor extends Component<Props> {
<EditValue <EditValue
type="text" type="text"
property="flexBasis" property="flexBasis"
placeholder="auto"
disabled={disabled || selectedNodeIsRoot} disabled={disabled || selectedNodeIsRoot}
value={node ? node.flexBasis : undefined} value={node ? node.flexBasis : undefined}
onChange={this.props.onChangeLayout} onChange={this.props.onChangeLayout}
@@ -105,7 +104,6 @@ export default class Editor extends Component<Props> {
<EditValue <EditValue
type="text" type="text"
property="flexGrow" property="flexGrow"
placeholder="0"
disabled={disabled || selectedNodeIsRoot} disabled={disabled || selectedNodeIsRoot}
value={node ? node.flexGrow : undefined} value={node ? node.flexGrow : undefined}
onChange={this.props.onChangeLayout} onChange={this.props.onChangeLayout}
@@ -122,7 +120,6 @@ export default class Editor extends Component<Props> {
<EditValue <EditValue
type="text" type="text"
property="flexShrink" property="flexShrink"
placeholder="1"
disabled={disabled || selectedNodeIsRoot} disabled={disabled || selectedNodeIsRoot}
value={node ? node.flexShrink : undefined} value={node ? node.flexShrink : undefined}
onChange={this.props.onChangeLayout} onChange={this.props.onChangeLayout}
@@ -225,62 +222,6 @@ export default class Editor extends Component<Props> {
/> />
</Col> </Col>
</Row> </Row>
<h2>
Max-Width &times; Max-Height
<InfoText doclink="/docs/min-max">
Maximum dimensions of the node
</InfoText>
</h2>
<Row gutter={15}>
<Col span={12}>
<EditValue
type="text"
placeholder="none"
property="maxWidth"
disabled={disabled}
value={node ? node.maxWidth : undefined}
onChange={this.props.onChangeLayout}
/>
</Col>
<Col span={12}>
<EditValue
type="text"
placeholder="none"
property="maxHeight"
disabled={disabled}
value={node ? node.maxHeight : undefined}
onChange={this.props.onChangeLayout}
/>
</Col>
</Row>
<h2>
Min-Width &times; Min-Height
<InfoText doclink="/docs/min-max">
Minimum dimensions of the node
</InfoText>
</h2>
<Row gutter={15}>
<Col span={12}>
<EditValue
type="text"
placeholder="0"
property="minWidth"
disabled={disabled}
value={node ? node.minWidth : undefined}
onChange={this.props.onChangeLayout}
/>
</Col>
<Col span={12}>
<EditValue
type="text"
placeholder="0"
property="minHeight"
disabled={disabled}
value={node ? node.minHeight : undefined}
onChange={this.props.onChangeLayout}
/>
</Col>
</Row>
<h2> <h2>
Aspect Ratio Aspect Ratio

View File

@@ -19,22 +19,18 @@ import type {
Yoga$JustifyContent, Yoga$JustifyContent,
Yoga$FlexDirection, Yoga$FlexDirection,
Yoga$FlexWrap, Yoga$FlexWrap,
Yoga$PositionType, Yoga$YogaPositionType,
} from 'yoga-layout'; } from 'yoga-layout';
export type LayoutRecordT = RecordOf<{ export type LayoutRecordT = RecordOf<{
width?: ?number, width?: ?number,
height?: ?number, height?: ?number,
minWidth?: ?number,
minHeight?: ?number,
maxWidth?: ?number,
maxHeight?: ?number,
justifyContent?: Yoga$JustifyContent, justifyContent?: Yoga$JustifyContent,
padding: PositionRecordT, padding: PositionRecordT,
border: PositionRecordT, border: PositionRecordT,
margin: PositionRecordT, margin: PositionRecordT,
position: PositionRecordT, position: PositionRecordT,
positionType: Yoga$PositionType, positionType: Yoga$YogaPositionType,
alignItems?: Yoga$Align, alignItems?: Yoga$Align,
alignSelf?: Yoga$Align, alignSelf?: Yoga$Align,
alignContent?: Yoga$Align, alignContent?: Yoga$Align,
@@ -55,10 +51,6 @@ export type LayoutRecordT = RecordOf<{
const r: LayoutRecordT = Record({ const r: LayoutRecordT = Record({
width: 'auto', width: 'auto',
height: 'auto', height: 'auto',
minWidth: 0,
minHeight: 0,
maxWidth: 'none',
maxHeight: 'none',
justifyContent: yoga.JUSTIFY_FLEX_START, justifyContent: yoga.JUSTIFY_FLEX_START,
alignItems: yoga.ALIGN_STRETCH, alignItems: yoga.ALIGN_STRETCH,
alignSelf: yoga.ALIGN_AUTO, alignSelf: yoga.ALIGN_AUTO,

View File

@@ -49,7 +49,7 @@ export default class URLShortener extends Component<{}, State> {
window.ga('send', { window.ga('send', {
hitType: 'event', hitType: 'event',
eventCategory: 'URLShortener', eventCategory: 'URLShortener',
eventAction: 'created', eventAction: 'created'
}); });
} }

View File

@@ -18,8 +18,7 @@ import {List, setIn} from 'immutable';
import PositionRecord from './PositionRecord'; import PositionRecord from './PositionRecord';
import LayoutRecord from './LayoutRecord'; import LayoutRecord from './LayoutRecord';
import Sidebar from './Sidebar'; import Sidebar from './Sidebar';
import {Row, Col, Button} from 'antd'; import {Row, Col} from 'antd';
import btoa from 'btoa';
import type {LayoutRecordT} from './LayoutRecord'; import type {LayoutRecordT} from './LayoutRecord';
import type {Yoga$Direction} from 'yoga-layout'; import type {Yoga$Direction} from 'yoga-layout';
import './index.css'; import './index.css';
@@ -165,15 +164,12 @@ export default class Playground extends Component<Props, State> {
}); });
if (this.props.persist) { if (this.props.persist) {
window.location.hash = this.getHash(layoutDefinition); window.location.hash = btoa(
JSON.stringify(this.removeUnchangedProperties(layoutDefinition)),
);
} }
} }
getHash = (
layoutDefinition: LayoutRecordT = this.state.layoutDefinition,
): string =>
btoa(JSON.stringify(this.removeUnchangedProperties(layoutDefinition)));
removeUnchangedProperties = (node: LayoutRecordT): Object => { removeUnchangedProperties = (node: LayoutRecordT): Object => {
const untouchedLayout = LayoutRecord({}); const untouchedLayout = LayoutRecord({});
const untouchedPosition = PositionRecord({}); const untouchedPosition = PositionRecord({});
@@ -247,15 +243,7 @@ export default class Playground extends Component<Props, State> {
/> />
</Col> </Col>
<Col span={12}> <Col span={12}>
{this.props.persist ? (
<URLShortener /> <URLShortener />
) : (
<Button
href={`/playground#${this.getHash()}`}
type="primary">
Open Playground
</Button>
)}
</Col> </Col>
</Row> </Row>
</div> </div>

View File

@@ -34,7 +34,7 @@ export default ({data}) => (
comes with an interactive playground for you to explore that comes with an interactive playground for you to explore that
feature. The examples section showcases some of the most common feature. The examples section showcases some of the most common
layouts and how to build them. This is a community projects and layouts and how to build them. This is a community projects and
contributions within documentation, code, and tests are more than contributions within documentation, code, and tests are more then
welcome. The contributing section below covers how to get started. welcome. The contributing section below covers how to get started.
</p> </p>
</Col> </Col>

View File

@@ -183,7 +183,6 @@ const AboutSectionTwo = () => (
); );
export default () => ( export default () => (
<div>
<Page className="landing-page" title="A cross-platform layout engine"> <Page className="landing-page" title="A cross-platform layout engine">
<HeroSection /> <HeroSection />
<PlaygroundSection /> <PlaygroundSection />
@@ -192,5 +191,4 @@ export default () => (
<AboutSectionTwo /> <AboutSectionTwo />
<Footer /> <Footer />
</Page> </Page>
</div>
); );

View File

@@ -3,13 +3,11 @@
flex: 1; flex: 1;
} }
@media (max-width: 991px) { .playground-page .error-container {
.playground-page .error-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
}
} }
.playground-page .error-text { .playground-page .error-text {

File diff suppressed because it is too large Load Diff

View File

@@ -58,11 +58,8 @@ float YGUnwrapFloatOptional(const YGFloatOptional& op) {
return op.isUndefined() ? YGUndefined : op.getValue(); return op.isUndefined() ? YGUndefined : op.getValue();
} }
YGFloatOptional YGFloatOptionalMax( bool YGFloatOptionalFloatEquals(
const YGFloatOptional& op1, const YGFloatOptional& optional,
const YGFloatOptional& op2) { const float& val) {
if (!op1.isUndefined() && !op2.isUndefined()) { return YGUnwrapFloatOptional(optional) == val;
return op1.getValue() > op2.getValue() ? op1 : op2;
}
return op1.isUndefined() ? op2 : op1;
} }

View File

@@ -40,12 +40,12 @@ struct YGCollectFlexItemsRowValues {
float sizeConsumedOnCurrentLine; float sizeConsumedOnCurrentLine;
float totalFlexGrowFactors; float totalFlexGrowFactors;
float totalFlexShrinkScaledFactors; float totalFlexShrinkScaledFactors;
uint32_t endOfLineIndex; float endOfLineIndex;
std::vector<YGNodeRef> relativeChildren; std::vector<YGNodeRef> relativeChildren;
float remainingFreeSpace; float remainingFreeSpace;
// The size of the mainDim for the row after considering size, padding, margin // The size of the mainDim for the row after considering size, padding, margin
// and border of flex items. This is used to calculate maxLineDim after going // and border of flex items. This is used to calculate maxLineDim after going
// through all the rows to decide on the main axis size of owner. // through all the rows to decide on the main axis size of parent.
float mainDim; float mainDim;
// The size of the crossDim for the row after considering size, padding, // The size of the crossDim for the row after considering size, padding,
// margin and border of flex items. Used for calculating containers crossSize. // margin and border of flex items. Used for calculating containers crossSize.
@@ -65,10 +65,6 @@ bool YGFloatsEqual(const float a, const float b);
// compiler flag. // compiler flag.
float YGFloatMax(const float a, const float b); float YGFloatMax(const float a, const float b);
YGFloatOptional YGFloatOptionalMax(
const YGFloatOptional& op1,
const YGFloatOptional& op2);
// We need custom min function, since we want that, if one argument is // We need custom min function, since we want that, if one argument is
// YGUndefined then the min funtion should return the other argument as the min // YGUndefined then the min funtion should return the other argument as the min
// value. We wouldn't have needed a custom min function if YGUndefined was NAN // value. We wouldn't have needed a custom min function if YGUndefined was NAN
@@ -98,6 +94,12 @@ float YGFloatSanitize(const float& val);
// TODO: Get rid off this function // TODO: Get rid off this function
float YGUnwrapFloatOptional(const YGFloatOptional& op); float YGUnwrapFloatOptional(const YGFloatOptional& op);
// This function returns true if val and optional both are undefined or if val
// and optional.val is true, otherwise its false.
bool YGFloatOptionalFloatEquals(
const YGFloatOptional& optional,
const float& val);
YGFlexDirection YGFlexDirectionCross( YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection, const YGFlexDirection flexDirection,
const YGDirection direction); const YGDirection direction);
@@ -107,7 +109,7 @@ inline bool YGFlexDirectionIsRow(const YGFlexDirection flexDirection) {
flexDirection == YGFlexDirectionRowReverse; flexDirection == YGFlexDirectionRowReverse;
} }
inline YGFloatOptional YGResolveValue(const YGValue value, const float ownerSize) { inline YGFloatOptional YGResolveValue(const YGValue value, const float parentSize) {
switch (value.unit) { switch (value.unit) {
case YGUnitUndefined: case YGUnitUndefined:
case YGUnitAuto: case YGUnitAuto:
@@ -116,7 +118,7 @@ inline YGFloatOptional YGResolveValue(const YGValue value, const float ownerSize
return YGFloatOptional(value.value); return YGFloatOptional(value.value);
case YGUnitPercent: case YGUnitPercent:
return YGFloatOptional( return YGFloatOptional(
static_cast<float>(value.value * ownerSize * 0.01)); static_cast<float>(value.value * parentSize * 0.01));
} }
return YGFloatOptional(); return YGFloatOptional();
} }
@@ -140,9 +142,8 @@ inline YGFlexDirection YGResolveFlexDirection(
return flexDirection; return flexDirection;
} }
static inline YGFloatOptional YGResolveValueMargin( static inline float YGResolveValueMargin(
const YGValue value, const YGValue value,
const float ownerSize) { const float parentSize) {
return value.unit == YGUnitAuto ? YGFloatOptional(0) return value.unit == YGUnitAuto ? 0 : YGUnwrapFloatOptional(YGResolveValue(value, parentSize));
: YGResolveValue(value, ownerSize);
} }

View File

@@ -1,19 +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.
*/
#include "YGConfig.h"
const std::array<bool, YGExperimentalFeatureCount>
kYGDefaultExperimentalFeatures = {{false}};
YGConfig::YGConfig(YGLogger logger)
: experimentalFeatures(kYGDefaultExperimentalFeatures),
useWebDefaults(false),
useLegacyStretchBehaviour(false),
shouldDiffLayoutWithoutLegacyStretchBehaviour(false),
pointScaleFactor(1.0f), logger(logger), cloneNodeCallback(nullptr),
context(nullptr) {}

View File

@@ -1,23 +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 "Yoga-internal.h"
#include "Yoga.h"
struct YGConfig {
std::array<bool, YGExperimentalFeatureCount> experimentalFeatures;
bool useWebDefaults;
bool useLegacyStretchBehaviour;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
float pointScaleFactor;
YGLogger logger;
YGCloneNodeFunc cloneNodeCallback;
void* context;
YGConfig(YGLogger logger);
};

View File

@@ -1,28 +1,19 @@
/* /**
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* *
* This source code is licensed under the MIT license found in the LICENSE * This source code is licensed under the MIT license found in the
* file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*
*/ */
#include "YGFloatOptional.h" #include "YGFloatOptional.h"
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include "Yoga.h"
YGFloatOptional::YGFloatOptional(float value) {
if (YGFloatIsUndefined(value)) {
isUndefined_ = true;
value_ = 0;
} else {
value_ = value;
isUndefined_ = false;
}
}
YGFloatOptional::YGFloatOptional(const float& value)
: value_(value), isUndefined_(false) {}
YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {} YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
const float& YGFloatOptional::getValue() const { float YGFloatOptional::getValue() const {
if (isUndefined_) { if (isUndefined_) {
// Abort, accessing a value of an undefined float optional // Abort, accessing a value of an undefined float optional
std::cerr << "Tried to get value of an undefined YGFloatOptional\n"; std::cerr << "Tried to get value of an undefined YGFloatOptional\n";
@@ -31,53 +22,11 @@ const float& YGFloatOptional::getValue() const {
return value_; return value_;
} }
bool YGFloatOptional::operator==(const YGFloatOptional& op) const { void YGFloatOptional::setValue(const float& val) {
if (isUndefined_ == op.isUndefined()) { value_ = val;
return isUndefined_ || value_ == op.getValue(); isUndefined_ = false;
}
return false;
} }
bool YGFloatOptional::operator!=(const YGFloatOptional& op) const { bool YGFloatOptional::isUndefined() const {
return !(*this == op); return isUndefined_;
}
bool YGFloatOptional::operator==(float val) const {
if (YGFloatIsUndefined(val) == isUndefined_) {
return isUndefined_ || val == value_;
}
return false;
}
bool YGFloatOptional::operator!=(float val) const {
return !(*this == val);
}
YGFloatOptional YGFloatOptional::operator+(const YGFloatOptional& op) {
if (!isUndefined_ && !op.isUndefined_) {
return YGFloatOptional(value_ + op.value_);
}
return YGFloatOptional();
}
bool YGFloatOptional::operator>(const YGFloatOptional& op) const {
if (isUndefined_ || op.isUndefined_) {
return false;
}
return value_ > op.value_;
}
bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
if (isUndefined_ || op.isUndefined_) {
return false;
}
return value_ < op.value_;
}
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
return *this == op || *this > op;
}
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
return *this == op || *this < op;
} }

View File

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

View File

@@ -19,10 +19,10 @@ YGLayout::YGLayout()
padding(), padding(),
direction(YGDirectionInherit), direction(YGDirectionInherit),
computedFlexBasisGeneration(0), computedFlexBasisGeneration(0),
computedFlexBasis(YGFloatOptional()), computedFlexBasis(YGUndefined),
hadOverflow(false), hadOverflow(false),
generationCount(0), generationCount(0),
lastOwnerDirection((YGDirection)-1), lastParentDirection((YGDirection)-1),
nextCachedMeasurementsIndex(0), nextCachedMeasurementsIndex(0),
cachedMeasurements(), cachedMeasurements(),
measuredDimensions(kYGDefaultDimensionValues), measuredDimensions(kYGDefaultDimensionValues),
@@ -37,15 +37,18 @@ bool YGLayout::operator==(YGLayout layout) const {
YGFloatArrayEqual(border, layout.border) && YGFloatArrayEqual(border, layout.border) &&
YGFloatArrayEqual(padding, layout.padding) && YGFloatArrayEqual(padding, layout.padding) &&
direction == layout.direction && hadOverflow == layout.hadOverflow && direction == layout.direction && hadOverflow == layout.hadOverflow &&
lastOwnerDirection == layout.lastOwnerDirection && lastParentDirection == layout.lastParentDirection &&
nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex && nextCachedMeasurementsIndex == layout.nextCachedMeasurementsIndex &&
cachedLayout == layout.cachedLayout && cachedLayout == layout.cachedLayout;
computedFlexBasis == layout.computedFlexBasis;
for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) { for (uint32_t i = 0; i < YG_MAX_CACHED_RESULT_COUNT && isEqual; ++i) {
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i]; isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
} }
if (!YGFloatIsUndefined(computedFlexBasis) ||
!YGFloatIsUndefined(layout.computedFlexBasis)) {
isEqual = isEqual && (computedFlexBasis == layout.computedFlexBasis);
}
if (!YGFloatIsUndefined(measuredDimensions[0]) || if (!YGFloatIsUndefined(measuredDimensions[0]) ||
!YGFloatIsUndefined(layout.measuredDimensions[0])) { !YGFloatIsUndefined(layout.measuredDimensions[0])) {
isEqual = isEqual =

View File

@@ -6,7 +6,6 @@
*/ */
#pragma once #pragma once
#include "YGFloatOptional.h"
#include "Yoga-internal.h" #include "Yoga-internal.h"
struct YGLayout { struct YGLayout {
@@ -18,13 +17,13 @@ struct YGLayout {
YGDirection direction; YGDirection direction;
uint32_t computedFlexBasisGeneration; uint32_t computedFlexBasisGeneration;
YGFloatOptional computedFlexBasis; float computedFlexBasis;
bool hadOverflow; bool hadOverflow;
// Instead of recomputing the entire layout every single time, we // Instead of recomputing the entire layout every single time, we
// cache some information to break early when nothing changed // cache some information to break early when nothing changed
uint32_t generationCount; uint32_t generationCount;
YGDirection lastOwnerDirection; YGDirection lastParentDirection;
uint32_t nextCachedMeasurementsIndex; uint32_t nextCachedMeasurementsIndex;
std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT> std::array<YGCachedMeasurement, YG_MAX_CACHED_RESULT_COUNT>

View File

@@ -9,14 +9,90 @@
#include <iostream> #include <iostream>
#include "Utils.h" #include "Utils.h"
YGFloatOptional YGNode::getLeadingPosition( void* YGNode::getContext() const {
const YGFlexDirection& axis, return context_;
const float& axisSize) const { }
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::getParent() const {
return parent_;
}
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_;
}
float YGNode::getLeadingPosition(
const YGFlexDirection axis,
const float axisSize) const {
if (YGFlexDirectionIsRow(axis)) { if (YGFlexDirectionIsRow(axis)) {
const YGValue* leadingPosition = const YGValue* leadingPosition =
YGComputedEdgeValue(style_.position, YGEdgeStart, &YGValueUndefined); YGComputedEdgeValue(style_.position, YGEdgeStart, &YGValueUndefined);
if (leadingPosition->unit != YGUnitUndefined) { if (leadingPosition->unit != YGUnitUndefined) {
return YGResolveValue(*leadingPosition, axisSize); return YGUnwrapFloatOptional(YGResolveValue(*leadingPosition, axisSize));
} }
} }
@@ -24,18 +100,18 @@ YGFloatOptional YGNode::getLeadingPosition(
YGComputedEdgeValue(style_.position, leading[axis], &YGValueUndefined); YGComputedEdgeValue(style_.position, leading[axis], &YGValueUndefined);
return leadingPosition->unit == YGUnitUndefined return leadingPosition->unit == YGUnitUndefined
? YGFloatOptional(0) ? 0.0f
: YGResolveValue(*leadingPosition, axisSize); : YGUnwrapFloatOptional(YGResolveValue(*leadingPosition, axisSize));
} }
YGFloatOptional YGNode::getTrailingPosition( float YGNode::getTrailingPosition(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& axisSize) const { const float axisSize) const {
if (YGFlexDirectionIsRow(axis)) { if (YGFlexDirectionIsRow(axis)) {
const YGValue* trailingPosition = const YGValue* trailingPosition =
YGComputedEdgeValue(style_.position, YGEdgeEnd, &YGValueUndefined); YGComputedEdgeValue(style_.position, YGEdgeEnd, &YGValueUndefined);
if (trailingPosition->unit != YGUnitUndefined) { if (trailingPosition->unit != YGUnitUndefined) {
return YGResolveValue(*trailingPosition, axisSize); return YGUnwrapFloatOptional(YGResolveValue(*trailingPosition, axisSize));
} }
} }
@@ -43,11 +119,11 @@ YGFloatOptional YGNode::getTrailingPosition(
YGComputedEdgeValue(style_.position, trailing[axis], &YGValueUndefined); YGComputedEdgeValue(style_.position, trailing[axis], &YGValueUndefined);
return trailingPosition->unit == YGUnitUndefined return trailingPosition->unit == YGUnitUndefined
? YGFloatOptional(0) ? 0.0f
: YGResolveValue(*trailingPosition, axisSize); : YGUnwrapFloatOptional(YGResolveValue(*trailingPosition, axisSize));
} }
bool YGNode::isLeadingPositionDefined(const YGFlexDirection& axis) const { bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const {
return (YGFlexDirectionIsRow(axis) && return (YGFlexDirectionIsRow(axis) &&
YGComputedEdgeValue(style_.position, YGEdgeStart, &YGValueUndefined) YGComputedEdgeValue(style_.position, YGEdgeStart, &YGValueUndefined)
->unit != YGUnitUndefined) || ->unit != YGUnitUndefined) ||
@@ -55,7 +131,7 @@ bool YGNode::isLeadingPositionDefined(const YGFlexDirection& axis) const {
->unit != YGUnitUndefined; ->unit != YGUnitUndefined;
} }
bool YGNode::isTrailingPosDefined(const YGFlexDirection& axis) const { bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const {
return (YGFlexDirectionIsRow(axis) && return (YGFlexDirectionIsRow(axis) &&
YGComputedEdgeValue(style_.position, YGEdgeEnd, &YGValueUndefined) YGComputedEdgeValue(style_.position, YGEdgeEnd, &YGValueUndefined)
->unit != YGUnitUndefined) || ->unit != YGUnitUndefined) ||
@@ -63,9 +139,9 @@ bool YGNode::isTrailingPosDefined(const YGFlexDirection& axis) const {
->unit != YGUnitUndefined; ->unit != YGUnitUndefined;
} }
YGFloatOptional YGNode::getLeadingMargin( float YGNode::getLeadingMargin(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.margin[YGEdgeStart].unit != YGUnitUndefined) { style_.margin[YGEdgeStart].unit != YGUnitUndefined) {
return YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize); return YGResolveValueMargin(style_.margin[YGEdgeStart], widthSize);
@@ -76,9 +152,9 @@ YGFloatOptional YGNode::getLeadingMargin(
widthSize); widthSize);
} }
YGFloatOptional YGNode::getTrailingMargin( float YGNode::getTrailingMargin(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.margin[YGEdgeEnd].unit != YGUnitUndefined) { style_.margin[YGEdgeEnd].unit != YGUnitUndefined) {
return YGResolveValueMargin(style_.margin[YGEdgeEnd], widthSize); return YGResolveValueMargin(style_.margin[YGEdgeEnd], widthSize);
@@ -89,15 +165,37 @@ YGFloatOptional YGNode::getTrailingMargin(
widthSize); widthSize);
} }
YGFloatOptional YGNode::getMarginForAxis( float YGNode::getMarginForAxis(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize); return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
} }
// Setters // 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) { void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
if (measureFunc == nullptr) { if (measureFunc == nullptr) {
@@ -119,6 +217,38 @@ void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
measure_ = 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::setParent(YGNodeRef parent) {
parent_ = parent;
}
void YGNode::setChildren(const YGVector& children) {
children_ = children;
}
void YGNode::setNextChild(YGNodeRef nextChild) {
nextChild_ = nextChild;
}
void YGNode::replaceChild(YGNodeRef child, uint32_t index) { void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
children_[index] = child; children_[index] = child;
} }
@@ -131,6 +261,10 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
children_.insert(children_.begin() + index, child); children_.insert(children_.begin() + index, child);
} }
void YGNode::setConfig(YGConfigRef config) {
config_ = config;
}
void YGNode::setDirty(bool isDirty) { void YGNode::setDirty(bool isDirty) {
if (isDirty == isDirty_) { if (isDirty == isDirty_) {
return; return;
@@ -171,12 +305,11 @@ void YGNode::setLayoutPadding(float padding, int index) {
layout_.padding[index] = padding; layout_.padding[index] = padding;
} }
void YGNode::setLayoutLastOwnerDirection(YGDirection direction) { void YGNode::setLayoutLastParentDirection(YGDirection direction) {
layout_.lastOwnerDirection = direction; layout_.lastParentDirection = direction;
} }
void YGNode::setLayoutComputedFlexBasis( void YGNode::setLayoutComputedFlexBasis(float computedFlexBasis) {
const YGFloatOptional& computedFlexBasis) {
layout_.computedFlexBasis = computedFlexBasis; layout_.computedFlexBasis = computedFlexBasis;
} }
@@ -203,54 +336,41 @@ void YGNode::setLayoutDimension(float dimension, int index) {
// If both left and right are defined, then use left. Otherwise return // If both left and right are defined, then use left. Otherwise return
// +left or -right depending on which is defined. // +left or -right depending on which is defined.
YGFloatOptional YGNode::relativePosition( float YGNode::relativePosition(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& axisSize) const { const float axisSize) {
if (isLeadingPositionDefined(axis)) { return isLeadingPositionDefined(axis) ? getLeadingPosition(axis, axisSize)
return getLeadingPosition(axis, axisSize); : -getTrailingPosition(axis, axisSize);
}
YGFloatOptional trailingPosition = getTrailingPosition(axis, axisSize);
if (!trailingPosition.isUndefined()) {
trailingPosition.setValue(-1 * trailingPosition.getValue());
}
return trailingPosition;
} }
void YGNode::setPosition( void YGNode::setPosition(
const YGDirection direction, const YGDirection direction,
const float mainSize, const float mainSize,
const float crossSize, const float crossSize,
const float ownerWidth) { const float parentWidth) {
/* Root nodes should be always layouted as LTR, so we don't return negative /* Root nodes should be always layouted as LTR, so we don't return negative
* values. */ * values. */
const YGDirection directionRespectingRoot = const YGDirection directionRespectingRoot =
owner_ != nullptr ? direction : YGDirectionLTR; parent_ != nullptr ? direction : YGDirectionLTR;
const YGFlexDirection mainAxis = const YGFlexDirection mainAxis =
YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot); YGResolveFlexDirection(style_.flexDirection, directionRespectingRoot);
const YGFlexDirection crossAxis = const YGFlexDirection crossAxis =
YGFlexDirectionCross(mainAxis, directionRespectingRoot); YGFlexDirectionCross(mainAxis, directionRespectingRoot);
const YGFloatOptional relativePositionMain = const float relativePositionMain = relativePosition(mainAxis, mainSize);
relativePosition(mainAxis, mainSize); const float relativePositionCross = relativePosition(crossAxis, crossSize);
const YGFloatOptional relativePositionCross =
relativePosition(crossAxis, crossSize);
setLayoutPosition( setLayoutPosition(
YGUnwrapFloatOptional( getLeadingMargin(mainAxis, parentWidth) + relativePositionMain,
getLeadingMargin(mainAxis, ownerWidth) + relativePositionMain),
leading[mainAxis]); leading[mainAxis]);
setLayoutPosition( setLayoutPosition(
YGUnwrapFloatOptional( getTrailingMargin(mainAxis, parentWidth) + relativePositionMain,
getTrailingMargin(mainAxis, ownerWidth) + relativePositionMain),
trailing[mainAxis]); trailing[mainAxis]);
setLayoutPosition( setLayoutPosition(
YGUnwrapFloatOptional( getLeadingMargin(crossAxis, parentWidth) + relativePositionCross,
getLeadingMargin(crossAxis, ownerWidth) + relativePositionCross),
leading[crossAxis]); leading[crossAxis]);
setLayoutPosition( setLayoutPosition(
YGUnwrapFloatOptional( getTrailingMargin(crossAxis, parentWidth) + relativePositionCross,
getTrailingMargin(crossAxis, ownerWidth) + relativePositionCross),
trailing[crossAxis]); trailing[crossAxis]);
} }
@@ -265,8 +385,9 @@ YGNode::YGNode()
style_(YGStyle()), style_(YGStyle()),
layout_(YGLayout()), layout_(YGLayout()),
lineIndex_(0), lineIndex_(0),
owner_(nullptr), parent_(nullptr),
children_(YGVector()), children_(YGVector()),
nextChild_(nullptr),
config_(nullptr), config_(nullptr),
isDirty_(false), isDirty_(false),
resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {} resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {}
@@ -282,8 +403,9 @@ YGNode::YGNode(const YGNode& node)
style_(node.style_), style_(node.style_),
layout_(node.layout_), layout_(node.layout_),
lineIndex_(node.lineIndex_), lineIndex_(node.lineIndex_),
owner_(node.owner_), parent_(node.parent_),
children_(node.children_), children_(node.children_),
nextChild_(node.nextChild_),
config_(node.config_), config_(node.config_),
isDirty_(node.isDirty_), isDirty_(node.isDirty_),
resolvedDimensions_(node.resolvedDimensions_) {} resolvedDimensions_(node.resolvedDimensions_) {}
@@ -303,8 +425,9 @@ YGNode::YGNode(
YGStyle style, YGStyle style,
const YGLayout& layout, const YGLayout& layout,
uint32_t lineIndex, uint32_t lineIndex,
YGNodeRef owner, YGNodeRef parent,
const YGVector& children, const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config, YGConfigRef config,
bool isDirty, bool isDirty,
std::array<YGValue, 2> resolvedDimensions) std::array<YGValue, 2> resolvedDimensions)
@@ -318,8 +441,9 @@ YGNode::YGNode(
style_(style), style_(style),
layout_(layout), layout_(layout),
lineIndex_(lineIndex), lineIndex_(lineIndex),
owner_(owner), parent_(parent),
children_(children), children_(children),
nextChild_(nextChild),
config_(config), config_(config),
isDirty_(isDirty), isDirty_(isDirty),
resolvedDimensions_(resolvedDimensions) {} resolvedDimensions_(resolvedDimensions) {}
@@ -343,8 +467,9 @@ YGNode& YGNode::operator=(const YGNode& node) {
style_ = node.style_; style_ = node.style_;
layout_ = node.layout_; layout_ = node.layout_;
lineIndex_ = node.getLineIndex(); lineIndex_ = node.getLineIndex();
owner_ = node.getOwner(); parent_ = node.getParent();
children_ = node.getChildren(); children_ = node.getChildren();
nextChild_ = node.getNextChild();
config_ = node.getConfig(); config_ = node.getConfig();
isDirty_ = node.isDirty(); isDirty_ = node.isDirty();
resolvedDimensions_ = node.getResolvedDimensions(); resolvedDimensions_ = node.getResolvedDimensions();
@@ -393,9 +518,9 @@ void YGNode::resolveDimension() {
} }
} }
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) { YGDirection YGNode::resolveDirection(const YGDirection parentDirection) {
if (style_.direction == YGDirectionInherit) { if (style_.direction == YGDirectionInherit) {
return ownerDirection > YGDirectionInherit ? ownerDirection return parentDirection > YGDirectionInherit ? parentDirection
: YGDirectionLTR; : YGDirectionLTR;
} else { } else {
return style_.direction; return style_.direction;
@@ -425,35 +550,32 @@ void YGNode::cloneChildrenIfNeeded() {
} }
const YGNodeRef firstChild = children_.front(); const YGNodeRef firstChild = children_.front();
if (firstChild->getOwner() == this) { if (firstChild->getParent() == this) {
// If the first child has this node as its owner, we assume that it is // If the first child has this node as its parent, we assume that it is
// already unique. We can do this because if we have it has a child, that // already unique. We can do this because if we have it has a child, that
// means that its owner was at some point cloned which made that subtree // means that its parent was at some point cloned which made that subtree
// immutable. We also assume that all its sibling are cloned as well. // immutable. We also assume that all its sibling are cloned as well.
return; return;
} }
const YGCloneNodeFunc cloneNodeCallback = config_->cloneNodeCallback; const YGNodeClonedFunc cloneNodeCallback = config_->cloneNodeCallback;
for (uint32_t i = 0; i < childCount; ++i) { for (uint32_t i = 0; i < childCount; ++i) {
const YGNodeRef oldChild = children_[i]; const YGNodeRef oldChild = children_[i];
YGNodeRef newChild = nullptr; const YGNodeRef newChild = YGNodeClone(oldChild);
if (cloneNodeCallback) {
newChild = cloneNodeCallback(oldChild, this, i);
}
if (newChild == nullptr) {
newChild = YGNodeClone(oldChild);
}
replaceChild(newChild, i); replaceChild(newChild, i);
newChild->setOwner(this); newChild->setParent(this);
if (cloneNodeCallback) {
cloneNodeCallback(oldChild, newChild, this, i);
}
} }
} }
void YGNode::markDirtyAndPropogate() { void YGNode::markDirtyAndPropogate() {
if (!isDirty_) { if (!isDirty_) {
setDirty(true); setDirty(true);
setLayoutComputedFlexBasis(YGFloatOptional()); setLayoutComputedFlexBasis(YGUndefined);
if (owner_) { if (parent_) {
owner_->markDirtyAndPropogate(); parent_->markDirtyAndPropogate();
} }
} }
} }
@@ -467,7 +589,7 @@ void YGNode::markDirtyAndPropogateDownwards() {
float YGNode::resolveFlexGrow() { float YGNode::resolveFlexGrow() {
// Root nodes flexGrow should always be 0 // Root nodes flexGrow should always be 0
if (owner_ == nullptr) { if (parent_ == nullptr) {
return 0.0; return 0.0;
} }
if (!style_.flexGrow.isUndefined()) { if (!style_.flexGrow.isUndefined()) {
@@ -480,7 +602,7 @@ float YGNode::resolveFlexGrow() {
} }
float YGNode::resolveFlexShrink() { float YGNode::resolveFlexShrink() {
if (owner_ == nullptr) { if (parent_ == nullptr) {
return 0.0; return 0.0;
} }
if (!style_.flexShrink.isUndefined()) { if (!style_.flexShrink.isUndefined()) {
@@ -499,7 +621,7 @@ bool YGNode::isNodeFlexible() {
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); (resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
} }
float YGNode::getLeadingBorder(const YGFlexDirection& axis) const { float YGNode::getLeadingBorder(const YGFlexDirection axis) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.border[YGEdgeStart].unit != YGUnitUndefined && style_.border[YGEdgeStart].unit != YGUnitUndefined &&
!YGFloatIsUndefined(style_.border[YGEdgeStart].value) && !YGFloatIsUndefined(style_.border[YGEdgeStart].value) &&
@@ -512,7 +634,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
return YGFloatMax(computedEdgeValue, 0.0f); return YGFloatMax(computedEdgeValue, 0.0f);
} }
float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const { float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const {
if (YGFlexDirectionIsRow(flexDirection) && if (YGFlexDirectionIsRow(flexDirection) &&
style_.border[YGEdgeEnd].unit != YGUnitUndefined && style_.border[YGEdgeEnd].unit != YGUnitUndefined &&
!YGFloatIsUndefined(style_.border[YGEdgeEnd].value) && !YGFloatIsUndefined(style_.border[YGEdgeEnd].value) &&
@@ -526,52 +648,51 @@ float YGNode::getTrailingBorder(const YGFlexDirection& flexDirection) const {
return YGFloatMax(computedEdgeValue, 0.0f); return YGFloatMax(computedEdgeValue, 0.0f);
} }
YGFloatOptional YGNode::getLeadingPadding( float YGNode::getLeadingPadding(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
const YGFloatOptional& paddingEdgeStart =
YGResolveValue(style_.padding[YGEdgeStart], widthSize);
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeStart].unit != YGUnitUndefined && style_.padding[YGEdgeStart].unit != YGUnitUndefined &&
!paddingEdgeStart.isUndefined() && paddingEdgeStart.getValue() > 0.0f) { !YGResolveValue(style_.padding[YGEdgeStart], widthSize).isUndefined() &&
return paddingEdgeStart; YGUnwrapFloatOptional(
YGResolveValue(style_.padding[YGEdgeStart], widthSize)) > 0.0f) {
return YGUnwrapFloatOptional(YGResolveValue(style_.padding[YGEdgeStart], widthSize));
} }
YGFloatOptional resolvedValue = YGResolveValue( float resolvedValue = YGUnwrapFloatOptional(YGResolveValue(
*YGComputedEdgeValue(style_.padding, leading[axis], &YGValueZero), *YGComputedEdgeValue(style_.padding, leading[axis], &YGValueZero),
widthSize); widthSize));
return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); return YGFloatMax(resolvedValue, 0.0f);
} }
YGFloatOptional YGNode::getTrailingPadding( float YGNode::getTrailingPadding(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
if (YGFlexDirectionIsRow(axis) && if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeEnd].unit != YGUnitUndefined && style_.padding[YGEdgeEnd].unit != YGUnitUndefined &&
!YGResolveValue(style_.padding[YGEdgeEnd], widthSize).isUndefined() && !YGResolveValue(style_.padding[YGEdgeEnd], widthSize).isUndefined() &&
YGResolveValue(style_.padding[YGEdgeEnd], widthSize).getValue() >= 0.0f) { YGUnwrapFloatOptional(
return YGResolveValue(style_.padding[YGEdgeEnd], widthSize); YGResolveValue(style_.padding[YGEdgeEnd], widthSize)) >= 0.0f) {
return YGUnwrapFloatOptional(YGResolveValue(style_.padding[YGEdgeEnd], widthSize));
} }
YGFloatOptional resolvedValue = YGResolveValue( float resolvedValue = YGUnwrapFloatOptional(YGResolveValue(
*YGComputedEdgeValue(style_.padding, trailing[axis], &YGValueZero), *YGComputedEdgeValue(style_.padding, trailing[axis], &YGValueZero),
widthSize); widthSize));
return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); return YGFloatMax(resolvedValue, 0.0f);
} }
YGFloatOptional YGNode::getLeadingPaddingAndBorder( float YGNode::getLeadingPaddingAndBorder(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
return getLeadingPadding(axis, widthSize) + return getLeadingPadding(axis, widthSize) + getLeadingBorder(axis);
YGFloatOptional(getLeadingBorder(axis));
} }
YGFloatOptional YGNode::getTrailingPaddingAndBorder( float YGNode::getTrailingPaddingAndBorder(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const { const float widthSize) const {
return getTrailingPadding(axis, widthSize) + return getTrailingPadding(axis, widthSize) + getTrailingBorder(axis);
YGFloatOptional(getTrailingBorder(axis));
} }
bool YGNode::didUseLegacyFlag() { bool YGNode::didUseLegacyFlag() {

View File

@@ -7,7 +7,6 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
#include "YGConfig.h"
#include "YGLayout.h" #include "YGLayout.h"
#include "YGStyle.h" #include "YGStyle.h"
#include "Yoga-internal.h" #include "Yoga-internal.h"
@@ -24,15 +23,14 @@ struct YGNode {
YGStyle style_; YGStyle style_;
YGLayout layout_; YGLayout layout_;
uint32_t lineIndex_; uint32_t lineIndex_;
YGNodeRef owner_; YGNodeRef parent_;
YGVector children_; YGVector children_;
YGNodeRef nextChild_;
YGConfigRef config_; YGConfigRef config_;
bool isDirty_; bool isDirty_;
std::array<YGValue, 2> resolvedDimensions_; std::array<YGValue, 2> resolvedDimensions_;
YGFloatOptional relativePosition( float relativePosition(const YGFlexDirection axis, const float axisSize);
const YGFlexDirection& axis,
const float& axisSize) const;
public: public:
YGNode(); YGNode();
@@ -51,201 +49,75 @@ struct YGNode {
YGStyle style, YGStyle style,
const YGLayout& layout, const YGLayout& layout,
uint32_t lineIndex, uint32_t lineIndex,
YGNodeRef owner, YGNodeRef parent,
const YGVector& children, const YGVector& children,
YGNodeRef nextChild,
YGConfigRef config, YGConfigRef config,
bool isDirty, bool isDirty,
std::array<YGValue, 2> resolvedDimensions); std::array<YGValue, 2> resolvedDimensions);
// Getters // Getters
void* getContext() const { void* getContext() const;
return context_; YGPrintFunc getPrintFunc() const;
} bool getHasNewLayout() const;
YGNodeType getNodeType() const;
YGPrintFunc getPrintFunc() const { YGMeasureFunc getMeasure() const;
return print_; YGBaselineFunc getBaseline() const;
} YGDirtiedFunc getDirtied() const;
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. // For Performance reasons passing as reference.
YGStyle& getStyle() { YGStyle& getStyle();
return style_;
}
const YGStyle& getStyle() const {
return style_;
}
// For Performance reasons passing as reference. // For Performance reasons passing as reference.
YGLayout& getLayout() { YGLayout& getLayout();
return layout_; uint32_t getLineIndex() const;
} YGNodeRef getParent() const;
YGVector getChildren() const;
const YGLayout& getLayout() const { uint32_t getChildrenCount() const;
return layout_; YGNodeRef getChild(uint32_t index) const;
} YGNodeRef getNextChild() const;
YGConfigRef getConfig() const;
uint32_t getLineIndex() const { bool isDirty() const;
return lineIndex_; std::array<YGValue, 2> getResolvedDimensions() const;
} YGValue getResolvedDimension(int index);
// 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 {
return owner_;
}
// Deprecated, use getOwner() instead.
YGNodeRef getParent() const {
return getOwner();
}
YGVector getChildren() const {
return children_;
}
uint32_t getChildrenCount() const {
return static_cast<uint32_t>(children_.size());
}
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 // Methods related to positions, margin, padding and border
YGFloatOptional getLeadingPosition(const YGFlexDirection& axis, float getLeadingPosition(const YGFlexDirection axis, const float axisSize) const;
const float& axisSize) const; bool isLeadingPositionDefined(const YGFlexDirection axis) const;
bool isLeadingPositionDefined(const YGFlexDirection& axis) const; bool isTrailingPosDefined(const YGFlexDirection axis) const;
bool isTrailingPosDefined(const YGFlexDirection& axis) const; float getTrailingPosition(const YGFlexDirection axis, const float axisSize) const;
YGFloatOptional getTrailingPosition( float getLeadingMargin(const YGFlexDirection axis, const float widthSize) const;
const YGFlexDirection& axis, float getTrailingMargin(const YGFlexDirection axis, const float widthSize) const;
const float& axisSize) const; float getLeadingBorder(const YGFlexDirection flexDirection) const;
YGFloatOptional getLeadingMargin( float getTrailingBorder(const YGFlexDirection flexDirection) const;
const YGFlexDirection& axis, float getLeadingPadding(const YGFlexDirection axis, const float widthSize) const;
const float& widthSize) const; float getTrailingPadding(const YGFlexDirection axis, const float widthSize) const;
YGFloatOptional getTrailingMargin( float getLeadingPaddingAndBorder(
const YGFlexDirection& axis, const YGFlexDirection axis,
const float& widthSize) const; const float widthSize) const;
float getLeadingBorder(const YGFlexDirection& flexDirection) const; float getTrailingPaddingAndBorder(
float getTrailingBorder(const YGFlexDirection& flexDirection) const; const YGFlexDirection axis,
YGFloatOptional getLeadingPadding( const float widthSize) const;
const YGFlexDirection& axis, float getMarginForAxis(const YGFlexDirection axis, const float widthSize) const;
const float& widthSize) const;
YGFloatOptional getTrailingPadding(
const YGFlexDirection& axis,
const float& widthSize) const;
YGFloatOptional getLeadingPaddingAndBorder(
const YGFlexDirection& axis,
const float& widthSize) const;
YGFloatOptional getTrailingPaddingAndBorder(
const YGFlexDirection& axis,
const float& widthSize) const;
YGFloatOptional getMarginForAxis(
const YGFlexDirection& axis,
const float& widthSize) const;
// Setters // Setters
void setContext(void* context) { void setContext(void* context);
context_ = context; void setPrintFunc(YGPrintFunc printFunc);
} void setHasNewLayout(bool hasNewLayout);
void setNodeType(YGNodeType nodeTye);
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 setMeasureFunc(YGMeasureFunc measureFunc);
void setBaseLineFunc(YGBaselineFunc baseLineFunc);
void setBaseLineFunc(YGBaselineFunc baseLineFunc) { void setDirtiedFunc(YGDirtiedFunc dirtiedFunc);
baseline_ = baseLineFunc; void setStyle(const YGStyle& style);
} void setStyleFlexDirection(YGFlexDirection direction);
void setStyleAlignContent(YGAlign alignContent);
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) { void setLayout(const YGLayout& layout);
dirtied_ = dirtiedFunc; void setLineIndex(uint32_t lineIndex);
} void setParent(YGNodeRef parent);
void setChildren(const YGVector& children);
void setStyle(const YGStyle& style) { void setNextChild(YGNodeRef nextChild);
style_ = style; void setConfig(YGConfigRef config);
}
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 setDirty(bool isDirty);
void setLayoutLastOwnerDirection(YGDirection direction); void setLayoutLastParentDirection(YGDirection direction);
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis); void setLayoutComputedFlexBasis(float computedFlexBasis);
void setLayoutComputedFlexBasisGeneration( void setLayoutComputedFlexBasisGeneration(
uint32_t computedFlexBasisGeneration); uint32_t computedFlexBasisGeneration);
void setLayoutMeasuredDimension(float measuredDimension, int index); void setLayoutMeasuredDimension(float measuredDimension, int index);
@@ -260,7 +132,7 @@ struct YGNode {
const YGDirection direction, const YGDirection direction,
const float mainSize, const float mainSize,
const float crossSize, const float crossSize,
const float ownerWidth); const float parentWidth);
void setAndPropogateUseLegacyFlag(bool useLegacyFlag); void setAndPropogateUseLegacyFlag(bool useLegacyFlag);
void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout); void setLayoutDoesLegacyFlagAffectsLayout(bool doesLegacyFlagAffectsLayout);
void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag); void setLayoutDidUseLegacyFlag(bool didUseLegacyFlag);
@@ -271,7 +143,7 @@ struct YGNode {
YGValue marginTrailingValue(const YGFlexDirection axis) const; YGValue marginTrailingValue(const YGFlexDirection axis) const;
YGValue resolveFlexBasisPtr() const; YGValue resolveFlexBasisPtr() const;
void resolveDimension(); void resolveDimension();
YGDirection resolveDirection(const YGDirection ownerDirection); YGDirection resolveDirection(const YGDirection parentDirection);
void clearChildren(); void clearChildren();
/// Replaces the occurrences of oldChild with newChild /// Replaces the occurrences of oldChild with newChild
void replaceChild(YGNodeRef oldChild, YGNodeRef newChild); void replaceChild(YGNodeRef oldChild, YGNodeRef newChild);

View File

@@ -9,7 +9,7 @@
const YGValue kYGValueUndefined = {0, YGUnitUndefined}; const YGValue kYGValueUndefined = {0, YGUnitUndefined};
const YGValue kYGValueAuto = {0, YGUnitAuto}; const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};
const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = { const std::array<YGValue, YGEdgeCount> kYGDefaultEdgeValuesUnit = {
{kYGValueUndefined, {kYGValueUndefined,
@@ -42,7 +42,7 @@ YGStyle::YGStyle()
flex(YGFloatOptional()), flex(YGFloatOptional()),
flexGrow(YGFloatOptional()), flexGrow(YGFloatOptional()),
flexShrink(YGFloatOptional()), flexShrink(YGFloatOptional()),
flexBasis(kYGValueAuto), flexBasis({0, YGUnitAuto}),
margin(kYGDefaultEdgeValuesUnit), margin(kYGDefaultEdgeValuesUnit),
position(kYGDefaultEdgeValuesUnit), position(kYGDefaultEdgeValuesUnit),
padding(kYGDefaultEdgeValuesUnit), padding(kYGDefaultEdgeValuesUnit),
@@ -50,7 +50,7 @@ YGStyle::YGStyle()
dimensions(kYGDefaultDimensionValuesAutoUnit), dimensions(kYGDefaultDimensionValuesAutoUnit),
minDimensions(kYGDefaultDimensionValuesUnit), minDimensions(kYGDefaultDimensionValuesUnit),
maxDimensions(kYGDefaultDimensionValuesUnit), maxDimensions(kYGDefaultDimensionValuesUnit),
aspectRatio(YGFloatOptional()) {} aspectRatio(YGUndefined) {}
// Yoga specific properties, not compatible with flexbox specification // Yoga specific properties, not compatible with flexbox specification
bool YGStyle::operator==(const YGStyle& style) { bool YGStyle::operator==(const YGStyle& style) {
@@ -91,9 +91,10 @@ bool YGStyle::operator==(const YGStyle& style) {
flexShrink.getValue() == style.flexShrink.getValue(); flexShrink.getValue() == style.flexShrink.getValue();
} }
if (!(aspectRatio.isUndefined() && style.aspectRatio.isUndefined())) { if (!(YGFloatIsUndefined(aspectRatio) &&
areNonFloatValuesEqual = areNonFloatValuesEqual && YGFloatIsUndefined(style.aspectRatio))) {
aspectRatio.getValue() == style.aspectRatio.getValue(); areNonFloatValuesEqual =
areNonFloatValuesEqual && aspectRatio == style.aspectRatio;
} }
return areNonFloatValuesEqual; return areNonFloatValuesEqual;

View File

@@ -32,7 +32,7 @@ struct YGStyle {
std::array<YGValue, 2> dimensions; std::array<YGValue, 2> dimensions;
std::array<YGValue, 2> minDimensions; std::array<YGValue, 2> minDimensions;
std::array<YGValue, 2> maxDimensions; std::array<YGValue, 2> maxDimensions;
YGFloatOptional aspectRatio; float aspectRatio;
YGStyle(); YGStyle();
// Yoga specific properties, not compatible with flexbox specification // Yoga specific properties, not compatible with flexbox specification

View File

@@ -87,6 +87,16 @@ struct YGCachedMeasurement {
// layouts should not require more than 16 entries to fit within the cache. // layouts should not require more than 16 entries to fit within the cache.
#define YG_MAX_CACHED_RESULT_COUNT 16 #define YG_MAX_CACHED_RESULT_COUNT 16
struct YGConfig {
bool experimentalFeatures[YGExperimentalFeatureCount + 1];
bool useWebDefaults;
bool useLegacyStretchBehaviour;
bool shouldDiffLayoutWithoutLegacyStretchBehaviour;
float pointScaleFactor;
YGLogger logger;
YGNodeClonedFunc cloneNodeCallback;
void* context;
};
static const float kDefaultFlexGrow = 0.0f; static const float kDefaultFlexGrow = 0.0f;
static const float kDefaultFlexShrink = 0.0f; static const float kDefaultFlexShrink = 0.0f;

File diff suppressed because it is too large Load Diff

View File

@@ -62,8 +62,10 @@ typedef int (*YGLogger)(const YGConfigRef config,
YGLogLevel level, YGLogLevel level,
const char *format, const char *format,
va_list args); va_list args);
typedef YGNodeRef ( typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex); YGNodeRef newNode,
YGNodeRef parent,
int childIndex);
// YGNode // YGNode
WIN_EXPORT YGNodeRef YGNodeNew(void); WIN_EXPORT YGNodeRef YGNodeNew(void);
@@ -77,32 +79,17 @@ WIN_EXPORT int32_t YGNodeGetInstanceCount(void);
WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node, WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
const YGNodeRef child, const YGNodeRef child,
const uint32_t index); const uint32_t index);
// This function inserts the child YGNodeRef as a children of the node received
// by parameter and set the Owner of the child object to null. This function is
// expected to be called when using Yoga in persistent mode in order to share a
// YGNodeRef object as a child of two different Yoga trees. The child YGNodeRef
// is expected to be referenced from its original owner and from a clone of its
// original owner.
WIN_EXPORT void YGNodeInsertSharedChild(
const YGNodeRef node,
const YGNodeRef child,
const uint32_t index);
WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child); WIN_EXPORT void YGNodeRemoveChild(const YGNodeRef node, const YGNodeRef child);
WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node); WIN_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef node);
WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index); WIN_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index);
WIN_EXPORT YGNodeRef YGNodeGetOwner(const YGNodeRef node);
WIN_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node); WIN_EXPORT YGNodeRef YGNodeGetParent(const YGNodeRef node);
WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node); WIN_EXPORT uint32_t YGNodeGetChildCount(const YGNodeRef node);
WIN_EXPORT void YGNodeSetChildren( WIN_EXPORT void YGNodeSetChildren(YGNodeRef const parent, const YGNodeRef children[], const uint32_t count);
YGNodeRef const owner,
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 availableWidth,
const float availableHeight, const float availableHeight,
const YGDirection ownerDirection); const YGDirection parentDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function // Mark a node as dirty. Only valid for nodes with a custom measure function
// set. // set.
@@ -296,8 +283,8 @@ WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
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 bool YGConfigGetUseWebDefaults(const YGConfigRef config);
WIN_EXPORT void YGConfigSetCloneNodeFunc(const YGConfigRef config, WIN_EXPORT void YGConfigSetNodeClonedFunc(const YGConfigRef config,
const YGCloneNodeFunc callback); const YGNodeClonedFunc callback);
// Export only for C# // Export only for C#
WIN_EXPORT YGConfigRef YGConfigGetDefault(void); WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
@@ -321,8 +308,6 @@ YG_EXTERN_C_END
// Calls f on each node in the tree including the given node argument. // 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( extern void YGNodeSetChildren(YGNodeRef const parent, const std::vector<YGNodeRef> &children);
YGNodeRef const owner,
const std::vector<YGNodeRef>& children);
#endif #endif

View File

@@ -1,192 +1,115 @@
"""Provides macros for working with yoga library.""" """Provides macros for working with yoga library."""
YOGA_ROOTS = ["//..."] YOGA_ROOTS = ['//...']
JAVA_TARGET = '//java:java'
JAVA_TARGET = "//java:java" INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations'
JSR_305_TARGET = '//lib/jsr-305:jsr-305'
INFER_ANNOTATIONS_TARGET = "//lib/infer-annotations:infer-annotations" JUNIT_TARGET = '//lib/junit:junit'
PROGRUARD_ANNOTATIONS_TARGET = '//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations'
JSR_305_TARGET = "//lib/jsr-305:jsr-305" SOLOADER_TARGET = '//lib/soloader:soloader'
GTEST_TARGET = '//lib/gtest:gtest'
JUNIT_TARGET = "//lib/junit:junit" JNI_TARGET = '//lib/jni:jni'
FBJNI_TARGET = '//lib/fb:fbjni'
PROGRUARD_ANNOTATIONS_TARGET = "//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations" FBJNI_JAVA_TARGET = '//lib/fb/src/main/java/com/facebook/jni:jni'
APPCOMPAT_TARGET = '//lib/appcompat:appcompat'
SOLOADER_TARGET = "//lib/soloader:soloader" ANDROID = ''
ANDROID_SUPPORT_TARGET = '//lib/android-support:android-support'
GTEST_TARGET = "//lib/gtest:gtest" ANDROID_TARGET = '//android:android'
ANDROID_JAVA_TARGET = '//android/src/main/java/com/facebook/yoga/android:android'
JNI_TARGET = "//lib/jni:jni" ANDROID_RES_TARGET = '//android:res'
ANDROID_SAMPLE_JAVA_TARGET = '//android/sample/java/com/facebook/samples/yoga:yoga'
FBJNI_TARGET = "//lib/fb:fbjni" ANDROID_SAMPLE_RES_TARGET = '//android/sample:res'
FBJNI_JAVA_TARGET = "//lib/fb/src/main/java/com/facebook/jni:jni"
APPCOMPAT_TARGET = "//lib/appcompat:appcompat"
APPLE = ""
ANDROID = ""
ANDROID_SUPPORT_TARGET = "//lib/android-support:android-support"
ANDROID_TARGET = "//android:android"
ANDROID_JAVA_TARGET = "//android/src/main/java/com/facebook/yoga/android:android"
ANDROID_RES_TARGET = "//android:res"
ANDROID_SAMPLE_JAVA_TARGET = "//android/sample/java/com/facebook/samples/yoga:yoga"
ANDROID_SAMPLE_RES_TARGET = "//android/sample:res"
CXX_LIBRARY_WHITELIST = [ CXX_LIBRARY_WHITELIST = [
"//:yoga", '//:yoga',
"//lib/fb:fbjni", '//lib/fb:fbjni',
"//java:jni", '//java:jni',
] ]
BASE_COMPILER_FLAGS = [ BASE_COMPILER_FLAGS = [
"-fno-omit-frame-pointer", '-fno-omit-frame-pointer',
"-fexceptions", '-fexceptions',
"-Wall", '-Wall',
"-Werror", '-Werror',
"-O3", '-O3',
"-ffast-math",
] ]
LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [ LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
"-fPIC", '-fPIC',
] ]
def _paths_join(path, *others):
"""Joins one or more path components."""
result = path
for p in others:
if p.startswith("/"): # absolute
result = p
elif not result or result.endswith("/"):
result += p
else:
result += "/" + p
return result
def subdir_glob(glob_specs, exclude = None, prefix = ""):
"""Returns a dict of sub-directory relative paths to full paths.
The subdir_glob() function is useful for defining header maps for C/C++
libraries which should be relative the given sub-directory.
Given a list of tuples, the form of (relative-sub-directory, glob-pattern),
it returns a dict of sub-directory relative paths to full paths.
Please refer to native.glob() for explanations and examples of the pattern.
Args:
glob_specs: The array of tuples in form of
(relative-sub-directory, glob-pattern inside relative-sub-directory).
type: List[Tuple[str, str]]
exclude: A list of patterns to identify files that should be removed
from the set specified by the first argument. Defaults to [].
type: Optional[List[str]]
prefix: If is not None, prepends it to each key in the dictionary.
Defaults to None.
type: Optional[str]
Returns:
A dict of sub-directory relative paths to full paths.
"""
if exclude == None:
exclude = []
results = []
for dirpath, glob_pattern in glob_specs:
results.append(
_single_subdir_glob(dirpath, glob_pattern, exclude, prefix),
)
return _merge_maps(*results)
def _merge_maps(*file_maps):
result = {}
for file_map in file_maps:
for key in file_map:
if key in result and result[key] != file_map[key]:
fail(
"Conflicting files in file search paths. " +
"\"%s\" maps to both \"%s\" and \"%s\"." %
(key, result[key], file_map[key]),
)
result[key] = file_map[key]
return result
def _single_subdir_glob(dirpath, glob_pattern, exclude = None, prefix = None):
if exclude == None:
exclude = []
results = {}
files = native.glob([_paths_join(dirpath, glob_pattern)], exclude = exclude)
for f in files:
if dirpath:
key = f[len(dirpath) + 1:]
else:
key = f
if prefix:
key = _paths_join(prefix, key)
results[key] = f
return results
def yoga_dep(dep): def yoga_dep(dep):
return "//" + dep return '//' + dep
def yoga_android_aar(*args, **kwargs):
native.android_aar(*args, **kwargs)
def yoga_android_binary(*args, **kwargs): _original_android_aar = android_aar
native.android_binary(*args, **kwargs) def android_aar(*args, **kwargs):
_original_android_aar(*args, **kwargs)
def yoga_android_library(*args, **kwargs):
native.android_library(*args, **kwargs)
def yoga_android_resource(*args, **kwargs): _original_android_binary = android_binary
native.android_resource(*args, **kwargs) def android_binary(*args, **kwargs):
_original_android_binary(*args, **kwargs)
def yoga_apple_library(*args, **kwargs):
native.apple_library(*args, **kwargs)
def yoga_apple_test(*args, **kwargs): _original_android_library = android_library
native.apple_test(*args, **kwargs) def android_library(*args, **kwargs):
_original_android_library(*args, **kwargs)
def yoga_cxx_binary(*args, **kwargs):
kwargs.pop("platforms", None)
native.cxx_binary(*args, **kwargs)
def yoga_cxx_library(*args, **kwargs): _original_android_resource = android_resource
def android_resource(*args, **kwargs):
_original_android_resource(*args, **kwargs)
_original_apple_library = apple_library
def apple_library(*args, **kwargs):
_original_apple_library(*args, **kwargs)
_original_apple_test = apple_test
def apple_test(*args, **kwargs):
_original_apple_test(*args, **kwargs)
_original_cxx_library = cxx_library
def cxx_library(*args, **kwargs):
# Currently unused # Currently unused
kwargs.pop("platforms", None) kwargs.pop("platforms", None)
native.cxx_library(*args, **kwargs) _original_cxx_library(*args, **kwargs)
def yoga_cxx_test(*args, **kwargs):
native.cxx_test(*args, **kwargs)
def yoga_java_binary(*args, **kwargs): _original_cxx_test = cxx_test
native.java_binary(*args, **kwargs) def cxx_test(*args, **kwargs):
_original_cxx_test(*args, **kwargs)
def yoga_java_library(*args, **kwargs):
native.java_library(*args, **kwargs)
def yoga_java_test(*args, **kwargs): _original_java_binary = java_binary
native.java_test(*args, **kwargs) def java_binary(*args, **kwargs):
_original_java_binary(*args, **kwargs)
def yoga_prebuilt_cxx_library(*args, **kwargs):
native.prebuilt_cxx_library(*args, **kwargs)
def yoga_prebuilt_jar(*args, **kwargs): _original_java_library = java_library
native.prebuilt_jar(*args, **kwargs) def java_library(*args, **kwargs):
_original_java_library(*args, **kwargs)
_original_java_test = java_test
def java_test(*args, **kwargs):
_original_java_test(*args, **kwargs)
_original_prebuilt_cxx_library = prebuilt_cxx_library
def prebuilt_cxx_library(*args, **kwargs):
_original_prebuilt_cxx_library(*args, **kwargs)
_original_prebuilt_jar = prebuilt_jar
def prebuilt_jar(*args, **kwargs):
_original_prebuilt_jar(*args, **kwargs)
def is_apple_platform(): def is_apple_platform():
return True return True