Makes Yoga threadsafed: #791
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |spec|
|
Pod::Spec.new do |spec|
|
||||||
spec.name = 'Yoga'
|
spec.name = 'Yoga'
|
||||||
spec.version = '1.8.1'
|
spec.version = '1.9.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,11 +11,14 @@ 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 => '1.8.0',
|
:tag => spec.version.to_s,
|
||||||
}
|
}
|
||||||
spec.platforms = { :ios => "8.0", :tvos => "10.0" }
|
spec.platforms = { :ios => "8.0", :tvos => "10.0" }
|
||||||
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',
|
||||||
|
@@ -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.8.1'
|
spec.version = '1.9.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 => '1.7.0',
|
:tag => spec.version.to_s,
|
||||||
}
|
}
|
||||||
|
|
||||||
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.8.1'
|
spec.dependency 'Yoga', '~> 1.9'
|
||||||
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'
|
||||||
|
@@ -5,10 +5,72 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGBenchmark.h"
|
#include <math.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include <yoga/Yoga.h>
|
#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,
|
||||||
@@ -97,7 +159,7 @@ YGBENCHMARKS({
|
|||||||
YGNodeStyleSetHeight(grandGrandChild, 10);
|
YGNodeStyleSetHeight(grandGrandChild, 10);
|
||||||
YGNodeInsertChild(grandChild, grandGrandChild, 0);
|
YGNodeInsertChild(grandChild, grandGrandChild, 0);
|
||||||
|
|
||||||
for (uint32_t iii = 0; iii < 10; iii++) {
|
for (uint32_t iiii = 0; iiii < 10; iiii++) {
|
||||||
const YGNodeRef grandGrandGrandChild = YGNodeNew();
|
const YGNodeRef grandGrandGrandChild = YGNodeNew();
|
||||||
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
|
||||||
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
|
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
|
||||||
|
@@ -1,71 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#define NUM_REPETITIONS 1000
|
|
||||||
|
|
||||||
#define YGBENCHMARKS(BLOCK) \
|
|
||||||
int main(int argc, char const *argv[]) { \
|
|
||||||
clock_t __start; \
|
|
||||||
clock_t __endTimes[NUM_REPETITIONS]; \
|
|
||||||
{ BLOCK } \
|
|
||||||
return 0; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define YGBENCHMARK(NAME, BLOCK) \
|
|
||||||
__start = clock(); \
|
|
||||||
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
|
|
||||||
{ BLOCK } \
|
|
||||||
__endTimes[__i] = clock(); \
|
|
||||||
} \
|
|
||||||
__printBenchmarkResult(NAME, __start, __endTimes);
|
|
||||||
|
|
||||||
int __compareDoubles(const void *a, const void *b) {
|
|
||||||
double arg1 = *(const double *) a;
|
|
||||||
double arg2 = *(const double *) b;
|
|
||||||
|
|
||||||
if (arg1 < arg2) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg1 > arg2) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) {
|
|
||||||
double timesInMs[NUM_REPETITIONS];
|
|
||||||
double mean = 0;
|
|
||||||
clock_t lastEnd = start;
|
|
||||||
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
|
|
||||||
timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000;
|
|
||||||
lastEnd = endTimes[i];
|
|
||||||
mean += timesInMs[i];
|
|
||||||
}
|
|
||||||
mean /= NUM_REPETITIONS;
|
|
||||||
|
|
||||||
qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles);
|
|
||||||
double median = timesInMs[NUM_REPETITIONS / 2];
|
|
||||||
|
|
||||||
double variance = 0;
|
|
||||||
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
|
|
||||||
variance += pow(timesInMs[i] - mean, 2);
|
|
||||||
}
|
|
||||||
variance /= NUM_REPETITIONS;
|
|
||||||
double stddev = sqrt(variance);
|
|
||||||
|
|
||||||
printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev);
|
|
||||||
}
|
|
48
csharp/BUCK
48
csharp/BUCK
@@ -3,7 +3,14 @@
|
|||||||
# 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",
|
||||||
|
"is_apple_platform",
|
||||||
|
"yoga_cxx_library",
|
||||||
|
"yoga_dep",
|
||||||
|
"yoga_apple_binary",
|
||||||
|
)
|
||||||
|
|
||||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
|
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
|
||||||
|
|
||||||
@@ -32,41 +39,4 @@ yoga_cxx_library(
|
|||||||
deps = [yoga_dep(":yoga")],
|
deps = [yoga_dep(":yoga")],
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_apple_platform():
|
yoga_apple_binary()
|
||||||
yoganet_ios_srcs = []
|
|
||||||
for arch in [
|
|
||||||
"iphonesimulator-x86_64",
|
|
||||||
"iphoneos-arm64",
|
|
||||||
]:
|
|
||||||
name = "yoganet-" + arch
|
|
||||||
yoganet_ios_srcs.append(":" + name)
|
|
||||||
genrule(
|
|
||||||
name = name,
|
|
||||||
srcs = [
|
|
||||||
yoga_dep(":yogaApple#%s,static" % arch),
|
|
||||||
yoga_dep("YogaKit:YogaKitApple#%s,static" % arch),
|
|
||||||
yoga_dep("csharp:yoganetApple#%s,static" % arch),
|
|
||||||
],
|
|
||||||
out = "libyoga-%s.a" % arch,
|
|
||||||
cmd = "libtool -static -o $OUT $SRCS",
|
|
||||||
visibility = [yoga_dep("csharp:yoganet-ios")],
|
|
||||||
)
|
|
||||||
|
|
||||||
genrule(
|
|
||||||
name = "yoganet-ios",
|
|
||||||
srcs = yoganet_ios_srcs,
|
|
||||||
out = "libyoga.a",
|
|
||||||
cmd = "lipo $SRCS -create -output $OUT",
|
|
||||||
visibility = ["PUBLIC"],
|
|
||||||
)
|
|
||||||
|
|
||||||
yoganet_macosx_target = "csharp:yoganetAppleMac#macosx-%s,dynamic"
|
|
||||||
genrule(
|
|
||||||
name = "yoganet-macosx",
|
|
||||||
srcs = [
|
|
||||||
yoga_dep(yoganet_macosx_target % "x86_64"),
|
|
||||||
],
|
|
||||||
out = "libyoga.dylib",
|
|
||||||
cmd = "lipo $SRCS -create -output $OUT",
|
|
||||||
visibility = ["PUBLIC"],
|
|
||||||
)
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1536M
|
org.gradle.jvmargs=-Xmx1536M
|
||||||
|
|
||||||
VERSION_NAME=1.8.1-SNAPSHOT
|
VERSION_NAME=1.9.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
|
||||||
|
@@ -52,7 +52,7 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
|
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
|
||||||
compileOnly project(':yoga:proguard-annotations')
|
compileOnly project(':yoga:proguard-annotations')
|
||||||
implementation 'com.facebook.soloader:soloader:0.2.0'
|
implementation 'com.facebook.soloader:soloader:0.5.1'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
public class YogaConstants {
|
public class YogaConstants {
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017-present, Facebook, Inc.
|
* Copyright (c) 2017-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
167
java/com/facebook/yoga/YogaNodeProperties.java
Normal file
167
java/com/facebook/yoga/YogaNodeProperties.java
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
public interface YogaNodeProperties {
|
||||||
|
|
||||||
|
YogaNodeProperties clone(YogaNode node);
|
||||||
|
|
||||||
|
long getNativePointer();
|
||||||
|
|
||||||
|
void onAfterCalculateLayout();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
boolean hasNewLayout();
|
||||||
|
|
||||||
|
boolean isDirty();
|
||||||
|
|
||||||
|
void markLayoutSeen();
|
||||||
|
|
||||||
|
YogaDirection getStyleDirection();
|
||||||
|
|
||||||
|
void setDirection(YogaDirection direction);
|
||||||
|
|
||||||
|
YogaFlexDirection getFlexDirection();
|
||||||
|
|
||||||
|
void setFlexDirection(YogaFlexDirection flexDirection);
|
||||||
|
|
||||||
|
YogaJustify getJustifyContent();
|
||||||
|
|
||||||
|
void setJustifyContent(YogaJustify justifyContent);
|
||||||
|
|
||||||
|
YogaAlign getAlignItems();
|
||||||
|
|
||||||
|
void setAlignItems(YogaAlign alignItems);
|
||||||
|
|
||||||
|
YogaAlign getAlignSelf();
|
||||||
|
|
||||||
|
void setAlignSelf(YogaAlign alignSelf);
|
||||||
|
|
||||||
|
YogaAlign getAlignContent();
|
||||||
|
|
||||||
|
void setAlignContent(YogaAlign alignContent);
|
||||||
|
|
||||||
|
YogaPositionType getPositionType();
|
||||||
|
|
||||||
|
void setPositionType(YogaPositionType positionType);
|
||||||
|
|
||||||
|
void setWrap(YogaWrap flexWrap);
|
||||||
|
|
||||||
|
YogaOverflow getOverflow();
|
||||||
|
|
||||||
|
void setOverflow(YogaOverflow overflow);
|
||||||
|
|
||||||
|
YogaDisplay getDisplay();
|
||||||
|
|
||||||
|
void setDisplay(YogaDisplay display);
|
||||||
|
|
||||||
|
void setFlex(float flex);
|
||||||
|
|
||||||
|
float getFlexGrow();
|
||||||
|
|
||||||
|
void setFlexGrow(float flexGrow);
|
||||||
|
|
||||||
|
float getFlexShrink();
|
||||||
|
|
||||||
|
void setFlexShrink(float flexShrink);
|
||||||
|
|
||||||
|
YogaValue getFlexBasis();
|
||||||
|
|
||||||
|
void setFlexBasis(float flexBasis);
|
||||||
|
|
||||||
|
void setFlexBasisPercent(float percent);
|
||||||
|
|
||||||
|
void setFlexBasisAuto();
|
||||||
|
|
||||||
|
YogaValue getMargin(YogaEdge edge);
|
||||||
|
|
||||||
|
void setMargin(YogaEdge edge, float margin);
|
||||||
|
|
||||||
|
void setMarginPercent(YogaEdge edge, float percent);
|
||||||
|
|
||||||
|
void setMarginAuto(YogaEdge edge);
|
||||||
|
|
||||||
|
YogaValue getPadding(YogaEdge edge);
|
||||||
|
|
||||||
|
void setPadding(YogaEdge edge, float padding);
|
||||||
|
|
||||||
|
void setPaddingPercent(YogaEdge edge, float percent);
|
||||||
|
|
||||||
|
float getBorder(YogaEdge edge);
|
||||||
|
|
||||||
|
void setBorder(YogaEdge edge, float border);
|
||||||
|
|
||||||
|
YogaValue getPosition(YogaEdge edge);
|
||||||
|
|
||||||
|
void setPosition(YogaEdge edge, float position);
|
||||||
|
|
||||||
|
void setPositionPercent(YogaEdge edge, float percent);
|
||||||
|
|
||||||
|
YogaValue getWidth();
|
||||||
|
|
||||||
|
void setWidth(float width);
|
||||||
|
|
||||||
|
void setWidthPercent(float percent);
|
||||||
|
|
||||||
|
void setWidthAuto();
|
||||||
|
|
||||||
|
YogaValue getHeight();
|
||||||
|
|
||||||
|
void setHeight(float height);
|
||||||
|
|
||||||
|
void setHeightPercent(float percent);
|
||||||
|
|
||||||
|
void setHeightAuto();
|
||||||
|
|
||||||
|
YogaValue getMinWidth();
|
||||||
|
|
||||||
|
void setMinWidth(float minWidth);
|
||||||
|
|
||||||
|
void setMinWidthPercent(float percent);
|
||||||
|
|
||||||
|
YogaValue getMinHeight();
|
||||||
|
|
||||||
|
void setMinHeight(float minHeight);
|
||||||
|
|
||||||
|
void setMinHeightPercent(float percent);
|
||||||
|
|
||||||
|
YogaValue getMaxWidth();
|
||||||
|
|
||||||
|
void setMaxWidth(float maxWidth);
|
||||||
|
|
||||||
|
void setMaxWidthPercent(float percent);
|
||||||
|
|
||||||
|
YogaValue getMaxHeight();
|
||||||
|
|
||||||
|
void setMaxHeight(float maxheight);
|
||||||
|
|
||||||
|
void setMaxHeightPercent(float percent);
|
||||||
|
|
||||||
|
float getAspectRatio();
|
||||||
|
|
||||||
|
void setAspectRatio(float aspectRatio);
|
||||||
|
|
||||||
|
float getLayoutX();
|
||||||
|
|
||||||
|
float getLayoutY();
|
||||||
|
|
||||||
|
float getLayoutWidth();
|
||||||
|
|
||||||
|
float getLayoutHeight();
|
||||||
|
|
||||||
|
boolean getDoesLegacyStretchFlagAffectsLayout();
|
||||||
|
|
||||||
|
float getLayoutMargin(YogaEdge edge);
|
||||||
|
|
||||||
|
float getLayoutPadding(YogaEdge edge);
|
||||||
|
|
||||||
|
float getLayoutBorder(YogaEdge edge);
|
||||||
|
|
||||||
|
YogaDirection getLayoutDirection();
|
||||||
|
}
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.facebook.yoga;
|
package com.facebook.yoga;
|
||||||
|
|
||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
@@ -33,94 +33,121 @@ 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(YGNodeRef node, alias_ref<jobject> javaNode) {
|
static void YGTransferLayoutDirection(
|
||||||
static auto layoutDirectionField = javaNode->getClass()->getField<jint>("mLayoutDirection");
|
YGNodeRef node,
|
||||||
javaNode->setFieldValue(layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
|
alias_ref<jobject> javaNode) {
|
||||||
|
static auto layoutDirectionField =
|
||||||
|
javaNode->getClass()->getField<jint>("mLayoutDirection");
|
||||||
|
javaNode->setFieldValue(
|
||||||
|
layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||||
if (root->getHasNewLayout()) {
|
if (!root->getHasNewLayout()) {
|
||||||
if (auto obj = YGNodeJobject(root)->lockLocal()) {
|
return;
|
||||||
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
}
|
||||||
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
auto obj = YGNodeJobject(root)->lockLocal();
|
||||||
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
if (!obj) {
|
||||||
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
YGLog(
|
||||||
|
root,
|
||||||
|
YGLogLevelError,
|
||||||
|
"Java YGNode was GCed during layout calculation\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
|
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
||||||
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
|
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
||||||
static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
|
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
||||||
static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");
|
static auto topField = obj->getClass()->getField<jfloat>("mTop");
|
||||||
|
|
||||||
static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
|
static auto marginLeftField =
|
||||||
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
|
obj->getClass()->getField<jfloat>("mMarginLeft");
|
||||||
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
|
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
|
||||||
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
|
static auto marginRightField =
|
||||||
|
obj->getClass()->getField<jfloat>("mMarginRight");
|
||||||
|
static auto marginBottomField =
|
||||||
|
obj->getClass()->getField<jfloat>("mMarginBottom");
|
||||||
|
|
||||||
static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
|
static auto paddingLeftField =
|
||||||
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
|
obj->getClass()->getField<jfloat>("mPaddingLeft");
|
||||||
static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
|
static auto paddingTopField =
|
||||||
static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
|
obj->getClass()->getField<jfloat>("mPaddingTop");
|
||||||
|
static auto paddingRightField =
|
||||||
|
obj->getClass()->getField<jfloat>("mPaddingRight");
|
||||||
|
static auto paddingBottomField =
|
||||||
|
obj->getClass()->getField<jfloat>("mPaddingBottom");
|
||||||
|
|
||||||
static auto edgeSetFlagField = obj->getClass()->getField<jint>("mEdgeSetFlag");
|
static auto borderLeftField =
|
||||||
static auto hasNewLayoutField = obj->getClass()->getField<jboolean>("mHasNewLayout");
|
obj->getClass()->getField<jfloat>("mBorderLeft");
|
||||||
static auto doesLegacyStretchBehaviour =
|
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
|
||||||
obj->getClass()->getField<jboolean>(
|
static auto borderRightField =
|
||||||
"mDoesLegacyStretchFlagAffectsLayout");
|
obj->getClass()->getField<jfloat>("mBorderRight");
|
||||||
|
static auto borderBottomField =
|
||||||
|
obj->getClass()->getField<jfloat>("mBorderBottom");
|
||||||
|
|
||||||
/* Those flags needs be in sync with YogaNode.java */
|
static auto edgeSetFlagField =
|
||||||
const int MARGIN = 1;
|
obj->getClass()->getField<jint>("mEdgeSetFlag");
|
||||||
const int PADDING = 2;
|
static auto hasNewLayoutField =
|
||||||
const int BORDER = 4;
|
obj->getClass()->getField<jboolean>("mHasNewLayout");
|
||||||
|
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
|
||||||
|
"mDoesLegacyStretchFlagAffectsLayout");
|
||||||
|
|
||||||
int hasEdgeSetFlag = (int) obj->getFieldValue(edgeSetFlagField);
|
/* Those flags needs be in sync with YogaNode.java */
|
||||||
|
const int MARGIN = 1;
|
||||||
|
const int PADDING = 2;
|
||||||
|
const int BORDER = 4;
|
||||||
|
|
||||||
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
int hasEdgeSetFlag = (int)obj->getFieldValue(edgeSetFlagField);
|
||||||
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
|
||||||
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
|
||||||
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
|
||||||
obj->setFieldValue<jboolean>(
|
|
||||||
doesLegacyStretchBehaviour,
|
|
||||||
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
|
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
||||||
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
||||||
obj->setFieldValue(
|
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
|
||||||
marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
obj->setFieldValue<jboolean>(
|
||||||
obj->setFieldValue(
|
doesLegacyStretchBehaviour,
|
||||||
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
||||||
obj->setFieldValue(
|
|
||||||
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & PADDING) == PADDING) {
|
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
|
||||||
obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
obj->setFieldValue(
|
||||||
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||||
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
||||||
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
obj->setFieldValue(
|
||||||
}
|
marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
|
||||||
|
obj->setFieldValue(
|
||||||
|
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
||||||
|
}
|
||||||
|
|
||||||
if ((hasEdgeSetFlag & BORDER) == BORDER) {
|
if ((hasEdgeSetFlag & PADDING) == PADDING) {
|
||||||
obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
obj->setFieldValue(
|
||||||
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
||||||
obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
obj->setFieldValue(
|
||||||
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
|
||||||
}
|
obj->setFieldValue(
|
||||||
|
paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
|
||||||
|
obj->setFieldValue(
|
||||||
|
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||||
|
}
|
||||||
|
|
||||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
if ((hasEdgeSetFlag & BORDER) == BORDER) {
|
||||||
YGTransferLayoutDirection(root, obj);
|
obj->setFieldValue(
|
||||||
root->setHasNewLayout(false);
|
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
||||||
|
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
||||||
|
obj->setFieldValue(
|
||||||
|
borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
|
||||||
|
obj->setFieldValue(
|
||||||
|
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||||
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
YGTransferLayoutDirection(root, obj);
|
||||||
}
|
root->setHasNewLayout(false);
|
||||||
} else {
|
|
||||||
YGLog(root, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||||
}
|
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,14 +155,18 @@ 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(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
YGLog(
|
||||||
|
node,
|
||||||
|
YGLogLevelError,
|
||||||
|
"Java YGNode was GCed during layout calculation\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
|
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
|
||||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||||
static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")
|
static auto baselineFunc =
|
||||||
->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
findClassStatic("com/facebook/yoga/YogaNode")
|
||||||
|
->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
||||||
return baselineFunc(obj, width, height);
|
return baselineFunc(obj, width, height);
|
||||||
} else {
|
} else {
|
||||||
return height;
|
return height;
|
||||||
@@ -150,20 +181,17 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
|
|||||||
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGNodeRef YGJNIOnNodeClonedFunc(
|
static YGNodeRef
|
||||||
YGNodeRef oldNode,
|
YGJNIOnNodeClonedFunc(YGNodeRef oldNode, YGNodeRef owner, int childIndex) {
|
||||||
YGNodeRef owner,
|
|
||||||
int childIndex) {
|
|
||||||
auto config = oldNode->getConfig();
|
auto config = oldNode->getConfig();
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto onNodeClonedFunc = findClassStatic("com/facebook/yoga/YogaConfig")
|
static auto onNodeClonedFunc =
|
||||||
->getMethod<alias_ref<JYogaNode>(
|
findClassStatic("com/facebook/yoga/YogaConfig")
|
||||||
local_ref<JYogaNode>,
|
->getMethod<alias_ref<JYogaNode>(
|
||||||
local_ref<JYogaNode>,
|
local_ref<JYogaNode>, local_ref<JYogaNode>, jint)>("cloneNode");
|
||||||
jint)>("cloneNode");
|
|
||||||
|
|
||||||
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
||||||
auto javaConfig = context->config;
|
auto javaConfig = context->config;
|
||||||
@@ -174,15 +202,12 @@ static YGNodeRef YGJNIOnNodeClonedFunc(
|
|||||||
YGNodeJobject(owner)->lockLocal(),
|
YGNodeJobject(owner)->lockLocal(),
|
||||||
childIndex);
|
childIndex);
|
||||||
|
|
||||||
static auto replaceChild = findClassStatic("com/facebook/yoga/YogaNode")
|
static auto replaceChild =
|
||||||
->getMethod<jlong(
|
findClassStatic("com/facebook/yoga/YogaNode")
|
||||||
local_ref<JYogaNode>,
|
->getMethod<jlong(local_ref<JYogaNode>, jint)>("replaceChild");
|
||||||
jint)>("replaceChild");
|
|
||||||
|
|
||||||
jlong newNodeNativePointer = replaceChild(
|
jlong newNodeNativePointer =
|
||||||
YGNodeJobject(owner)->lockLocal(),
|
replaceChild(YGNodeJobject(owner)->lockLocal(), newNode, childIndex);
|
||||||
newNode,
|
|
||||||
childIndex);
|
|
||||||
|
|
||||||
return _jlong2YGNodeRef(newNodeNativePointer);
|
return _jlong2YGNodeRef(newNodeNativePointer);
|
||||||
}
|
}
|
||||||
@@ -194,24 +219,30 @@ 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 = findClassStatic("com/facebook/yoga/YogaNode")
|
static auto measureFunc =
|
||||||
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
findClassStatic("com/facebook/yoga/YogaNode")
|
||||||
|
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||||
|
|
||||||
YGTransferLayoutDirection(node, obj);
|
YGTransferLayoutDirection(node, obj);
|
||||||
const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode);
|
const auto measureResult =
|
||||||
|
measureFunc(obj, width, widthMode, height, heightMode);
|
||||||
|
|
||||||
static_assert(sizeof(measureResult) == 8,
|
static_assert(
|
||||||
"Expected measureResult to be 8 bytes, or two 32 bit ints");
|
sizeof(measureResult) == 8,
|
||||||
|
"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(node, YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
|
YGLog(
|
||||||
|
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,
|
||||||
@@ -223,24 +254,28 @@ struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
|
|||||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||||
};
|
};
|
||||||
|
|
||||||
static int YGJNILogFunc(const YGConfigRef config,
|
static int YGJNILogFunc(
|
||||||
const YGNodeRef node,
|
const YGConfigRef config,
|
||||||
YGLogLevel level,
|
const YGNodeRef node,
|
||||||
const char *format,
|
YGLogLevel level,
|
||||||
va_list args) {
|
const char* format,
|
||||||
|
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);
|
||||||
vsnprintf(buffer.data(), buffer.size(), format, args);
|
vsnprintf(buffer.data(), buffer.size(), format, args);
|
||||||
|
|
||||||
static auto logFunc =
|
static auto logFunc =
|
||||||
findClassStatic("com/facebook/yoga/YogaLogger")
|
findClassStatic("com/facebook/yoga/YogaLogger")
|
||||||
->getMethod<void(local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
|
->getMethod<void(
|
||||||
|
local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
|
||||||
|
|
||||||
static auto logLevelFromInt =
|
static auto logLevelFromInt =
|
||||||
JYogaLogLevel::javaClassStatic()->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
JYogaLogLevel::javaClassStatic()
|
||||||
|
->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
||||||
|
|
||||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||||
auto jlogger = reinterpret_cast<global_ref<jobject> *>(YGConfigGetContext(config));
|
auto jlogger =
|
||||||
|
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
||||||
logFunc(
|
logFunc(
|
||||||
jlogger->get(),
|
jlogger->get(),
|
||||||
obj,
|
obj,
|
||||||
@@ -309,13 +344,19 @@ 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(node,
|
YGNodePrint(
|
||||||
(YGPrintOptions)(YGPrintOptionsStyle | YGPrintOptionsLayout |
|
node,
|
||||||
YGPrintOptionsChildren));
|
(YGPrintOptions)(
|
||||||
|
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeInsertChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer, jint index) {
|
void jni_YGNodeInsertChild(
|
||||||
YGNodeInsertChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
|
alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jlong childPointer,
|
||||||
|
jint index) {
|
||||||
|
YGNodeInsertChild(
|
||||||
|
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeInsertSharedChild(
|
void jni_YGNodeInsertSharedChild(
|
||||||
@@ -327,19 +368,25 @@ void jni_YGNodeInsertSharedChild(
|
|||||||
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
|
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeRemoveChild(alias_ref<jobject>, jlong nativePointer, jlong childPointer) {
|
void jni_YGNodeRemoveChild(
|
||||||
YGNodeRemoveChild(_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
|
alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jlong childPointer) {
|
||||||
|
YGNodeRemoveChild(
|
||||||
|
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeCalculateLayout(alias_ref<jobject>,
|
void jni_YGNodeCalculateLayout(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jfloat width,
|
jlong nativePointer,
|
||||||
jfloat height) {
|
jfloat width,
|
||||||
|
jfloat height) {
|
||||||
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
|
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
|
||||||
YGNodeCalculateLayout(root,
|
YGNodeCalculateLayout(
|
||||||
static_cast<float>(width),
|
root,
|
||||||
static_cast<float>(height),
|
static_cast<float>(width),
|
||||||
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)));
|
static_cast<float>(height),
|
||||||
|
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)));
|
||||||
YGTransferLayoutOutputsRecursive(root);
|
YGTransferLayoutOutputsRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,20 +404,28 @@ jboolean jni_YGNodeIsDirty(alias_ref<jobject>, jlong nativePointer) {
|
|||||||
return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty();
|
return (jboolean)_jlong2YGNodeRef(nativePointer)->isDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeSetHasMeasureFunc(alias_ref<jobject>, jlong nativePointer, jboolean hasMeasureFunc) {
|
void jni_YGNodeSetHasMeasureFunc(
|
||||||
|
alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jboolean hasMeasureFunc) {
|
||||||
_jlong2YGNodeRef(nativePointer)
|
_jlong2YGNodeRef(nativePointer)
|
||||||
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
|
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
|
void jni_YGNodeSetHasBaselineFunc(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jboolean hasBaselineFunc) {
|
jlong nativePointer,
|
||||||
|
jboolean hasBaselineFunc) {
|
||||||
_jlong2YGNodeRef(nativePointer)
|
_jlong2YGNodeRef(nativePointer)
|
||||||
->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNativePointer) {
|
void jni_YGNodeCopyStyle(
|
||||||
YGNodeCopyStyle(_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
|
alias_ref<jobject>,
|
||||||
|
jlong dstNativePointer,
|
||||||
|
jlong srcNativePointer) {
|
||||||
|
YGNodeCopyStyle(
|
||||||
|
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct JYogaValue : public JavaClass<JYogaValue> {
|
struct JYogaValue : public JavaClass<JYogaValue> {
|
||||||
@@ -392,67 +447,76 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
|||||||
_jlong2YGNodeRef(nativePointer), static_cast<type>(value)); \
|
_jlong2YGNodeRef(nativePointer), static_cast<type>(value)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
||||||
local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \
|
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||||
return JYogaValue::create(YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
|
alias_ref<jobject>, jlong nativePointer) { \
|
||||||
} \
|
return JYogaValue::create( \
|
||||||
\
|
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
|
||||||
void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
} \
|
||||||
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
\
|
||||||
} \
|
void jni_YGNodeStyleSet##name( \
|
||||||
\
|
alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
||||||
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
YGNodeStyleSet##name( \
|
||||||
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
void jni_YGNodeStyleSet##name##Percent( \
|
||||||
|
alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
||||||
|
YGNodeStyleSet##name##Percent( \
|
||||||
|
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \
|
#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(alias_ref<jobject>, jlong nativePointer) { \
|
void jni_YGNodeStyleSet##name##Auto( \
|
||||||
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \
|
alias_ref<jobject>, jlong 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(alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
javatype jni_YGNodeStyleGet##name( \
|
||||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \
|
alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||||
static_cast<YGEdge>(edge)); \
|
return (javatype)YGNodeStyleGet##name( \
|
||||||
} \
|
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
|
||||||
\
|
} \
|
||||||
void jni_YGNodeStyleSet##name(alias_ref<jobject>, \
|
\
|
||||||
jlong nativePointer, \
|
void jni_YGNodeStyleSet##name( \
|
||||||
jint edge, \
|
alias_ref<jobject>, jlong nativePointer, jint edge, javatype value) { \
|
||||||
javatype value) { \
|
YGNodeStyleSet##name( \
|
||||||
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
|
_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(alias_ref<jobject>, \
|
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||||
jlong nativePointer, \
|
alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||||
jint edge) { \
|
return JYogaValue::create(YGNodeStyleGet##name( \
|
||||||
return JYogaValue::create( \
|
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
|
||||||
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( \
|
||||||
static_cast<YGEdge>(edge), \
|
_jlong2YGNodeRef(nativePointer), \
|
||||||
static_cast<float>(value)); \
|
static_cast<YGEdge>(edge), \
|
||||||
} \
|
static_cast<float>(value)); \
|
||||||
\
|
} \
|
||||||
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, \
|
\
|
||||||
jlong nativePointer, \
|
void jni_YGNodeStyleSet##name##Percent( \
|
||||||
jint edge, \
|
alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
|
||||||
jfloat value) { \
|
YGNodeStyleSet##name##Percent( \
|
||||||
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), \
|
_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(alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
void jni_YGNodeStyleSet##name##Auto( \
|
||||||
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
|
alias_ref<jobject>, jlong nativePointer, jint 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);
|
||||||
@@ -466,8 +530,12 @@ YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
|
|||||||
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
|
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
|
||||||
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
|
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
|
||||||
|
|
||||||
void jni_YGNodeStyleSetFlex(alias_ref<jobject>, jlong nativePointer, jfloat value) {
|
void jni_YGNodeStyleSetFlex(
|
||||||
YGNodeStyleSetFlex(_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
|
alias_ref<jobject>,
|
||||||
|
jlong nativePointer,
|
||||||
|
jfloat value) {
|
||||||
|
YGNodeStyleSetFlex(
|
||||||
|
_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
|
||||||
}
|
}
|
||||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
|
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
|
||||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
|
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
|
||||||
@@ -501,14 +569,14 @@ void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
|||||||
YGConfigFree(config);
|
YGConfigFree(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>,
|
void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jint feature,
|
jlong nativePointer,
|
||||||
jboolean enabled) {
|
jint feature,
|
||||||
|
jboolean enabled) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetExperimentalFeatureEnabled(config,
|
YGConfigSetExperimentalFeatureEnabled(
|
||||||
static_cast<YGExperimentalFeature>(feature),
|
config, static_cast<YGExperimentalFeature>(feature), enabled);
|
||||||
enabled);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
@@ -519,23 +587,26 @@ void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
|||||||
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
|
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>,
|
void jni_YGConfigSetUseWebDefaults(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jboolean useWebDefaults) {
|
jlong nativePointer,
|
||||||
|
jboolean useWebDefaults) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetUseWebDefaults(config, useWebDefaults);
|
YGConfigSetUseWebDefaults(config, useWebDefaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetPointScaleFactor(alias_ref<jobject>,
|
void jni_YGConfigSetPointScaleFactor(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jfloat pixelsInPoint) {
|
jlong nativePointer,
|
||||||
|
jfloat pixelsInPoint) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
YGConfigSetPointScaleFactor(config, pixelsInPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void jni_YGConfigSetUseLegacyStretchBehaviour(alias_ref<jobject>,
|
void jni_YGConfigSetUseLegacyStretchBehaviour(
|
||||||
jlong nativePointer,
|
alias_ref<jobject>,
|
||||||
jboolean useLegacyStretchBehaviour) {
|
jlong nativePointer,
|
||||||
|
jboolean useLegacyStretchBehaviour) {
|
||||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||||
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
||||||
}
|
}
|
||||||
@@ -592,7 +663,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",
|
||||||
|
983
java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java
Normal file
983
java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java
Normal file
@@ -0,0 +1,983 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the LICENSE
|
||||||
|
* file in the root directory of this source tree.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class YogaNodeStylePropertiesTest {
|
||||||
|
|
||||||
|
private static final float UNDEFINED = YogaValue.UNDEFINED.value;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDirectionDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(node.getStyleDirection(), YogaDirection.INHERIT);
|
||||||
|
assertEquals(node.getLayoutDirection(), YogaDirection.INHERIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDirectionAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setDirection(YogaDirection.LTR);
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(YogaDirection.LTR, node.getStyleDirection());
|
||||||
|
assertEquals(YogaDirection.LTR, node.getLayoutDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDirectionAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().direction(YogaDirection.RTL).width(200).children(style().widthPercent(40)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(120, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexDirectionDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaFlexDirection.COLUMN, node.getFlexDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexDirectionAssignment() {
|
||||||
|
final YogaNode node = style().flexDirection(YogaFlexDirection.COLUMN_REVERSE).node();
|
||||||
|
|
||||||
|
assertEquals(YogaFlexDirection.COLUMN_REVERSE, node.getFlexDirection());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexDirectionAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.flexDirection(YogaFlexDirection.ROW_REVERSE)
|
||||||
|
.width(200)
|
||||||
|
.children(style().widthPercent(40))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(120, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJustifyContentDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaJustify.FLEX_START, node.getJustifyContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJustifyContentAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setJustifyContent(YogaJustify.SPACE_EVENLY);
|
||||||
|
|
||||||
|
assertEquals(YogaJustify.SPACE_EVENLY, node.getJustifyContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJustifyContentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.justifyContent(YogaJustify.CENTER)
|
||||||
|
.height(200)
|
||||||
|
.children(style().heightPercent(40))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(60, node.getChildAt(0).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignItemsDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.STRETCH, node.getAlignItems());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignItemsAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setAlignItems(YogaAlign.SPACE_AROUND);
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.SPACE_AROUND, node.getAlignItems());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignItemsAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().alignItems(YogaAlign.CENTER).height(200).children(style().widthPercent(40)).node();
|
||||||
|
node.calculateLayout(200, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(60, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignSelfDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.AUTO, node.getAlignSelf());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignSelfAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setAlignSelf(YogaAlign.FLEX_END);
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.FLEX_END, node.getAlignSelf());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignSelfAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().height(200).children(style().alignSelf(YogaAlign.CENTER).widthPercent(40)).node();
|
||||||
|
node.calculateLayout(200, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(60, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignContentDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.FLEX_START, node.getAlignContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignContentAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setAlignContent(YogaAlign.BASELINE);
|
||||||
|
|
||||||
|
assertEquals(YogaAlign.BASELINE, node.getAlignContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAlignContentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.alignContent(YogaAlign.SPACE_AROUND)
|
||||||
|
.flexWrap(YogaWrap.WRAP)
|
||||||
|
.height(200)
|
||||||
|
.width(200)
|
||||||
|
.children(
|
||||||
|
style().widthPercent(20).heightPercent(60),
|
||||||
|
style().widthPercent(20).heightPercent(60))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(30, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionTypeDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaPositionType.RELATIVE, node.getPositionType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionTypeAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
|
||||||
|
assertEquals(YogaPositionType.ABSOLUTE, node.getPositionType());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionTypeAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.height(200)
|
||||||
|
.children(
|
||||||
|
style().height(100), style().height(100).positionType(YogaPositionType.ABSOLUTE))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0, node.getChildAt(1).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrapAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.width(200)
|
||||||
|
.height(200)
|
||||||
|
.flexWrap(YogaWrap.WRAP_REVERSE)
|
||||||
|
.children(style().width(10).heightPercent(60), style().heightPercent(60))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(190, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOverflowDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaOverflow.VISIBLE, node.getOverflow());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOverflowAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setOverflow(YogaOverflow.SCROLL);
|
||||||
|
|
||||||
|
assertEquals(YogaOverflow.SCROLL, node.getOverflow());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO add testOverflowAffectsLayout()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaDisplay.FLEX, node.getDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setDisplay(YogaDisplay.NONE);
|
||||||
|
|
||||||
|
assertEquals(YogaDisplay.NONE, node.getDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDisplayAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().children(style().flexGrow(1).display(YogaDisplay.NONE), style().flexGrow(1)).node();
|
||||||
|
node.calculateLayout(200, 200);
|
||||||
|
|
||||||
|
assertEquals(200, node.getChildAt(1).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexAffectsLayoutGrowing() {
|
||||||
|
final YogaNode node = style().height(200).children(style().height(100).flex(1.25f)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexAffectsLayoutShrinking() {
|
||||||
|
final YogaNode node = style().height(200).children(style().height(300).flex(1.25f)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexGrowDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(0, node.getFlexGrow(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexGrowAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setFlexGrow(2.5f);
|
||||||
|
|
||||||
|
assertEquals(2.5f, node.getFlexGrow(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexGrowAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().height(200).children(style().height(50).flexGrow(1), style().height(50)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(150, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexShrinkDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(0, node.getFlexShrink(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexShrinkAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setFlexShrink(2.5f);
|
||||||
|
|
||||||
|
assertEquals(2.5f, node.getFlexShrink(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexShrinkAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().height(200).children(style().height(150).flexShrink(1), style().height(150)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(50, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexBasisDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.AUTO, node.getFlexBasis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexBasisAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setFlexBasis(50);
|
||||||
|
assertEquals(new YogaValue(50, YogaUnit.POINT), node.getFlexBasis());
|
||||||
|
|
||||||
|
node.setFlexBasisPercent(20);
|
||||||
|
assertEquals(new YogaValue(20, YogaUnit.PERCENT), node.getFlexBasis());
|
||||||
|
|
||||||
|
node.setFlexBasisAuto();
|
||||||
|
assertEquals(YogaValue.AUTO, node.getFlexBasis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexBasisAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.height(200)
|
||||||
|
.children(style().flexBasis(150).flexShrink(1), style().flexBasis(150).flexShrink(1))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(100, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFlexBasisPercentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.height(200)
|
||||||
|
.children(style().flexBasisPercent(60), style().flexBasisPercent(40))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(80, node.getChildAt(1).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarginDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getMargin(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarginAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
node.setMargin(edge, 25);
|
||||||
|
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getMargin(edge));
|
||||||
|
|
||||||
|
node.setMarginPercent(edge, 5);
|
||||||
|
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getMargin(edge));
|
||||||
|
|
||||||
|
node.setMarginAuto(edge);
|
||||||
|
assertEquals(YogaValue.AUTO, node.getMargin(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarginPointAffectsLayout() {
|
||||||
|
final YogaNode node = style().margin(YogaEdge.TOP, 42).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(42, node.getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarginPercentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().height(200).children(style().flexGrow(1).marginPercent(YogaEdge.TOP, 20)).node();
|
||||||
|
node.calculateLayout(200, 200);
|
||||||
|
|
||||||
|
assertEquals(40, node.getChildAt(0).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarginAutoAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.width(200)
|
||||||
|
.flexDirection(YogaFlexDirection.ROW)
|
||||||
|
.children(style().marginAuto(YogaEdge.LEFT).marginAuto(YogaEdge.RIGHT).width(100))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(50, node.getChildAt(0).getLayoutX(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPaddingDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getPadding(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPaddingAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
node.setPadding(edge, 25);
|
||||||
|
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPadding(edge));
|
||||||
|
|
||||||
|
node.setPaddingPercent(edge, 5);
|
||||||
|
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getPadding(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPaddingPointAffectsLayout() {
|
||||||
|
final YogaNode node = style().padding(YogaEdge.TOP, 42).children(style()).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(42, node.getChildAt(0).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPaddingPercentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style().height(200).paddingPercent(YogaEdge.TOP, 20).children(style().flexGrow(1)).node();
|
||||||
|
node.calculateLayout(200, 200);
|
||||||
|
|
||||||
|
assertEquals(40, node.getChildAt(0).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBorderDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
assertEquals(UNDEFINED, node.getBorder(edge), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBorderAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
node.setBorder(edge, 2.5f);
|
||||||
|
assertEquals(2.5f, node.getBorder(edge), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBorderAffectsLayout() {
|
||||||
|
final YogaNode node = style().border(YogaEdge.TOP, 42).children(style()).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(42, node.getChildAt(0).getLayoutY(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getPosition(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
for (YogaEdge edge : YogaEdge.values()) {
|
||||||
|
node.setPosition(edge, 25);
|
||||||
|
assertEquals(new YogaValue(25, YogaUnit.POINT), node.getPosition(edge));
|
||||||
|
|
||||||
|
node.setPositionPercent(edge, 5);
|
||||||
|
assertEquals(new YogaValue(5, YogaUnit.PERCENT), node.getPosition(edge));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.height(100)
|
||||||
|
.children(
|
||||||
|
style()
|
||||||
|
.positionType(YogaPositionType.ABSOLUTE)
|
||||||
|
.position(YogaEdge.TOP, 11)
|
||||||
|
.position(YogaEdge.BOTTOM, 22))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(67, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPositionPercentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.width(100)
|
||||||
|
.children(
|
||||||
|
style()
|
||||||
|
.positionType(YogaPositionType.ABSOLUTE)
|
||||||
|
.positionPercent(YogaEdge.LEFT, 11)
|
||||||
|
.positionPercent(YogaEdge.RIGHT, 22))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(67, node.getChildAt(0).getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWidthDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.AUTO, node.getWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWidthAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setWidth(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getWidth());
|
||||||
|
|
||||||
|
node.setWidthPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWidthAffectsLayout() {
|
||||||
|
final YogaNode node = style().width(123).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWidthPercentAffectsLayout() {
|
||||||
|
final YogaNode node = style().widthPercent(75).node();
|
||||||
|
node.calculateLayout(200, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(150, node.getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: testWidthAutoAffectsLayout
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeightDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.AUTO, node.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeightAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setHeight(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getHeight());
|
||||||
|
|
||||||
|
node.setHeightPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeightAffectsLayout() {
|
||||||
|
final YogaNode node = style().height(123).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHeightPercentAffectsLayout() {
|
||||||
|
final YogaNode node = style().heightPercent(75).node();
|
||||||
|
node.calculateLayout(UNDEFINED, 200);
|
||||||
|
|
||||||
|
assertEquals(150, node.getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: testHeightAutoAffectsLayout
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinWidthDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getMinWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinWidthAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setMinWidth(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinWidth());
|
||||||
|
|
||||||
|
node.setMinWidthPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMinWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinWidthAffectsLayout() {
|
||||||
|
final YogaNode node = style().minWidth(123).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinWidthPercentAffectsLayout() {
|
||||||
|
final YogaNode node = style().minWidthPercent(120).node();
|
||||||
|
node.calculateLayout(200, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(240, node.getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinHeightDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getMinHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinHeightAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setMinHeight(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMinHeight());
|
||||||
|
|
||||||
|
node.setMinHeightPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMinHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinHeightAffectsLayout() {
|
||||||
|
final YogaNode node = style().minHeight(123).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMinHeightPercentAffectsLayout() {
|
||||||
|
final YogaNode node = style().minHeightPercent(120).node();
|
||||||
|
node.calculateLayout(UNDEFINED, 200);
|
||||||
|
|
||||||
|
assertEquals(240, node.getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxWidthDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getMaxWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxWidthAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setMaxWidth(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxWidth());
|
||||||
|
|
||||||
|
node.setMaxWidthPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMaxWidth());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxWidthAffectsLayout() {
|
||||||
|
final YogaNode node = style().width(200).children(style().maxWidth(123)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getChildAt(0).getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxWidthPercentAffectsLayout() {
|
||||||
|
final YogaNode node = style().width(200).children(style().maxWidthPercent(80)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(160, node.getChildAt(0).getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxHeightDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(YogaValue.UNDEFINED, node.getMaxHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxHeightAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setMaxHeight(123);
|
||||||
|
assertEquals(new YogaValue(123, YogaUnit.POINT), node.getMaxHeight());
|
||||||
|
|
||||||
|
node.setMaxHeightPercent(45);
|
||||||
|
assertEquals(new YogaValue(45, YogaUnit.PERCENT), node.getMaxHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxHeightAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.height(200)
|
||||||
|
.flexDirection(YogaFlexDirection.ROW)
|
||||||
|
.children(style().maxHeight(123))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(123, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMaxHeightPercentAffectsLayout() {
|
||||||
|
final YogaNode node =
|
||||||
|
style()
|
||||||
|
.flexDirection(YogaFlexDirection.ROW)
|
||||||
|
.height(200)
|
||||||
|
.children(style().maxHeightPercent(80))
|
||||||
|
.node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(160, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAspectRatioDefault() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
|
||||||
|
assertEquals(UNDEFINED, node.getAspectRatio(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAspectRatioAssignment() {
|
||||||
|
final YogaNode node = new YogaNode();
|
||||||
|
node.setAspectRatio(2.75f);
|
||||||
|
|
||||||
|
assertEquals(2.75f, node.getAspectRatio(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aspectRatioAffectsLayoutWithGivenWidth() {
|
||||||
|
final YogaNode node = style().children(style().width(300).aspectRatio(1.5f)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(200, node.getChildAt(0).getLayoutHeight(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aspectRatioAffectsLayoutWithGivenHeight() {
|
||||||
|
final YogaNode node = style().children(style().height(300).aspectRatio(1.5f)).node();
|
||||||
|
node.calculateLayout(UNDEFINED, UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(450, node.getChildAt(0).getLayoutWidth(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StyledNode style() {
|
||||||
|
return new StyledNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class StyledNode {
|
||||||
|
|
||||||
|
private YogaNode mNode = new YogaNode();
|
||||||
|
|
||||||
|
YogaNode node() {
|
||||||
|
return mNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode children(StyledNode... children) {
|
||||||
|
for (int i = mNode.getChildCount(); --i >= 0; ) {
|
||||||
|
mNode.removeChildAt(i);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < children.length; i++) {
|
||||||
|
mNode.addChildAt(children[i].node(), i);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode direction(YogaDirection direction) {
|
||||||
|
mNode.setDirection(direction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode width(float width) {
|
||||||
|
mNode.setWidth(width);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode widthPercent(float width) {
|
||||||
|
mNode.setWidthPercent(width);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexDirection(YogaFlexDirection direction) {
|
||||||
|
mNode.setFlexDirection(direction);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode justifyContent(YogaJustify justify) {
|
||||||
|
mNode.setJustifyContent(justify);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode height(float height) {
|
||||||
|
mNode.setHeight(height);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode heightPercent(float height) {
|
||||||
|
mNode.setHeightPercent(height);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode alignItems(YogaAlign align) {
|
||||||
|
mNode.setAlignItems(align);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode alignSelf(YogaAlign align) {
|
||||||
|
mNode.setAlignSelf(align);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode alignContent(YogaAlign align) {
|
||||||
|
mNode.setAlignContent(align);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexWrap(YogaWrap wrap) {
|
||||||
|
mNode.setWrap(wrap);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode positionType(YogaPositionType positionType) {
|
||||||
|
mNode.setPositionType(positionType);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode overflow(YogaOverflow overflow) {
|
||||||
|
mNode.setOverflow(overflow);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexShrink(float flexShrink) {
|
||||||
|
mNode.setFlexShrink(flexShrink);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode display(YogaDisplay display) {
|
||||||
|
mNode.setDisplay(display);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexGrow(float flexGrow) {
|
||||||
|
mNode.setFlexGrow(flexGrow);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flex(float flex) {
|
||||||
|
mNode.setFlex(flex);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexBasis(float flexBasis) {
|
||||||
|
mNode.setFlexBasis(flexBasis);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode flexBasisPercent(float flexBasis) {
|
||||||
|
mNode.setFlexBasisPercent(flexBasis);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode margin(YogaEdge edge, float margin) {
|
||||||
|
mNode.setMargin(edge, margin);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode marginPercent(YogaEdge edge, float margin) {
|
||||||
|
mNode.setMarginPercent(edge, margin);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode marginAuto(YogaEdge edge) {
|
||||||
|
mNode.setMarginAuto(edge);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode padding(YogaEdge edge, float padding) {
|
||||||
|
mNode.setPadding(edge, padding);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode paddingPercent(YogaEdge edge, float padding) {
|
||||||
|
mNode.setPaddingPercent(edge, padding);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode border(YogaEdge edge, float border) {
|
||||||
|
mNode.setBorder(edge, border);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode position(YogaEdge edge, float position) {
|
||||||
|
mNode.setPosition(edge, position);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode positionPercent(YogaEdge edge, float position) {
|
||||||
|
mNode.setPositionPercent(edge, position);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode minWidth(float minWidth) {
|
||||||
|
mNode.setMinWidth(minWidth);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode minWidthPercent(float minWidth) {
|
||||||
|
mNode.setMinWidthPercent(minWidth);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode minHeight(float minHeight) {
|
||||||
|
mNode.setMinHeight(minHeight);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode minHeightPercent(float minHeight) {
|
||||||
|
mNode.setMinHeightPercent(minHeight);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode maxWidth(float maxWidth) {
|
||||||
|
mNode.setMaxWidth(maxWidth);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode maxWidthPercent(float maxWidth) {
|
||||||
|
mNode.setMaxWidthPercent(maxWidth);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode maxHeight(float maxHeight) {
|
||||||
|
mNode.setMaxHeight(maxHeight);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode maxHeightPercent(float maxHeight) {
|
||||||
|
mNode.setMaxHeightPercent(maxHeight);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
StyledNode aspectRatio(float aspectRatio) {
|
||||||
|
mNode.setAspectRatio(aspectRatio);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -26,7 +26,7 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.facebook.soloader:soloader:0.2.0'
|
implementation 'com.facebook.soloader:soloader:0.5.1'
|
||||||
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
|
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
|
||||||
compileOnly project(':yoga:proguard-annotations')
|
compileOnly project(':yoga:proguard-annotations')
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,6 @@ load("//:yoga_defs.bzl", "YOGA_ROOTS")
|
|||||||
|
|
||||||
android_prebuilt_aar(
|
android_prebuilt_aar(
|
||||||
name = "soloader",
|
name = "soloader",
|
||||||
aar = "soloader-0.1.0.aar",
|
aar = "soloader-0.5.1.aar",
|
||||||
visibility = YOGA_ROOTS,
|
visibility = YOGA_ROOTS,
|
||||||
)
|
)
|
||||||
|
Binary file not shown.
BIN
lib/soloader/soloader-0.5.1.aar
Normal file
BIN
lib/soloader/soloader-0.5.1.aar
Normal file
Binary file not shown.
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
|
// @Generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -64,6 +64,90 @@ 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();
|
||||||
|
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <yoga/YGNode.h>
|
#include <yoga/YGNode.h>
|
||||||
#include <yoga/Yoga.h>
|
#include <yoga/Yoga.h>
|
||||||
|
@@ -5,8 +5,6 @@
|
|||||||
* 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>
|
||||||
|
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
/**
|
/*
|
||||||
* 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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
YGFlexDirection YGFlexDirectionCross(
|
YGFlexDirection YGFlexDirectionCross(
|
||||||
const YGFlexDirection flexDirection,
|
const YGFlexDirection flexDirection,
|
||||||
const YGDirection direction) {
|
const YGDirection direction) {
|
||||||
@@ -16,18 +18,18 @@ YGFlexDirection YGFlexDirectionCross(
|
|||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatMax(const float a, const float b) {
|
float YGFloatMax(const float a, const float b) {
|
||||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||||
return fmaxf(a, b);
|
return fmaxf(a, b);
|
||||||
}
|
}
|
||||||
return YGFloatIsUndefined(a) ? b : a;
|
return yoga::isUndefined(a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatMin(const float a, const float b) {
|
float YGFloatMin(const float a, const float b) {
|
||||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||||
return fminf(a, b);
|
return fminf(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
return YGFloatIsUndefined(a) ? b : a;
|
return yoga::isUndefined(a) ? b : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGValueEqual(const YGValue a, const YGValue b) {
|
bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||||
@@ -36,7 +38,7 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (a.unit == YGUnitUndefined ||
|
if (a.unit == YGUnitUndefined ||
|
||||||
(YGFloatIsUndefined(a.value) && YGFloatIsUndefined(b.value))) {
|
(yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,14 +46,14 @@ bool YGValueEqual(const YGValue a, const YGValue b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatsEqual(const float a, const float b) {
|
bool YGFloatsEqual(const float a, const float b) {
|
||||||
if (!YGFloatIsUndefined(a) && !YGFloatIsUndefined(b)) {
|
if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
|
||||||
return fabs(a - b) < 0.0001f;
|
return fabs(a - b) < 0.0001f;
|
||||||
}
|
}
|
||||||
return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
|
return yoga::isUndefined(a) && yoga::isUndefined(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGFloatSanitize(const float& val) {
|
float YGFloatSanitize(const float& val) {
|
||||||
return YGFloatIsUndefined(val) ? 0 : val;
|
return yoga::isUndefined(val) ? 0 : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
float YGUnwrapFloatOptional(const YGFloatOptional& op) {
|
||||||
|
@@ -1,17 +1,20 @@
|
|||||||
/**
|
/*
|
||||||
* 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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGFloatOptional.h"
|
#include "YGFloatOptional.h"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Yoga.h"
|
#include "Yoga.h"
|
||||||
|
#include "Yoga-internal.h"
|
||||||
|
|
||||||
YGFloatOptional::YGFloatOptional(const float& value) {
|
using namespace facebook;
|
||||||
if (YGFloatIsUndefined(value)) {
|
|
||||||
|
YGFloatOptional::YGFloatOptional(float value) {
|
||||||
|
if (yoga::isUndefined(value)) {
|
||||||
isUndefined_ = true;
|
isUndefined_ = true;
|
||||||
value_ = 0;
|
value_ = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -20,9 +23,7 @@ YGFloatOptional::YGFloatOptional(const float& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
YGFloatOptional::YGFloatOptional() : value_(0), isUndefined_(true) {}
|
float YGFloatOptional::getValue() const {
|
||||||
|
|
||||||
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,18 +32,9 @@ const float& YGFloatOptional::getValue() const {
|
|||||||
return value_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void YGFloatOptional::setValue(const float& val) {
|
|
||||||
value_ = val;
|
|
||||||
isUndefined_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool& YGFloatOptional::isUndefined() const {
|
|
||||||
return isUndefined_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
|
bool YGFloatOptional::operator==(const YGFloatOptional& op) const {
|
||||||
if (isUndefined_ == op.isUndefined()) {
|
if (isUndefined_ == op.isUndefined()) {
|
||||||
return isUndefined_ ? true : value_ == op.getValue();
|
return isUndefined_ || value_ == op.getValue();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -51,14 +43,14 @@ bool YGFloatOptional::operator!=(const YGFloatOptional& op) const {
|
|||||||
return !(*this == op);
|
return !(*this == op);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator==(const float& val) const {
|
bool YGFloatOptional::operator==(float val) const {
|
||||||
if (YGFloatIsUndefined(val) == isUndefined_) {
|
if (yoga::isUndefined(val) == isUndefined_) {
|
||||||
return isUndefined_ ? true : val == value_;
|
return isUndefined_ || val == value_;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator!=(const float& val) const {
|
bool YGFloatOptional::operator!=(float val) const {
|
||||||
return !(*this == val);
|
return !(*this == val);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,9 +76,9 @@ bool YGFloatOptional::operator<(const YGFloatOptional& op) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
|
bool YGFloatOptional::operator>=(const YGFloatOptional& op) const {
|
||||||
return *this == op ? true : *this > op;
|
return *this == op || *this > op;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
|
bool YGFloatOptional::operator<=(const YGFloatOptional& op) const {
|
||||||
return *this == op ? true : *this < op;
|
return *this == op || *this < op;
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct YGFloatOptional {
|
struct YGFloatOptional {
|
||||||
@@ -13,18 +13,23 @@ struct YGFloatOptional {
|
|||||||
bool isUndefined_;
|
bool isUndefined_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit YGFloatOptional(const float& value);
|
explicit YGFloatOptional(float value);
|
||||||
explicit YGFloatOptional();
|
explicit YGFloatOptional() : value_(0), isUndefined_(true) {}
|
||||||
|
|
||||||
// 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(const float& val);
|
void setValue(float val) {
|
||||||
|
value_ = val;
|
||||||
|
isUndefined_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
const bool& isUndefined() const;
|
bool isUndefined() const {
|
||||||
|
return isUndefined_;
|
||||||
|
}
|
||||||
|
|
||||||
YGFloatOptional operator+(const YGFloatOptional& op);
|
YGFloatOptional operator+(const YGFloatOptional& op);
|
||||||
bool operator>(const YGFloatOptional& op) const;
|
bool operator>(const YGFloatOptional& op) const;
|
||||||
@@ -34,6 +39,6 @@ struct YGFloatOptional {
|
|||||||
bool operator==(const YGFloatOptional& op) const;
|
bool operator==(const YGFloatOptional& op) const;
|
||||||
bool operator!=(const YGFloatOptional& op) const;
|
bool operator!=(const YGFloatOptional& op) const;
|
||||||
|
|
||||||
bool operator==(const float& val) const;
|
bool operator==(float val) const;
|
||||||
bool operator!=(const float& val) const;
|
bool operator!=(float val) const;
|
||||||
};
|
};
|
||||||
|
@@ -1,13 +1,15 @@
|
|||||||
/**
|
/*
|
||||||
* 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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGLayout.h"
|
#include "YGLayout.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
const std::array<float, 2> kYGDefaultDimensionValues = {
|
const std::array<float, 2> kYGDefaultDimensionValues = {
|
||||||
{YGUndefined, YGUndefined}};
|
{YGUndefined, YGUndefined}};
|
||||||
|
|
||||||
@@ -46,20 +48,16 @@ bool YGLayout::operator==(YGLayout layout) const {
|
|||||||
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
isEqual = isEqual && cachedMeasurements[i] == layout.cachedMeasurements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(measuredDimensions[0]) ||
|
if (!yoga::isUndefined(measuredDimensions[0]) ||
|
||||||
!YGFloatIsUndefined(layout.measuredDimensions[0])) {
|
!yoga::isUndefined(layout.measuredDimensions[0])) {
|
||||||
isEqual =
|
isEqual =
|
||||||
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
isEqual && (measuredDimensions[0] == layout.measuredDimensions[0]);
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(measuredDimensions[1]) ||
|
if (!yoga::isUndefined(measuredDimensions[1]) ||
|
||||||
!YGFloatIsUndefined(layout.measuredDimensions[1])) {
|
!yoga::isUndefined(layout.measuredDimensions[1])) {
|
||||||
isEqual =
|
isEqual =
|
||||||
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
isEqual && (measuredDimensions[1] == layout.measuredDimensions[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isEqual;
|
return isEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGLayout::operator!=(YGLayout layout) const {
|
|
||||||
return !(*this == layout);
|
|
||||||
}
|
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "YGFloatOptional.h"
|
#include "YGFloatOptional.h"
|
||||||
#include "Yoga-internal.h"
|
#include "Yoga-internal.h"
|
||||||
@@ -38,5 +38,7 @@ struct YGLayout {
|
|||||||
YGLayout();
|
YGLayout();
|
||||||
|
|
||||||
bool operator==(YGLayout layout) const;
|
bool operator==(YGLayout layout) const;
|
||||||
bool operator!=(YGLayout layout) const;
|
bool operator!=(YGLayout layout) const {
|
||||||
|
return !(*this == layout);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
236
yoga/YGNode.cpp
236
yoga/YGNode.cpp
@@ -1,93 +1,15 @@
|
|||||||
/**
|
/*
|
||||||
* 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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGNode.h"
|
#include "YGNode.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
void* YGNode::getContext() const {
|
using namespace facebook;
|
||||||
return context_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGPrintFunc YGNode::getPrintFunc() const {
|
|
||||||
return print_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool YGNode::getHasNewLayout() const {
|
|
||||||
return hasNewLayout_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeType YGNode::getNodeType() const {
|
|
||||||
return nodeType_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGMeasureFunc YGNode::getMeasure() const {
|
|
||||||
return measure_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGBaselineFunc YGNode::getBaseline() const {
|
|
||||||
return baseline_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGDirtiedFunc YGNode::getDirtied() const {
|
|
||||||
return dirtied_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGStyle& YGNode::getStyle() {
|
|
||||||
return style_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGLayout& YGNode::getLayout() {
|
|
||||||
return layout_;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t YGNode::getLineIndex() const {
|
|
||||||
return lineIndex_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeRef YGNode::getOwner() const {
|
|
||||||
return owner_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeRef YGNode::getParent() const {
|
|
||||||
return getOwner();
|
|
||||||
}
|
|
||||||
|
|
||||||
YGVector YGNode::getChildren() const {
|
|
||||||
return children_;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t YGNode::getChildrenCount() const {
|
|
||||||
return static_cast<uint32_t>(children_.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeRef YGNode::getChild(uint32_t index) const {
|
|
||||||
return children_.at(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNodeRef YGNode::getNextChild() const {
|
|
||||||
return nextChild_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGConfigRef YGNode::getConfig() const {
|
|
||||||
return config_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool YGNode::isDirty() const {
|
|
||||||
return isDirty_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGValue YGNode::getResolvedDimension(int index) {
|
|
||||||
return resolvedDimensions_[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<YGValue, 2> YGNode::getResolvedDimensions() const {
|
|
||||||
return resolvedDimensions_;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGFloatOptional YGNode::getLeadingPosition(
|
YGFloatOptional YGNode::getLeadingPosition(
|
||||||
const YGFlexDirection& axis,
|
const YGFlexDirection& axis,
|
||||||
@@ -177,30 +99,6 @@ YGFloatOptional YGNode::getMarginForAxis(
|
|||||||
|
|
||||||
// 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) {
|
||||||
measure_ = nullptr;
|
measure_ = nullptr;
|
||||||
@@ -221,38 +119,6 @@ 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::setOwner(YGNodeRef owner) {
|
|
||||||
owner_ = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNode::setChildren(const YGVector& children) {
|
|
||||||
children_ = children;
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNode::setNextChild(YGNodeRef nextChild) {
|
|
||||||
nextChild_ = nextChild;
|
|
||||||
}
|
|
||||||
|
|
||||||
void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
|
void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
|
||||||
children_[index] = child;
|
children_[index] = child;
|
||||||
setChildRoot(child);
|
setChildRoot(child);
|
||||||
@@ -268,10 +134,6 @@ void YGNode::insertChild(YGNodeRef child, uint32_t index) {
|
|||||||
setChildRoot(child);
|
setChildRoot(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;
|
||||||
@@ -395,80 +257,6 @@ void YGNode::setPosition(
|
|||||||
trailing[crossAxis]);
|
trailing[crossAxis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNode::YGNode()
|
|
||||||
: context_(nullptr),
|
|
||||||
print_(nullptr),
|
|
||||||
hasNewLayout_(true),
|
|
||||||
nodeType_(YGNodeTypeDefault),
|
|
||||||
measure_(nullptr),
|
|
||||||
baseline_(nullptr),
|
|
||||||
dirtied_(nullptr),
|
|
||||||
style_(YGStyle()),
|
|
||||||
layout_(YGLayout()),
|
|
||||||
lineIndex_(0),
|
|
||||||
owner_(nullptr),
|
|
||||||
children_(YGVector()),
|
|
||||||
nextChild_(nullptr),
|
|
||||||
config_(nullptr),
|
|
||||||
isDirty_(false),
|
|
||||||
resolvedDimensions_({{YGValueUndefined, YGValueUndefined}}) {}
|
|
||||||
|
|
||||||
YGNode::YGNode(const YGNode& node)
|
|
||||||
: context_(node.context_),
|
|
||||||
print_(node.print_),
|
|
||||||
hasNewLayout_(node.hasNewLayout_),
|
|
||||||
nodeType_(node.nodeType_),
|
|
||||||
measure_(node.measure_),
|
|
||||||
baseline_(node.baseline_),
|
|
||||||
dirtied_(node.dirtied_),
|
|
||||||
style_(node.style_),
|
|
||||||
layout_(node.layout_),
|
|
||||||
lineIndex_(node.lineIndex_),
|
|
||||||
owner_(node.owner_),
|
|
||||||
children_(node.children_),
|
|
||||||
nextChild_(node.nextChild_),
|
|
||||||
config_(node.config_),
|
|
||||||
isDirty_(node.isDirty_),
|
|
||||||
resolvedDimensions_(node.resolvedDimensions_) {}
|
|
||||||
|
|
||||||
YGNode::YGNode(const YGConfigRef newConfig) : YGNode() {
|
|
||||||
config_ = newConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
YGNode::YGNode(
|
|
||||||
void* context,
|
|
||||||
YGPrintFunc print,
|
|
||||||
bool hasNewLayout,
|
|
||||||
YGNodeType nodeType,
|
|
||||||
YGMeasureFunc measure,
|
|
||||||
YGBaselineFunc baseline,
|
|
||||||
YGDirtiedFunc dirtied,
|
|
||||||
YGStyle style,
|
|
||||||
const YGLayout& layout,
|
|
||||||
uint32_t lineIndex,
|
|
||||||
YGNodeRef owner,
|
|
||||||
const YGVector& children,
|
|
||||||
YGNodeRef nextChild,
|
|
||||||
YGConfigRef config,
|
|
||||||
bool isDirty,
|
|
||||||
std::array<YGValue, 2> resolvedDimensions)
|
|
||||||
: context_(context),
|
|
||||||
print_(print),
|
|
||||||
hasNewLayout_(hasNewLayout),
|
|
||||||
nodeType_(nodeType),
|
|
||||||
measure_(measure),
|
|
||||||
baseline_(baseline),
|
|
||||||
dirtied_(dirtied),
|
|
||||||
style_(style),
|
|
||||||
layout_(layout),
|
|
||||||
lineIndex_(lineIndex),
|
|
||||||
owner_(owner),
|
|
||||||
children_(children),
|
|
||||||
nextChild_(nextChild),
|
|
||||||
config_(config),
|
|
||||||
isDirty_(isDirty),
|
|
||||||
resolvedDimensions_(resolvedDimensions) {}
|
|
||||||
|
|
||||||
YGNode& YGNode::operator=(const YGNode& node) {
|
YGNode& YGNode::operator=(const YGNode& node) {
|
||||||
if (&node == this) {
|
if (&node == this) {
|
||||||
return *this;
|
return *this;
|
||||||
@@ -490,7 +278,6 @@ YGNode& YGNode::operator=(const YGNode& node) {
|
|||||||
lineIndex_ = node.getLineIndex();
|
lineIndex_ = node.getLineIndex();
|
||||||
owner_ = node.getOwner();
|
owner_ = node.getOwner();
|
||||||
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();
|
||||||
@@ -542,7 +329,7 @@ void YGNode::resolveDimension() {
|
|||||||
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) {
|
YGDirection YGNode::resolveDirection(const YGDirection ownerDirection) {
|
||||||
if (style_.direction == YGDirectionInherit) {
|
if (style_.direction == YGDirectionInherit) {
|
||||||
return ownerDirection > YGDirectionInherit ? ownerDirection
|
return ownerDirection > YGDirectionInherit ? ownerDirection
|
||||||
: YGDirectionLTR;
|
: YGDirectionLTR;
|
||||||
} else {
|
} else {
|
||||||
return style_.direction;
|
return style_.direction;
|
||||||
}
|
}
|
||||||
@@ -553,11 +340,6 @@ void YGNode::clearChildren() {
|
|||||||
children_.shrink_to_fit();
|
children_.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNode::~YGNode() {
|
|
||||||
// All the member variables are deallocated externally, so no need to
|
|
||||||
// deallocate here
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other Methods
|
// Other Methods
|
||||||
|
|
||||||
void YGNode::cloneChildrenIfNeeded() {
|
void YGNode::cloneChildrenIfNeeded() {
|
||||||
@@ -648,7 +430,7 @@ bool YGNode::isNodeFlexible() {
|
|||||||
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) &&
|
!yoga::isUndefined(style_.border[YGEdgeStart].value) &&
|
||||||
style_.border[YGEdgeStart].value >= 0.0f) {
|
style_.border[YGEdgeStart].value >= 0.0f) {
|
||||||
return style_.border[YGEdgeStart].value;
|
return style_.border[YGEdgeStart].value;
|
||||||
}
|
}
|
||||||
@@ -661,7 +443,7 @@ float YGNode::getLeadingBorder(const YGFlexDirection& axis) const {
|
|||||||
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) &&
|
!yoga::isUndefined(style_.border[YGEdgeEnd].value) &&
|
||||||
style_.border[YGEdgeEnd].value >= 0.0f) {
|
style_.border[YGEdgeEnd].value >= 0.0f) {
|
||||||
return style_.border[YGEdgeEnd].value;
|
return style_.border[YGEdgeEnd].value;
|
||||||
}
|
}
|
||||||
|
243
yoga/YGNode.h
243
yoga/YGNode.h
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "YGConfig.h"
|
#include "YGConfig.h"
|
||||||
@@ -14,83 +14,126 @@
|
|||||||
|
|
||||||
struct YGNode {
|
struct YGNode {
|
||||||
private:
|
private:
|
||||||
void* context_;
|
void* context_ = nullptr;
|
||||||
YGPrintFunc print_;
|
YGPrintFunc print_ = nullptr;
|
||||||
bool hasNewLayout_;
|
bool hasNewLayout_ = true;
|
||||||
YGNodeType nodeType_;
|
YGNodeType nodeType_ = YGNodeTypeDefault;
|
||||||
YGMeasureFunc measure_;
|
YGMeasureFunc measure_ = nullptr;
|
||||||
YGBaselineFunc baseline_;
|
YGBaselineFunc baseline_ = nullptr;
|
||||||
YGDirtiedFunc dirtied_;
|
YGDirtiedFunc dirtied_ = nullptr;
|
||||||
YGStyle style_;
|
YGStyle style_ = {};
|
||||||
YGLayout layout_;
|
YGLayout layout_ = {};
|
||||||
uint32_t lineIndex_;
|
uint32_t lineIndex_ = 0;
|
||||||
YGNodeRef owner_;
|
YGNodeRef owner_ = nullptr;
|
||||||
YGVector children_;
|
YGVector children_ = {};
|
||||||
YGNodeRef nextChild_;
|
YGConfigRef config_ = nullptr;
|
||||||
YGConfigRef config_;
|
bool isDirty_ = false;
|
||||||
bool isDirty_;
|
std::array<YGValue, 2> resolvedDimensions_ = {
|
||||||
std::array<YGValue, 2> resolvedDimensions_;
|
{YGValueUndefined, YGValueUndefined}};
|
||||||
|
|
||||||
YGFloatOptional relativePosition(
|
YGFloatOptional relativePosition(
|
||||||
const YGFlexDirection& axis,
|
const YGFlexDirection& axis,
|
||||||
const float& axisSize) const;
|
const float& axisSize) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YGNode();
|
YGNode() = default;
|
||||||
~YGNode();
|
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
||||||
explicit YGNode(const YGConfigRef newConfig);
|
explicit YGNode(const YGConfigRef newConfig) : config_(newConfig){};
|
||||||
YGNode(const YGNode& node);
|
YGNode(const YGNode& node) = default;
|
||||||
YGNode& operator=(const YGNode& node);
|
YGNode& operator=(const YGNode& node);
|
||||||
YGNode(
|
|
||||||
void* context,
|
|
||||||
YGPrintFunc print,
|
|
||||||
bool hasNewLayout,
|
|
||||||
YGNodeType nodeType,
|
|
||||||
YGMeasureFunc measure,
|
|
||||||
YGBaselineFunc baseline,
|
|
||||||
YGDirtiedFunc dirtied,
|
|
||||||
YGStyle style,
|
|
||||||
const YGLayout& layout,
|
|
||||||
uint32_t lineIndex,
|
|
||||||
YGNodeRef owner,
|
|
||||||
const YGVector& children,
|
|
||||||
YGNodeRef nextChild,
|
|
||||||
YGConfigRef config,
|
|
||||||
bool isDirty,
|
|
||||||
std::array<YGValue, 2> resolvedDimensions);
|
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
void* getContext() const;
|
void* getContext() const {
|
||||||
YGPrintFunc getPrintFunc() const;
|
return context_;
|
||||||
bool getHasNewLayout() const;
|
}
|
||||||
YGNodeType getNodeType() const;
|
|
||||||
YGMeasureFunc getMeasure() const;
|
YGPrintFunc getPrintFunc() const {
|
||||||
YGBaselineFunc getBaseline() const;
|
return print_;
|
||||||
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() {
|
||||||
uint32_t getLineIndex() const;
|
return layout_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const YGLayout& getLayout() const {
|
||||||
|
return layout_;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t getLineIndex() const {
|
||||||
|
return lineIndex_;
|
||||||
|
}
|
||||||
|
|
||||||
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
// returns the YGNodeRef that owns this YGNode. An owner is used to identify
|
||||||
// the YogaTree that a YGNode belongs to.
|
// the YogaTree that a YGNode belongs to.
|
||||||
// This method will return the parent of the YGNode when a YGNode only belongs
|
// 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
|
// to one YogaTree or nullptr when the YGNode is shared between two or more
|
||||||
// YogaTrees.
|
// YogaTrees.
|
||||||
YGNodeRef getOwner() const;
|
YGNodeRef getOwner() const {
|
||||||
|
return owner_;
|
||||||
|
}
|
||||||
|
|
||||||
// Deprecated, use getOwner() instead.
|
// Deprecated, use getOwner() instead.
|
||||||
YGNodeRef getParent() const;
|
YGNodeRef getParent() const {
|
||||||
YGVector getChildren() const;
|
return getOwner();
|
||||||
uint32_t getChildrenCount() const;
|
}
|
||||||
YGNodeRef getChild(uint32_t index) const;
|
|
||||||
YGNodeRef getNextChild() const;
|
const YGVector& getChildren() const {
|
||||||
YGConfigRef getConfig() const;
|
return children_;
|
||||||
bool isDirty() const;
|
}
|
||||||
std::array<YGValue, 2> getResolvedDimensions() const;
|
|
||||||
YGValue getResolvedDimension(int index);
|
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,
|
YGFloatOptional 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;
|
||||||
@@ -122,22 +165,66 @@ struct YGNode {
|
|||||||
const float& widthSize) const;
|
const float& widthSize) const;
|
||||||
// Setters
|
// Setters
|
||||||
|
|
||||||
void setContext(void* context);
|
void setContext(void* context) {
|
||||||
void setPrintFunc(YGPrintFunc printFunc);
|
context_ = context;
|
||||||
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 setDirtiedFunc(YGDirtiedFunc dirtiedFunc);
|
void setBaseLineFunc(YGBaselineFunc baseLineFunc) {
|
||||||
void setStyle(const YGStyle& style);
|
baseline_ = baseLineFunc;
|
||||||
void setStyleFlexDirection(YGFlexDirection direction);
|
}
|
||||||
void setStyleAlignContent(YGAlign alignContent);
|
|
||||||
void setLayout(const YGLayout& layout);
|
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) {
|
||||||
void setLineIndex(uint32_t lineIndex);
|
dirtied_ = dirtiedFunc;
|
||||||
void setOwner(YGNodeRef owner);
|
}
|
||||||
void setChildren(const YGVector& children);
|
|
||||||
void setNextChild(YGNodeRef nextChild);
|
void setStyle(const YGStyle& style) {
|
||||||
void setConfig(YGConfigRef config);
|
style_ = style;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLayout(const YGLayout& layout) {
|
||||||
|
layout_ = layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLineIndex(uint32_t lineIndex) {
|
||||||
|
lineIndex_ = lineIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setOwner(YGNodeRef owner) {
|
||||||
|
owner_ = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChildren(const YGVector& children) {
|
||||||
|
children_ = children;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: rvalue override for setChildren
|
||||||
|
|
||||||
|
void setConfig(YGConfigRef config) {
|
||||||
|
config_ = config;
|
||||||
|
}
|
||||||
|
|
||||||
void setDirty(bool isDirty);
|
void setDirty(bool isDirty);
|
||||||
void setLayoutLastOwnerDirection(YGDirection direction);
|
void setLayoutLastOwnerDirection(YGDirection direction);
|
||||||
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis);
|
void setLayoutComputedFlexBasis(const YGFloatOptional& computedFlexBasis);
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "YGStyle.h"
|
#include "YGStyle.h"
|
||||||
|
|
||||||
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
|
const YGValue kYGValueUndefined = {0, YGUnitUndefined};
|
||||||
@@ -98,9 +98,3 @@ bool YGStyle::operator==(const YGStyle& style) {
|
|||||||
|
|
||||||
return areNonFloatValuesEqual;
|
return areNonFloatValuesEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool YGStyle::operator!=(YGStyle style) {
|
|
||||||
return !(*this == style);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGStyle::~YGStyle() {}
|
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "YGFloatOptional.h"
|
#include "YGFloatOptional.h"
|
||||||
#include "Yoga-internal.h"
|
#include "Yoga-internal.h"
|
||||||
@@ -32,12 +32,14 @@ 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;
|
||||||
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
YGFloatOptional aspectRatio;
|
YGFloatOptional aspectRatio;
|
||||||
|
|
||||||
YGStyle();
|
YGStyle();
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
|
||||||
bool operator==(const YGStyle& style);
|
bool operator==(const YGStyle& style);
|
||||||
|
|
||||||
bool operator!=(YGStyle style);
|
bool operator!=(YGStyle style) {
|
||||||
~YGStyle();
|
return !(*this == style);
|
||||||
|
}
|
||||||
|
~YGStyle() = default;
|
||||||
};
|
};
|
||||||
|
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
@@ -16,13 +16,34 @@ using YGVector = std::vector<YGNodeRef>;
|
|||||||
|
|
||||||
YG_EXTERN_C_BEGIN
|
YG_EXTERN_C_BEGIN
|
||||||
|
|
||||||
WIN_EXPORT float YGRoundValueToPixelGrid(const float value,
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||||
const float pointScaleFactor,
|
const float value,
|
||||||
const bool forceCeil,
|
const float pointScaleFactor,
|
||||||
const bool forceFloor);
|
const bool forceCeil,
|
||||||
|
const bool forceFloor);
|
||||||
|
|
||||||
YG_EXTERN_C_END
|
YG_EXTERN_C_END
|
||||||
|
|
||||||
|
namespace facebook {
|
||||||
|
namespace yoga {
|
||||||
|
|
||||||
|
inline bool isUndefined(float value) {
|
||||||
|
// Value of a float in the case of it being not defined is 10.1E20. Earlier
|
||||||
|
// it used to be NAN, the benefit of which was that if NAN is involved in any
|
||||||
|
// mathematical expression the result was NAN. But since we want to have
|
||||||
|
// `-ffast-math` flag being used by compiler which assumes that the floating
|
||||||
|
// point values are not NAN and Inf, we represent YGUndefined as 10.1E20. But
|
||||||
|
// now if YGUndefined is involved in any mathematical operations this
|
||||||
|
// value(10.1E20) would change. So the following check makes sure that if the
|
||||||
|
// value is outside a range (-10E8, 10E8) then it is undefined.
|
||||||
|
return value >= 10E8 || value <= -10E8;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yoga
|
||||||
|
} // namespace facebook
|
||||||
|
|
||||||
|
using namespace facebook;
|
||||||
|
|
||||||
extern const std::array<YGEdge, 4> trailing;
|
extern const std::array<YGEdge, 4> trailing;
|
||||||
extern const std::array<YGEdge, 4> leading;
|
extern const std::array<YGEdge, 4> leading;
|
||||||
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
extern bool YGValueEqual(const YGValue a, const YGValue b);
|
||||||
@@ -62,20 +83,20 @@ struct YGCachedMeasurement {
|
|||||||
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
bool isEqual = widthMeasureMode == measurement.widthMeasureMode &&
|
||||||
heightMeasureMode == measurement.heightMeasureMode;
|
heightMeasureMode == measurement.heightMeasureMode;
|
||||||
|
|
||||||
if (!YGFloatIsUndefined(availableWidth) ||
|
if (!yoga::isUndefined(availableWidth) ||
|
||||||
!YGFloatIsUndefined(measurement.availableWidth)) {
|
!yoga::isUndefined(measurement.availableWidth)) {
|
||||||
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(availableHeight) ||
|
if (!yoga::isUndefined(availableHeight) ||
|
||||||
!YGFloatIsUndefined(measurement.availableHeight)) {
|
!yoga::isUndefined(measurement.availableHeight)) {
|
||||||
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(computedWidth) ||
|
if (!yoga::isUndefined(computedWidth) ||
|
||||||
!YGFloatIsUndefined(measurement.computedWidth)) {
|
!yoga::isUndefined(measurement.computedWidth)) {
|
||||||
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
||||||
}
|
}
|
||||||
if (!YGFloatIsUndefined(computedHeight) ||
|
if (!yoga::isUndefined(computedHeight) ||
|
||||||
!YGFloatIsUndefined(measurement.computedHeight)) {
|
!yoga::isUndefined(measurement.computedHeight)) {
|
||||||
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +108,6 @@ struct YGCachedMeasurement {
|
|||||||
// layouts should not require more than 16 entries to fit within the cache.
|
// 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
|
||||||
|
|
||||||
|
|
||||||
static const float kDefaultFlexGrow = 0.0f;
|
static const float kDefaultFlexGrow = 0.0f;
|
||||||
static const float kDefaultFlexShrink = 0.0f;
|
static const float kDefaultFlexShrink = 0.0f;
|
||||||
static const float kWebDefaultFlexShrink = 1.0f;
|
static const float kWebDefaultFlexShrink = 1.0f;
|
||||||
|
1297
yoga/Yoga.cpp
1297
yoga/Yoga.cpp
File diff suppressed because it is too large
Load Diff
449
yoga/Yoga.h
449
yoga/Yoga.h
@@ -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
|
||||||
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -45,23 +45,33 @@ typedef struct YGValue {
|
|||||||
extern const YGValue YGValueUndefined;
|
extern const YGValue YGValueUndefined;
|
||||||
extern const YGValue YGValueAuto;
|
extern const YGValue YGValueAuto;
|
||||||
|
|
||||||
typedef struct YGConfig *YGConfigRef;
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
extern bool operator==(const YGValue& lhs, const YGValue& rhs);
|
||||||
|
extern bool operator!=(const YGValue& lhs, const YGValue& rhs);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct YGConfig* YGConfigRef;
|
||||||
|
|
||||||
typedef struct YGNode* YGNodeRef;
|
typedef struct YGNode* YGNodeRef;
|
||||||
|
|
||||||
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
typedef YGSize (*YGMeasureFunc)(
|
||||||
float width,
|
YGNodeRef node,
|
||||||
YGMeasureMode widthMode,
|
float width,
|
||||||
float height,
|
YGMeasureMode widthMode,
|
||||||
YGMeasureMode heightMode);
|
float height,
|
||||||
typedef float (*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
|
YGMeasureMode heightMode);
|
||||||
|
typedef float (
|
||||||
|
*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
|
||||||
typedef void (*YGDirtiedFunc)(YGNodeRef node);
|
typedef void (*YGDirtiedFunc)(YGNodeRef node);
|
||||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||||
typedef int (*YGLogger)(const YGConfigRef config,
|
typedef int (*YGLogger)(
|
||||||
const YGNodeRef node,
|
const YGConfigRef config,
|
||||||
YGLogLevel level,
|
const YGNodeRef node,
|
||||||
const char *format,
|
YGLogLevel level,
|
||||||
va_list args);
|
const char* format,
|
||||||
|
va_list args);
|
||||||
typedef YGNodeRef (
|
typedef YGNodeRef (
|
||||||
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
|
*YGCloneNodeFunc)(YGNodeRef oldNode, YGNodeRef owner, int childIndex);
|
||||||
|
|
||||||
@@ -74,9 +84,10 @@ WIN_EXPORT void YGNodeFreeRecursive(const YGNodeRef node);
|
|||||||
WIN_EXPORT void YGNodeReset(const YGNodeRef node);
|
WIN_EXPORT void YGNodeReset(const YGNodeRef node);
|
||||||
WIN_EXPORT int32_t YGNodeGetInstanceCount(void);
|
WIN_EXPORT int32_t YGNodeGetInstanceCount(void);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeInsertChild(const YGNodeRef node,
|
WIN_EXPORT void YGNodeInsertChild(
|
||||||
const YGNodeRef child,
|
const YGNodeRef node,
|
||||||
const uint32_t index);
|
const YGNodeRef child,
|
||||||
|
const uint32_t index);
|
||||||
|
|
||||||
// This function inserts the child YGNodeRef as a children of the node received
|
// 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
|
// by parameter and set the Owner of the child object to null. This function is
|
||||||
@@ -99,10 +110,11 @@ WIN_EXPORT void YGNodeSetChildren(
|
|||||||
const YGNodeRef children[],
|
const YGNodeRef children[],
|
||||||
const uint32_t count);
|
const uint32_t count);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
WIN_EXPORT void YGNodeCalculateLayout(
|
||||||
const float availableWidth,
|
const YGNodeRef node,
|
||||||
const float availableHeight,
|
const float availableWidth,
|
||||||
const YGDirection ownerDirection);
|
const float availableHeight,
|
||||||
|
const YGDirection ownerDirection);
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -112,70 +124,34 @@ WIN_EXPORT void YGNodeCalculateLayout(const YGNodeRef node,
|
|||||||
// marking manually.
|
// marking manually.
|
||||||
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
|
WIN_EXPORT void YGNodeMarkDirty(const YGNodeRef node);
|
||||||
|
|
||||||
// This function marks the current node and all its descendants as dirty. This function is added to test yoga benchmarks.
|
// This function marks the current node and all its descendants as dirty. This
|
||||||
// This function is not expected to be used in production as calling `YGCalculateLayout` will cause the recalculation of each and every node.
|
// function is added to test yoga benchmarks. This function is not expected to
|
||||||
|
// be used in production as calling `YGCalculateLayout` will cause the
|
||||||
|
// recalculation of each and every node.
|
||||||
WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node);
|
WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(const YGNodeRef node);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
WIN_EXPORT void YGNodePrint(const YGNodeRef node, const YGPrintOptions options);
|
||||||
|
|
||||||
WIN_EXPORT bool YGFloatIsUndefined(const float value);
|
WIN_EXPORT bool YGFloatIsUndefined(const float value);
|
||||||
|
|
||||||
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(const YGMeasureMode widthMode,
|
WIN_EXPORT bool YGNodeCanUseCachedMeasurement(
|
||||||
const float width,
|
const YGMeasureMode widthMode,
|
||||||
const YGMeasureMode heightMode,
|
const float width,
|
||||||
const float height,
|
const YGMeasureMode heightMode,
|
||||||
const YGMeasureMode lastWidthMode,
|
const float height,
|
||||||
const float lastWidth,
|
const YGMeasureMode lastWidthMode,
|
||||||
const YGMeasureMode lastHeightMode,
|
const float lastWidth,
|
||||||
const float lastHeight,
|
const YGMeasureMode lastHeightMode,
|
||||||
const float lastComputedWidth,
|
const float lastHeight,
|
||||||
const float lastComputedHeight,
|
const float lastComputedWidth,
|
||||||
const float marginRow,
|
const float lastComputedHeight,
|
||||||
const float marginColumn,
|
const float marginRow,
|
||||||
const YGConfigRef config);
|
const float marginColumn,
|
||||||
|
const YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode);
|
WIN_EXPORT void YGNodeCopyStyle(
|
||||||
|
const YGNodeRef dstNode,
|
||||||
#define YG_NODE_PROPERTY(type, name, paramName) \
|
const YGNodeRef srcNode);
|
||||||
WIN_EXPORT void YGNodeSet##name(const YGNodeRef node, type paramName); \
|
|
||||||
WIN_EXPORT type YGNodeGet##name(const YGNodeRef node);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY(type, name, paramName) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const type paramName); \
|
|
||||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, const float paramName); \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, const float paramName); \
|
|
||||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_PROPERTY_UNIT_AUTO(type, name, paramName) \
|
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT(type, name, paramName) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
|
||||||
const YGEdge edge, \
|
|
||||||
const type paramName); \
|
|
||||||
WIN_EXPORT type YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT(type, name, paramName) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name(const YGNodeRef node, \
|
|
||||||
const YGEdge edge, \
|
|
||||||
const float paramName); \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name##Percent(const YGNodeRef node, \
|
|
||||||
const YGEdge edge, \
|
|
||||||
const float paramName); \
|
|
||||||
WIN_EXPORT WIN_STRUCT(type) YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge);
|
|
||||||
|
|
||||||
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(type, name) \
|
|
||||||
WIN_EXPORT void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge);
|
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_PROPERTY(type, name) \
|
|
||||||
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node);
|
|
||||||
|
|
||||||
#define YG_NODE_LAYOUT_EDGE_PROPERTY(type, name) \
|
|
||||||
WIN_EXPORT type YGNodeLayoutGet##name(const YGNodeRef node, const YGEdge edge);
|
|
||||||
|
|
||||||
void* YGNodeGetContext(YGNodeRef node);
|
void* YGNodeGetContext(YGNodeRef node);
|
||||||
void YGNodeSetContext(YGNodeRef node, void* context);
|
void YGNodeSetContext(YGNodeRef node, void* context);
|
||||||
@@ -194,90 +170,240 @@ void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
|
|||||||
bool YGNodeIsDirty(YGNodeRef node);
|
bool YGNodeIsDirty(YGNodeRef node);
|
||||||
bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node);
|
bool YGNodeLayoutGetDidUseLegacyFlag(const YGNodeRef node);
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGDirection, Direction, direction);
|
WIN_EXPORT void YGNodeStyleSetDirection(
|
||||||
YG_NODE_STYLE_PROPERTY(YGFlexDirection, FlexDirection, flexDirection);
|
const YGNodeRef node,
|
||||||
YG_NODE_STYLE_PROPERTY(YGJustify, JustifyContent, justifyContent);
|
const YGDirection direction);
|
||||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignContent, alignContent);
|
WIN_EXPORT YGDirection YGNodeStyleGetDirection(const YGNodeRef node);
|
||||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignItems, alignItems);
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGAlign, AlignSelf, alignSelf);
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGPositionType, PositionType, positionType);
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGWrap, FlexWrap, flexWrap);
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGOverflow, Overflow, overflow);
|
|
||||||
YG_NODE_STYLE_PROPERTY(YGDisplay, Display, display);
|
|
||||||
YG_NODE_STYLE_PROPERTY(float, Flex, flex);
|
|
||||||
YG_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
|
|
||||||
YG_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
|
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, FlexBasis, flexBasis);
|
|
||||||
|
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Position, position);
|
WIN_EXPORT void YGNodeStyleSetFlexDirection(
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Margin, margin);
|
const YGNodeRef node,
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO(YGValue, Margin);
|
const YGFlexDirection flexDirection);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY_UNIT(YGValue, Padding, padding);
|
WIN_EXPORT YGFlexDirection YGNodeStyleGetFlexDirection(const YGNodeRef node);
|
||||||
YG_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
|
|
||||||
|
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Width, width);
|
WIN_EXPORT void YGNodeStyleSetJustifyContent(
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT_AUTO(YGValue, Height, height);
|
const YGNodeRef node,
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinWidth, minWidth);
|
const YGJustify justifyContent);
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MinHeight, minHeight);
|
WIN_EXPORT YGJustify YGNodeStyleGetJustifyContent(const YGNodeRef node);
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxWidth, maxWidth);
|
|
||||||
YG_NODE_STYLE_PROPERTY_UNIT(YGValue, MaxHeight, maxHeight);
|
WIN_EXPORT void YGNodeStyleSetAlignContent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGAlign alignContent);
|
||||||
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignContent(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetAlignItems(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGAlign alignItems);
|
||||||
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignItems(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetAlignSelf(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGAlign alignSelf);
|
||||||
|
WIN_EXPORT YGAlign YGNodeStyleGetAlignSelf(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetPositionType(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGPositionType positionType);
|
||||||
|
WIN_EXPORT YGPositionType YGNodeStyleGetPositionType(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexWrap(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGWrap flexWrap);
|
||||||
|
WIN_EXPORT YGWrap YGNodeStyleGetFlexWrap(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetOverflow(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGOverflow overflow);
|
||||||
|
WIN_EXPORT YGOverflow YGNodeStyleGetOverflow(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetDisplay(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGDisplay display);
|
||||||
|
WIN_EXPORT YGDisplay YGNodeStyleGetDisplay(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlex(const YGNodeRef node, const float flex);
|
||||||
|
WIN_EXPORT float YGNodeStyleGetFlex(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexGrow(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float flexGrow);
|
||||||
|
WIN_EXPORT float YGNodeStyleGetFlexGrow(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexShrink(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float flexShrink);
|
||||||
|
WIN_EXPORT float YGNodeStyleGetFlexShrink(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexBasis(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float flexBasis);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexBasisPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float flexBasis);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetFlexBasis(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetPosition(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float position);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetPositionPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float position);
|
||||||
|
WIN_EXPORT WIN_STRUCT(YGValue)
|
||||||
|
YGNodeStyleGetPosition(const YGNodeRef node, const YGEdge edge);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMargin(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float margin);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMarginPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float margin);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMarginAuto(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge);
|
||||||
|
WIN_EXPORT YGValue
|
||||||
|
YGNodeStyleGetMargin(const YGNodeRef node, const YGEdge edge);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetPadding(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float padding);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetPaddingPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float padding);
|
||||||
|
WIN_EXPORT YGValue
|
||||||
|
YGNodeStyleGetPadding(const YGNodeRef node, const YGEdge edge);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetBorder(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge,
|
||||||
|
const float border);
|
||||||
|
WIN_EXPORT float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetWidth(const YGNodeRef node, const float width);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetWidthPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float width);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetWidthAuto(const YGNodeRef node);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetWidth(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetHeight(const YGNodeRef node, const float height);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetHeightPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float height);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetHeightAuto(const YGNodeRef node);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetHeight(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMinWidth(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float minWidth);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMinWidthPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float minWidth);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetMinWidth(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMinHeight(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float minHeight);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMinHeightPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float minHeight);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetMinHeight(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMaxWidth(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float maxWidth);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMaxWidthPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float maxWidth);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetMaxWidth(const YGNodeRef node);
|
||||||
|
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMaxHeight(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float maxHeight);
|
||||||
|
WIN_EXPORT void YGNodeStyleSetMaxHeightPercent(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float maxHeight);
|
||||||
|
WIN_EXPORT YGValue YGNodeStyleGetMaxHeight(const YGNodeRef node);
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
// Aspect ratio control the size of the undefined dimension of a node.
|
// Aspect ratio control the size of the undefined dimension of a node.
|
||||||
// Aspect ratio is encoded as a floating point value width/height. e.g. A value of 2 leads to a node
|
// Aspect ratio is encoded as a floating point value width/height. e.g. A value
|
||||||
// with a width twice the size of its height while a value of 0.5 gives the opposite effect.
|
// of 2 leads to a node with a width twice the size of its height while a value
|
||||||
|
// of 0.5 gives the opposite effect.
|
||||||
//
|
//
|
||||||
// - On a node with a set width/height aspect ratio control the size of the unset dimension
|
// - On a node with a set width/height aspect ratio control the size of the
|
||||||
// - On a node with a set flex basis aspect ratio controls the size of the node in the cross axis if
|
// unset dimension
|
||||||
// unset
|
// - On a node with a set flex basis aspect ratio controls the size of the node
|
||||||
// - On a node with a measure function aspect ratio works as though the measure function measures
|
// in the cross axis if unset
|
||||||
// the flex basis
|
// - On a node with a measure function aspect ratio works as though the measure
|
||||||
// - On a node with flex grow/shrink aspect ratio controls the size of the node in the cross axis if
|
// function measures the flex basis
|
||||||
// unset
|
// - On a node with flex grow/shrink aspect ratio controls the size of the node
|
||||||
|
// in the cross axis if unset
|
||||||
// - Aspect ratio takes min/max dimensions into account
|
// - Aspect ratio takes min/max dimensions into account
|
||||||
YG_NODE_STYLE_PROPERTY(float, AspectRatio, aspectRatio);
|
WIN_EXPORT void YGNodeStyleSetAspectRatio(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const float aspectRatio);
|
||||||
|
WIN_EXPORT float YGNodeStyleGetAspectRatio(const YGNodeRef node);
|
||||||
|
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Left);
|
WIN_EXPORT float YGNodeLayoutGetLeft(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Top);
|
WIN_EXPORT float YGNodeLayoutGetTop(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Right);
|
WIN_EXPORT float YGNodeLayoutGetRight(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Bottom);
|
WIN_EXPORT float YGNodeLayoutGetBottom(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Width);
|
WIN_EXPORT float YGNodeLayoutGetWidth(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(float, Height);
|
WIN_EXPORT float YGNodeLayoutGetHeight(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
|
WIN_EXPORT YGDirection YGNodeLayoutGetDirection(const YGNodeRef node);
|
||||||
YG_NODE_LAYOUT_PROPERTY(bool, HadOverflow);
|
WIN_EXPORT bool YGNodeLayoutGetHadOverflow(const YGNodeRef node);
|
||||||
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node);
|
bool YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(const YGNodeRef node);
|
||||||
|
|
||||||
// Get the computed values for these nodes after performing layout. If they were set using
|
// Get the computed values for these nodes after performing layout. If they were
|
||||||
// point values then the returned value will be the same as YGNodeStyleGetXXX. However if
|
// set using point values then the returned value will be the same as
|
||||||
// they were set using a percentage value then the returned value is the computed value used
|
// YGNodeStyleGetXXX. However if they were set using a percentage value then the
|
||||||
// during layout.
|
// returned value is the computed value used during layout.
|
||||||
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);
|
WIN_EXPORT float YGNodeLayoutGetMargin(const YGNodeRef node, const YGEdge edge);
|
||||||
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Border);
|
WIN_EXPORT float YGNodeLayoutGetBorder(const YGNodeRef node, const YGEdge edge);
|
||||||
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Padding);
|
WIN_EXPORT float YGNodeLayoutGetPadding(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const YGEdge edge);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
|
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
|
||||||
WIN_EXPORT void YGLog(const YGNodeRef node, YGLogLevel level, const char *message, ...);
|
WIN_EXPORT void
|
||||||
WIN_EXPORT void YGLogWithConfig(const YGConfigRef config, YGLogLevel level, const char *format, ...);
|
YGLog(const YGNodeRef node, YGLogLevel level, const char* message, ...);
|
||||||
WIN_EXPORT void YGAssert(const bool condition, const char *message);
|
WIN_EXPORT void YGLogWithConfig(
|
||||||
WIN_EXPORT void YGAssertWithNode(const YGNodeRef node, const bool condition, const char *message);
|
const YGConfigRef config,
|
||||||
WIN_EXPORT void YGAssertWithConfig(const YGConfigRef config,
|
YGLogLevel level,
|
||||||
const bool condition,
|
const char* format,
|
||||||
const char *message);
|
...);
|
||||||
|
WIN_EXPORT void YGAssert(const bool condition, const char* message);
|
||||||
|
WIN_EXPORT void YGAssertWithNode(
|
||||||
|
const YGNodeRef node,
|
||||||
|
const bool condition,
|
||||||
|
const char* message);
|
||||||
|
WIN_EXPORT void YGAssertWithConfig(
|
||||||
|
const YGConfigRef config,
|
||||||
|
const bool condition,
|
||||||
|
const char* message);
|
||||||
// Set this to number of pixels in 1 point to round calculation results
|
// Set this to number of pixels in 1 point to round calculation results
|
||||||
// If you want to avoid rounding - set PointScaleFactor to 0
|
// If you want to avoid rounding - set PointScaleFactor to 0
|
||||||
WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const float pixelsInPoint);
|
WIN_EXPORT void YGConfigSetPointScaleFactor(
|
||||||
|
const YGConfigRef config,
|
||||||
|
const float pixelsInPoint);
|
||||||
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||||
const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool shouldDiffLayout);
|
const bool shouldDiffLayout);
|
||||||
|
|
||||||
// Yoga previously had an error where containers would take the maximum space possible instead of
|
// Yoga previously had an error where containers would take the maximum space
|
||||||
// the minimum
|
// possible instead of the minimum like they are supposed to. In practice this
|
||||||
// like they are supposed to. In practice this resulted in implicit behaviour similar to align-self:
|
// resulted in implicit behaviour similar to align-self: stretch; Because this
|
||||||
// stretch;
|
// was such a long-standing bug we must allow legacy users to switch back to
|
||||||
// Because this was such a long-standing bug we must allow legacy users to switch back to this
|
// this behaviour.
|
||||||
// behaviour.
|
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(
|
||||||
WIN_EXPORT void YGConfigSetUseLegacyStretchBehaviour(const YGConfigRef config,
|
const YGConfigRef config,
|
||||||
const bool useLegacyStretchBehaviour);
|
const bool useLegacyStretchBehaviour);
|
||||||
|
|
||||||
// YGConfig
|
// YGConfig
|
||||||
WIN_EXPORT YGConfigRef YGConfigNew(void);
|
WIN_EXPORT YGConfigRef YGConfigNew(void);
|
||||||
@@ -285,25 +411,30 @@ WIN_EXPORT void YGConfigFree(const YGConfigRef config);
|
|||||||
WIN_EXPORT void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src);
|
WIN_EXPORT void YGConfigCopy(const YGConfigRef dest, const YGConfigRef src);
|
||||||
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
|
WIN_EXPORT int32_t YGConfigGetInstanceCount(void);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config,
|
WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(
|
||||||
const YGExperimentalFeature feature,
|
const YGConfigRef config,
|
||||||
const bool enabled);
|
const YGExperimentalFeature feature,
|
||||||
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(const YGConfigRef config,
|
const bool enabled);
|
||||||
const YGExperimentalFeature feature);
|
WIN_EXPORT bool YGConfigIsExperimentalFeatureEnabled(
|
||||||
|
const YGConfigRef config,
|
||||||
|
const YGExperimentalFeature feature);
|
||||||
|
|
||||||
// Using the web defaults is the prefered configuration for new projects.
|
// Using the web defaults is the prefered configuration for new projects.
|
||||||
// Usage of non web defaults should be considered as legacy.
|
// Usage of non web defaults should be considered as legacy.
|
||||||
WIN_EXPORT void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled);
|
WIN_EXPORT void YGConfigSetUseWebDefaults(
|
||||||
|
const YGConfigRef config,
|
||||||
|
const bool enabled);
|
||||||
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
WIN_EXPORT bool YGConfigGetUseWebDefaults(const YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetCloneNodeFunc(const YGConfigRef config,
|
WIN_EXPORT void YGConfigSetCloneNodeFunc(
|
||||||
const YGCloneNodeFunc callback);
|
const YGConfigRef config,
|
||||||
|
const YGCloneNodeFunc callback);
|
||||||
|
|
||||||
// Export only for C#
|
// Export only for C#
|
||||||
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
|
||||||
|
|
||||||
WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void *context);
|
WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void* context);
|
||||||
WIN_EXPORT void *YGConfigGetContext(const YGConfigRef config);
|
WIN_EXPORT void* YGConfigGetContext(const YGConfigRef config);
|
||||||
|
|
||||||
WIN_EXPORT float YGRoundValueToPixelGrid(
|
WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||||
const float value,
|
const float value,
|
||||||
@@ -319,7 +450,9 @@ YG_EXTERN_C_END
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// 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 owner,
|
YGNodeRef const owner,
|
||||||
|
@@ -190,3 +190,43 @@ def yoga_prebuilt_jar(*args, **kwargs):
|
|||||||
|
|
||||||
def is_apple_platform():
|
def is_apple_platform():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def yoga_apple_binary():
|
||||||
|
if is_apple_platform():
|
||||||
|
yoganet_ios_srcs = []
|
||||||
|
for arch in [
|
||||||
|
"iphonesimulator-x86_64",
|
||||||
|
"iphoneos-arm64",
|
||||||
|
]:
|
||||||
|
name = "yoganet-" + arch
|
||||||
|
yoganet_ios_srcs.append(":" + name)
|
||||||
|
native.genrule(
|
||||||
|
name = name,
|
||||||
|
srcs = [
|
||||||
|
yoga_dep(":yogaApple#%s,static" % arch),
|
||||||
|
yoga_dep("YogaKit:YogaKitApple#%s,static" % arch),
|
||||||
|
yoga_dep("csharp:yoganetApple#%s,static" % arch),
|
||||||
|
],
|
||||||
|
out = "libyoga-%s.a" % arch,
|
||||||
|
cmd = "libtool -static -o $OUT $SRCS",
|
||||||
|
visibility = [yoga_dep("csharp:yoganet-ios")],
|
||||||
|
)
|
||||||
|
|
||||||
|
native.genrule(
|
||||||
|
name = "yoganet-ios",
|
||||||
|
srcs = yoganet_ios_srcs,
|
||||||
|
out = "libyoga.a",
|
||||||
|
cmd = "lipo $SRCS -create -output $OUT",
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
)
|
||||||
|
|
||||||
|
yoganet_macosx_target = "csharp:yoganetAppleMac#macosx-%s,dynamic"
|
||||||
|
native.genrule(
|
||||||
|
name = "yoganet-macosx",
|
||||||
|
srcs = [
|
||||||
|
yoga_dep(yoganet_macosx_target % "x86_64"),
|
||||||
|
],
|
||||||
|
out = "libyoga.dylib",
|
||||||
|
cmd = "lipo $SRCS -create -output $OUT",
|
||||||
|
visibility = ["PUBLIC"],
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user