Compare commits
57 Commits
1.11.0
...
1.12.0-pre
Author | SHA1 | Date | |
---|---|---|---|
|
5bb2265083 | ||
|
ab3bf40c7d | ||
|
f273e80c77 | ||
|
1471be54e3 | ||
|
f039835249 | ||
|
f793ba2d6b | ||
|
9f72ad05ce | ||
|
14f3827491 | ||
|
0d96098fd9 | ||
|
42e3b78f04 | ||
|
3ad49d27d9 | ||
|
3331a9e480 | ||
|
7890672ecc | ||
|
d7bfbf3646 | ||
|
6d271c05f6 | ||
|
a9bddf87ff | ||
|
88994129ae | ||
|
888892885e | ||
|
de79f2a1d4 | ||
|
6368416178 | ||
|
a935a222b5 | ||
|
7c4da0a341 | ||
|
b047af25ca | ||
|
2abd9dd91b | ||
|
afadc5cf6b | ||
|
8823cc357a | ||
|
8b8d9a05b7 | ||
|
15668aceb6 | ||
|
e25fe994b3 | ||
|
47abe1c482 | ||
|
95169c3150 | ||
|
7331de78bd | ||
|
05f36a835a | ||
|
dcd9438488 | ||
|
d38db1292c | ||
|
4463fe0856 | ||
|
2156de5fb5 | ||
|
b1c749075d | ||
|
367a93de88 | ||
|
2643b96589 | ||
|
016a10df26 | ||
|
cbcf07f08a | ||
|
59bcac3289 | ||
|
bd90192df9 | ||
|
e7fcf1ee65 | ||
|
f86c74ce7e | ||
|
d5ad51bccc | ||
|
0bdf36f5d1 | ||
|
1b9053bc5d | ||
|
446101a168 | ||
|
f0324035bf | ||
|
a2f94cbf9a | ||
|
d21fa68033 | ||
|
5a6d84abc9 | ||
|
61ae484316 | ||
|
42657017bd | ||
|
9b9a344934 |
18
BUCK
18
BUCK
@@ -15,12 +15,12 @@ COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
||||
|
||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
|
||||
"-std=c++1y",
|
||||
"-DDEBUG",
|
||||
]
|
||||
|
||||
yoga_cxx_library(
|
||||
name = "yoga",
|
||||
srcs = glob(["yoga/*.cpp"]),
|
||||
headers = subdir_glob([("", "yoga/**/*.h")]),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
||||
compiler_flags = COMPILER_FLAGS,
|
||||
@@ -32,6 +32,20 @@ yoga_cxx_library(
|
||||
],
|
||||
)
|
||||
|
||||
yoga_cxx_library(
|
||||
name = "yogaForDebug",
|
||||
srcs = glob(["yoga/*.cpp"]),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob([("", "yoga/*.h")]),
|
||||
compiler_flags = TEST_COMPILER_FLAGS,
|
||||
soname = "libyogacore.$(ext)",
|
||||
tests = [":YogaTests"],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
yoga_dep("lib/fb:ndklog"),
|
||||
],
|
||||
)
|
||||
|
||||
yoga_cxx_test(
|
||||
name = "YogaTests",
|
||||
srcs = glob(["tests/*.cpp"]),
|
||||
@@ -40,7 +54,7 @@ yoga_cxx_test(
|
||||
contacts = ["emilsj@fb.com"],
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
":yoga",
|
||||
":yogaForDebug",
|
||||
GTEST_TARGET,
|
||||
],
|
||||
)
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#
|
||||
Pod::Spec.new do |spec|
|
||||
spec.name = 'Yoga'
|
||||
spec.version = '1.9.0'
|
||||
spec.version = '1.12.0-pre.1'
|
||||
spec.license = { :type => 'MIT', :file => "LICENSE" }
|
||||
spec.homepage = 'https://yogalayout.com/'
|
||||
spec.documentation_url = 'https://yogalayout.com/docs'
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#
|
||||
podspec = Pod::Spec.new do |spec|
|
||||
spec.name = 'YogaKit'
|
||||
spec.version = '1.10.0'
|
||||
spec.version = '1.12.0'
|
||||
spec.license = { :type => 'MIT', :file => "LICENSE" }
|
||||
spec.homepage = 'https://facebook.github.io/yoga/'
|
||||
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/yogakit/'
|
||||
|
@@ -180,7 +180,7 @@ static YGConfigRef globalConfig;
|
||||
// the measure function. Since we already know that this is a leaf,
|
||||
// this *should* be fine. Forgive me Hack Gods.
|
||||
const YGNodeRef node = self.node;
|
||||
if (YGNodeGetMeasureFunc(node) == NULL) {
|
||||
if (YGNodeHasMeasureFunc(node)) {
|
||||
YGNodeSetMeasureFunc(node, YGMeasureView);
|
||||
}
|
||||
|
||||
@@ -425,9 +425,7 @@ static void YGRemoveAllChildren(const YGNodeRef node)
|
||||
return;
|
||||
}
|
||||
|
||||
while (YGNodeGetChildCount(node) > 0) {
|
||||
YGNodeRemoveChild(node, YGNodeGetChild(node, YGNodeGetChildCount(node) - 1));
|
||||
}
|
||||
YGNodeRemoveAllChildren(node);
|
||||
}
|
||||
|
||||
static CGFloat YGRoundPixelValue(CGFloat value)
|
||||
|
@@ -1,10 +1,3 @@
|
||||
<!--
|
||||
Copyright (c) Facebook, Inc. and its affiliates.
|
||||
|
||||
This source code is licensed under the MIT license found in the
|
||||
LICENSE file in the root directory of this source tree.
|
||||
-->
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
|
@@ -33,7 +33,7 @@ public class VirtualYogaLayout extends ViewGroup {
|
||||
|
||||
final private List<View> mChildren = new LinkedList<>();
|
||||
final private Map<View, YogaNode> mYogaNodes = new HashMap<>();
|
||||
final private YogaNode mYogaNode = new YogaNode();
|
||||
final private YogaNode mYogaNode = YogaNode.create();
|
||||
|
||||
public VirtualYogaLayout(Context context) {
|
||||
super(context);
|
||||
@@ -73,7 +73,7 @@ public class VirtualYogaLayout extends ViewGroup {
|
||||
return;
|
||||
}
|
||||
|
||||
YogaNode node = new YogaNode();
|
||||
YogaNode node = YogaNode.create();
|
||||
YogaLayout.LayoutParams lp = new YogaLayout.LayoutParams(params);
|
||||
YogaLayout.applyLayoutParams(lp, node, child);
|
||||
node.setData(child);
|
||||
|
@@ -78,7 +78,7 @@ public class YogaLayout extends ViewGroup {
|
||||
public YogaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
mYogaNode = new YogaNode();
|
||||
mYogaNode = YogaNode.create();
|
||||
mYogaNodes = new HashMap<>();
|
||||
|
||||
mYogaNode.setData(this);
|
||||
@@ -155,7 +155,7 @@ public class YogaLayout extends ViewGroup {
|
||||
if(mYogaNodes.containsKey(child)) {
|
||||
childNode = mYogaNodes.get(child);
|
||||
} else {
|
||||
childNode = new YogaNode();
|
||||
childNode = YogaNode.create();
|
||||
}
|
||||
|
||||
childNode.setData(child);
|
||||
|
@@ -9,11 +9,12 @@
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
maven { url 'https://maven.google.com/' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.0.0'
|
||||
classpath 'com.android.tools.build:gradle:3.1.0'
|
||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
|
||||
|
||||
@@ -24,6 +25,7 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ load(
|
||||
"yoga_dep",
|
||||
)
|
||||
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++11"]
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ["-std=c++14"]
|
||||
|
||||
fb_native.csharp_library(
|
||||
name = "yogalibnet46",
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
|
||||
VERSION_NAME=1.11.0
|
||||
VERSION_NAME=1.13.1-SNAPSHOT
|
||||
POM_URL=https://github.com/facebook/yoga
|
||||
POM_SCM_URL=https://github.com/facebook/yoga.git
|
||||
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
|
||||
|
@@ -18,7 +18,7 @@ yoga_cxx_library(
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Os",
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
],
|
||||
platforms = ANDROID,
|
||||
preprocessor_flags = [
|
||||
|
@@ -29,7 +29,7 @@ add_compile_options(
|
||||
-Wall
|
||||
-std=c++11)
|
||||
|
||||
add_library(yoga SHARED jni/YGJNI.cpp)
|
||||
add_library(yoga SHARED jni/YGJNI.cpp jni/YGJTypes.cpp)
|
||||
|
||||
target_include_directories(yoga PRIVATE
|
||||
${libfb_DIR}/include
|
||||
|
@@ -35,6 +35,7 @@ android {
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path 'CMakeLists.txt'
|
||||
version '3.6.0-rc2'
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,82 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaConfig {
|
||||
|
||||
public static int SPACING_TYPE = 1;
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
}
|
||||
|
||||
long mNativePointer;
|
||||
private YogaLogger mLogger;
|
||||
private YogaNodeCloneFunction mYogaNodeCloneFunction;
|
||||
|
||||
private native long jni_YGConfigNew();
|
||||
public YogaConfig() {
|
||||
mNativePointer = jni_YGConfigNew();
|
||||
mNativePointer = YogaNative.jni_YGConfigNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
private native void jni_YGConfigFree(long nativePointer);
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
jni_YGConfigFree(mNativePointer);
|
||||
YogaNative.jni_YGConfigFree(mNativePointer);
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
long nativePointer,
|
||||
int feature,
|
||||
boolean enabled);
|
||||
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
|
||||
jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
|
||||
public void setUseWebDefaults(boolean useWebDefaults) {
|
||||
jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetPrintTreeFlag(long nativePointer, boolean enable);
|
||||
public void setPrintTreeFlag(boolean enable) {
|
||||
jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
|
||||
public void setPointScaleFactor(float pixelsInPoint) {
|
||||
jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
|
||||
|
||||
/**
|
||||
* Yoga previously had an error where containers would take the maximum space possible instead of the minimum
|
||||
* like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch;
|
||||
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
|
||||
*/
|
||||
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
|
||||
jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
/**
|
||||
* If this flag is set then yoga would diff the layout without legacy flag and would set a bool in
|
||||
* YogaNode(mDoesLegacyStretchFlagAffectsLayout) with true if the layouts were different and false
|
||||
@@ -84,29 +64,16 @@ public class YogaConfig {
|
||||
*/
|
||||
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
|
||||
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
||||
public void setLogger(YogaLogger logger) {
|
||||
mLogger = logger;
|
||||
jni_YGConfigSetLogger(mNativePointer, logger);
|
||||
YogaNative.jni_YGConfigSetLogger(mNativePointer, logger);
|
||||
}
|
||||
|
||||
public YogaLogger getLogger() {
|
||||
return mLogger;
|
||||
}
|
||||
|
||||
private native void jni_YGConfigSetHasCloneNodeFunc(long nativePointer, boolean hasClonedFunc);
|
||||
|
||||
public void setOnCloneNode(YogaNodeCloneFunction cloneYogaNodeFunction) {
|
||||
mYogaNodeCloneFunction = cloneYogaNodeFunction;
|
||||
jni_YGConfigSetHasCloneNodeFunc(mNativePointer, cloneYogaNodeFunction != null);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
private final YogaNode cloneNode(YogaNode oldNode, YogaNode parent, int childIndex) {
|
||||
return mYogaNodeCloneFunction.cloneNode(oldNode, parent, childIndex);
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
114
java/com/facebook/yoga/YogaNative.java
Normal file
114
java/com/facebook/yoga/YogaNative.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaNative {
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
}
|
||||
|
||||
// YGConfig related
|
||||
static native long jni_YGConfigNew();
|
||||
static native void jni_YGConfigFree(long nativePointer);
|
||||
static native void jni_YGConfigSetExperimentalFeatureEnabled(long nativePointer, int feature, boolean enabled);
|
||||
static native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
|
||||
static native void jni_YGConfigSetPrintTreeFlag(long nativePointer, boolean enable);
|
||||
static native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
|
||||
static native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
|
||||
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
|
||||
static native void jni_YGConfigSetLogger(long nativePointer, Object logger);
|
||||
|
||||
|
||||
// YGNode related
|
||||
static native int jni_YGNodeGetInstanceCount();
|
||||
static native long jni_YGNodeNew();
|
||||
static native long jni_YGNodeNewWithConfig(long configPointer);
|
||||
static native void jni_YGNodeFree(long nativePointer);
|
||||
static native void jni_YGNodeReset(long nativePointer);
|
||||
static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||
static native void jni_YGNodeSetIsReferenceBaseline(long nativePointer, boolean isReferenceBaseline);
|
||||
static native boolean jni_YGNodeIsReferenceBaseline(long nativePointer);
|
||||
static native void jni_YGNodeClearChildren(long nativePointer);
|
||||
static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
|
||||
static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes);
|
||||
static native void jni_YGNodeMarkDirty(long nativePointer);
|
||||
static native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer);
|
||||
static native boolean jni_YGNodeIsDirty(long nativePointer);
|
||||
static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||
static native int jni_YGNodeStyleGetDirection(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
|
||||
static native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
|
||||
static native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
|
||||
static native int jni_YGNodeStyleGetAlignItems(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
|
||||
static native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
|
||||
static native int jni_YGNodeStyleGetAlignContent(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
|
||||
static native int jni_YGNodeStyleGetPositionType(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
|
||||
static native int jni_YGNodeStyleGetFlexWrap(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
|
||||
static native int jni_YGNodeStyleGetOverflow(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
|
||||
static native int jni_YGNodeStyleGetDisplay(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
|
||||
static native float jni_YGNodeStyleGetFlex(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
|
||||
static native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
|
||||
static native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
|
||||
static native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
|
||||
static native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
|
||||
static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
|
||||
static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
|
||||
static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
|
||||
static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
|
||||
static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
|
||||
static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
|
||||
static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
|
||||
static native Object jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
|
||||
static native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
|
||||
static native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
|
||||
static native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
|
||||
static native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
|
||||
static native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
|
||||
static native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
|
||||
static native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
|
||||
static native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
|
||||
static native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
|
||||
static native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
|
||||
static native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio);
|
||||
static native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
static native void jni_YGNodePrint(long nativePointer);
|
||||
static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size);
|
||||
}
|
@@ -6,250 +6,30 @@
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaNode implements Cloneable {
|
||||
|
||||
static {
|
||||
SoLoader.loadLibrary("yoga");
|
||||
public abstract class YogaNode {
|
||||
public static YogaNode create() {
|
||||
return new YogaNodeJNI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get native instance count. Useful for testing only.
|
||||
*/
|
||||
static native int jni_YGNodeGetInstanceCount();
|
||||
|
||||
private YogaNode mOwner;
|
||||
@Nullable private List<YogaNode> mChildren;
|
||||
private YogaMeasureFunction mMeasureFunction;
|
||||
private YogaBaselineFunction mBaselineFunction;
|
||||
private long mNativePointer;
|
||||
private Object mData;
|
||||
|
||||
/* Those flags needs be in sync with YGJNI.cpp */
|
||||
private static final int MARGIN = 1;
|
||||
private static final int PADDING = 2;
|
||||
private static final int BORDER = 4;
|
||||
|
||||
@DoNotStrip
|
||||
private int mEdgeSetFlag = 0;
|
||||
|
||||
private boolean mHasSetPosition = false;
|
||||
|
||||
@DoNotStrip
|
||||
private float mWidth = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mHeight = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mTop = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mLeft = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mMarginLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginTop = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginRight = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingTop = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingRight = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderTop = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderRight = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderBottom = 0;
|
||||
@DoNotStrip
|
||||
private int mLayoutDirection = 0;
|
||||
@DoNotStrip
|
||||
private boolean mHasNewLayout = true;
|
||||
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
private native long jni_YGNodeNew();
|
||||
public YogaNode() {
|
||||
mNativePointer = jni_YGNodeNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
public static YogaNode create(YogaConfig config) {
|
||||
return new YogaNodeJNI(config);
|
||||
}
|
||||
|
||||
private native long jni_YGNodeNewWithConfig(long configPointer);
|
||||
public YogaNode(YogaConfig config) {
|
||||
mNativePointer = jni_YGNodeNewWithConfig(config.mNativePointer);
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
public abstract void reset();
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
freeNatives();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
public abstract int getChildCount();
|
||||
|
||||
private static native void jni_YGNodeFree(long nativePointer);
|
||||
public abstract YogaNode getChildAt(int i);
|
||||
|
||||
/* frees the native underlying YGNode. Useful for testing. */
|
||||
public void freeNatives() {
|
||||
if (mNativePointer > 0) {
|
||||
long nativePointer = mNativePointer;
|
||||
mNativePointer = 0;
|
||||
jni_YGNodeFree(nativePointer);
|
||||
}
|
||||
}
|
||||
public abstract void addChildAt(YogaNode child, int i);
|
||||
|
||||
private static native void jni_YGNodeReset(long nativePointer);
|
||||
public void reset() {
|
||||
mEdgeSetFlag = 0;
|
||||
mHasSetPosition = false;
|
||||
mHasNewLayout = true;
|
||||
public abstract void setIsReferenceBaseline(boolean isReferenceBaseline);
|
||||
|
||||
mWidth = YogaConstants.UNDEFINED;
|
||||
mHeight = YogaConstants.UNDEFINED;
|
||||
mTop = YogaConstants.UNDEFINED;
|
||||
mLeft = YogaConstants.UNDEFINED;
|
||||
mMarginLeft = 0;
|
||||
mMarginTop = 0;
|
||||
mMarginRight = 0;
|
||||
mMarginBottom = 0;
|
||||
mPaddingLeft = 0;
|
||||
mPaddingTop = 0;
|
||||
mPaddingRight = 0;
|
||||
mPaddingBottom = 0;
|
||||
mBorderLeft = 0;
|
||||
mBorderTop = 0;
|
||||
mBorderRight = 0;
|
||||
mBorderBottom = 0;
|
||||
mLayoutDirection = 0;
|
||||
public abstract boolean isReferenceBaseline();
|
||||
|
||||
mMeasureFunction = null;
|
||||
mBaselineFunction = null;
|
||||
mData = null;
|
||||
mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
jni_YGNodeReset(mNativePointer);
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
return mChildren == null ? 0 : mChildren.size();
|
||||
}
|
||||
|
||||
public YogaNode getChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("YogaNode does not have children");
|
||||
}
|
||||
return mChildren.get(i);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
|
||||
|
||||
public void addChildAt(YogaNode child, int i) {
|
||||
if (child.mOwner != null) {
|
||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||
}
|
||||
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
mChildren.add(i, child);
|
||||
child.mOwner = this;
|
||||
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetIsReferenceBaseline(long nativePointer, boolean isReferenceBaseline);
|
||||
|
||||
public void setIsReferenceBaseline(boolean isReferenceBaseline) {
|
||||
jni_YGNodeSetIsReferenceBaseline(mNativePointer, isReferenceBaseline);
|
||||
}
|
||||
|
||||
private static native boolean jni_YGNodeIsReferenceBaseline(long nativePointer);
|
||||
|
||||
public boolean isReferenceBaseline() {
|
||||
return jni_YGNodeIsReferenceBaseline(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetOwner(long nativePointer, long newOwnerNativePointer);
|
||||
|
||||
private native long jni_YGNodeClone(long nativePointer, Object newNode);
|
||||
|
||||
@Override
|
||||
public YogaNode clone() {
|
||||
try {
|
||||
YogaNode clonedYogaNode = (YogaNode) super.clone();
|
||||
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
|
||||
|
||||
if (mChildren != null) {
|
||||
for (YogaNode child : mChildren) {
|
||||
YogaNode.jni_YGNodeSetOwner(child.mNativePointer, 0);
|
||||
child.mOwner = null;
|
||||
}
|
||||
}
|
||||
|
||||
clonedYogaNode.mNativePointer = clonedNativePointer;
|
||||
clonedYogaNode.mOwner = null;
|
||||
clonedYogaNode.mChildren =
|
||||
mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null;
|
||||
if (clonedYogaNode.mChildren != null) {
|
||||
for (YogaNode child : clonedYogaNode.mChildren) {
|
||||
child.mOwner = null;
|
||||
}
|
||||
}
|
||||
return clonedYogaNode;
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
// This class implements Cloneable, this should not happen
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public YogaNode cloneWithNewChildren() {
|
||||
try {
|
||||
YogaNode clonedYogaNode = (YogaNode) super.clone();
|
||||
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
|
||||
clonedYogaNode.mOwner = null;
|
||||
clonedYogaNode.mNativePointer = clonedNativePointer;
|
||||
clonedYogaNode.clearChildren();
|
||||
return clonedYogaNode;
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
// This class implements Cloneable, this should not happen
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeClearChildren(long nativePointer);
|
||||
|
||||
private void clearChildren() {
|
||||
mChildren = null;
|
||||
jni_YGNodeClearChildren(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
|
||||
public YogaNode removeChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException(
|
||||
"Trying to remove a child of a YogaNode that does not have children");
|
||||
}
|
||||
final YogaNode child = mChildren.remove(i);
|
||||
child.mOwner = null;
|
||||
jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||
return child;
|
||||
}
|
||||
public abstract YogaNode removeChildAt(int i);
|
||||
|
||||
/**
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||
@@ -260,539 +40,182 @@ public class YogaNode implements Cloneable {
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
*/
|
||||
@Nullable
|
||||
public YogaNode getOwner() {
|
||||
return mOwner;
|
||||
}
|
||||
public abstract YogaNode getOwner();
|
||||
|
||||
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public YogaNode getParent() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
public int indexOf(YogaNode child) {
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height);
|
||||
public void calculateLayout(float width, float height) {
|
||||
jni_YGNodeCalculateLayout(mNativePointer, width, height);
|
||||
}
|
||||
|
||||
public boolean hasNewLayout() {
|
||||
return mHasNewLayout;
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeMarkDirty(long nativePointer);
|
||||
public void dirty() {
|
||||
jni_YGNodeMarkDirty(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer);
|
||||
|
||||
public void dirtyAllDescendants() {
|
||||
jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer);
|
||||
}
|
||||
|
||||
private static native boolean jni_YGNodeIsDirty(long nativePointer);
|
||||
public boolean isDirty() {
|
||||
return jni_YGNodeIsDirty(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
|
||||
public void copyStyle(YogaNode srcNode) {
|
||||
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
|
||||
}
|
||||
|
||||
public void markLayoutSeen() {
|
||||
mHasNewLayout = false;
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetDirection(long nativePointer);
|
||||
public YogaDirection getStyleDirection() {
|
||||
return YogaDirection.fromInt(jni_YGNodeStyleGetDirection(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
|
||||
public void setDirection(YogaDirection direction) {
|
||||
jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
|
||||
public YogaFlexDirection getFlexDirection() {
|
||||
return YogaFlexDirection.fromInt(jni_YGNodeStyleGetFlexDirection(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
|
||||
public void setFlexDirection(YogaFlexDirection flexDirection) {
|
||||
jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
|
||||
public YogaJustify getJustifyContent() {
|
||||
return YogaJustify.fromInt(jni_YGNodeStyleGetJustifyContent(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
|
||||
public void setJustifyContent(YogaJustify justifyContent) {
|
||||
jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignItems(long nativePointer);
|
||||
public YogaAlign getAlignItems() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignItems(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
|
||||
public void setAlignItems(YogaAlign alignItems) {
|
||||
jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
|
||||
public YogaAlign getAlignSelf() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignSelf(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
|
||||
public void setAlignSelf(YogaAlign alignSelf) {
|
||||
jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetAlignContent(long nativePointer);
|
||||
public YogaAlign getAlignContent() {
|
||||
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignContent(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
|
||||
public void setAlignContent(YogaAlign alignContent) {
|
||||
jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetPositionType(long nativePointer);
|
||||
public YogaPositionType getPositionType() {
|
||||
return YogaPositionType.fromInt(jni_YGNodeStyleGetPositionType(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
|
||||
public void setPositionType(YogaPositionType positionType) {
|
||||
jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
|
||||
public void setWrap(YogaWrap flexWrap) {
|
||||
jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetOverflow(long nativePointer);
|
||||
public YogaOverflow getOverflow() {
|
||||
return YogaOverflow.fromInt(jni_YGNodeStyleGetOverflow(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
|
||||
public void setOverflow(YogaOverflow overflow) {
|
||||
jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
|
||||
}
|
||||
|
||||
private static native int jni_YGNodeStyleGetDisplay(long nativePointer);
|
||||
public YogaDisplay getDisplay() {
|
||||
return YogaDisplay.fromInt(jni_YGNodeStyleGetDisplay(mNativePointer));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
|
||||
public void setDisplay(YogaDisplay display) {
|
||||
jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
|
||||
public void setFlex(float flex) {
|
||||
jni_YGNodeStyleSetFlex(mNativePointer, flex);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
|
||||
public float getFlexGrow() {
|
||||
return jni_YGNodeStyleGetFlexGrow(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
|
||||
public void setFlexGrow(float flexGrow) {
|
||||
jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
|
||||
public float getFlexShrink() {
|
||||
return jni_YGNodeStyleGetFlexShrink(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
|
||||
public void setFlexShrink(float flexShrink) {
|
||||
jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
|
||||
public void setFlexBasis(float flexBasis) {
|
||||
jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
|
||||
public void setFlexBasisPercent(float percent) {
|
||||
jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
|
||||
public void setFlexBasisAuto() {
|
||||
jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
if (!((mEdgeSetFlag & MARGIN) == MARGIN)) {
|
||||
return YogaValue.UNDEFINED;
|
||||
}
|
||||
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
|
||||
public void setMargin(YogaEdge edge, float margin) {
|
||||
mEdgeSetFlag |= MARGIN;
|
||||
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
|
||||
public void setMarginPercent(YogaEdge edge, float percent) {
|
||||
mEdgeSetFlag |= MARGIN;
|
||||
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
|
||||
public void setMarginAuto(YogaEdge edge) {
|
||||
mEdgeSetFlag |= MARGIN;
|
||||
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
if (!((mEdgeSetFlag & PADDING) == PADDING)) {
|
||||
return YogaValue.UNDEFINED;
|
||||
}
|
||||
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
|
||||
public void setPadding(YogaEdge edge, float padding) {
|
||||
mEdgeSetFlag |= PADDING;
|
||||
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
|
||||
public void setPaddingPercent(YogaEdge edge, float percent) {
|
||||
mEdgeSetFlag |= PADDING;
|
||||
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
|
||||
public float getBorder(YogaEdge edge) {
|
||||
if (!((mEdgeSetFlag & BORDER) == BORDER)) {
|
||||
return YogaConstants.UNDEFINED;
|
||||
}
|
||||
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
|
||||
public void setBorder(YogaEdge edge, float border) {
|
||||
mEdgeSetFlag |= BORDER;
|
||||
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
if (!mHasSetPosition) {
|
||||
return YogaValue.UNDEFINED;
|
||||
}
|
||||
return (YogaValue) jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
|
||||
public void setPosition(YogaEdge edge, float position) {
|
||||
mHasSetPosition = true;
|
||||
jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
|
||||
public void setPositionPercent(YogaEdge edge, float percent) {
|
||||
mHasSetPosition = true;
|
||||
jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
|
||||
public void setWidth(float width) {
|
||||
jni_YGNodeStyleSetWidth(mNativePointer, width);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
|
||||
public void setWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
|
||||
public void setWidthAuto() {
|
||||
jni_YGNodeStyleSetWidthAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
|
||||
public void setHeight(float height) {
|
||||
jni_YGNodeStyleSetHeight(mNativePointer, height);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
|
||||
public void setHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
|
||||
public void setHeightAuto() {
|
||||
jni_YGNodeStyleSetHeightAuto(mNativePointer);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
|
||||
public void setMinWidth(float minWidth) {
|
||||
jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
|
||||
public void setMinWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
|
||||
public void setMinHeight(float minHeight) {
|
||||
jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
|
||||
public void setMinHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
|
||||
public void setMaxWidth(float maxWidth) {
|
||||
jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
|
||||
public void setMaxWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
|
||||
public void setMaxHeight(float maxheight) {
|
||||
jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
|
||||
public void setMaxHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private static native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
|
||||
public float getAspectRatio() {
|
||||
return jni_YGNodeStyleGetAspectRatio(mNativePointer);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio);
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
|
||||
}
|
||||
|
||||
public float getLayoutX() {
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
public float getLayoutY() {
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public float getLayoutWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public float getLayoutHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public boolean getDoesLegacyStretchFlagAffectsLayout() {
|
||||
return mDoesLegacyStretchFlagAffectsLayout;
|
||||
}
|
||||
|
||||
public float getLayoutMargin(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mMarginLeft;
|
||||
case TOP:
|
||||
return mMarginTop;
|
||||
case RIGHT:
|
||||
return mMarginRight;
|
||||
case BOTTOM:
|
||||
return mMarginBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginRight : mMarginLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginLeft : mMarginRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutPadding(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mPaddingLeft;
|
||||
case TOP:
|
||||
return mPaddingTop;
|
||||
case RIGHT:
|
||||
return mPaddingRight;
|
||||
case BOTTOM:
|
||||
return mPaddingBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingRight : mPaddingLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingLeft : mPaddingRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutBorder(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mBorderLeft;
|
||||
case TOP:
|
||||
return mBorderTop;
|
||||
case RIGHT:
|
||||
return mBorderRight;
|
||||
case BOTTOM:
|
||||
return mBorderBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaDirection getLayoutDirection() {
|
||||
return YogaDirection.fromInt(mLayoutDirection);
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
|
||||
mMeasureFunction = measureFunction;
|
||||
jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
|
||||
}
|
||||
|
||||
// Implementation Note: Why this method needs to stay final
|
||||
//
|
||||
// We cache the jmethodid for this method in Yoga code. This means that even if a subclass
|
||||
// were to override measure, we'd still call this implementation from layout code since the
|
||||
// overriding method will have a different jmethodid. This is final to prevent that mistake.
|
||||
@DoNotStrip
|
||||
public final long measure(float width, int widthMode, float height, int heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
}
|
||||
|
||||
private static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
|
||||
mBaselineFunction = baselineFunction;
|
||||
jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public final float baseline(float width, float height) {
|
||||
return mBaselineFunction.baseline(this, width, height);
|
||||
}
|
||||
|
||||
public boolean isMeasureDefined() {
|
||||
return mMeasureFunction != null;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
private static native void jni_YGNodePrint(long nativePointer);
|
||||
|
||||
/**
|
||||
* Use the set logger (defaults to adb log) to print out the styles, children, and computed
|
||||
* layout of the tree rooted at this node.
|
||||
*/
|
||||
public void print() {
|
||||
jni_YGNodePrint(mNativePointer);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method replaces the child at childIndex position with the newNode received by parameter.
|
||||
* This is different than calling removeChildAt and addChildAt because this method ONLY replaces
|
||||
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
|
||||
*
|
||||
* @return the nativePointer of the newNode {@linl YogaNode}
|
||||
*/
|
||||
@DoNotStrip
|
||||
private final long replaceChild(YogaNode newNode, int childIndex) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
||||
}
|
||||
mChildren.remove(childIndex);
|
||||
mChildren.add(childIndex, newNode);
|
||||
newNode.mOwner = this;
|
||||
return newNode.mNativePointer;
|
||||
}
|
||||
public abstract YogaNode getParent();
|
||||
|
||||
public abstract int indexOf(YogaNode child);
|
||||
|
||||
public abstract void calculateLayout(float width, float height);
|
||||
|
||||
public abstract boolean hasNewLayout();
|
||||
|
||||
public abstract void dirty();
|
||||
|
||||
public abstract boolean isDirty();
|
||||
|
||||
public abstract void copyStyle(YogaNode srcNode);
|
||||
|
||||
public abstract void markLayoutSeen();
|
||||
|
||||
public abstract YogaDirection getStyleDirection();
|
||||
|
||||
public abstract void setDirection(YogaDirection direction);
|
||||
|
||||
public abstract YogaFlexDirection getFlexDirection();
|
||||
|
||||
public abstract void setFlexDirection(YogaFlexDirection flexDirection);
|
||||
|
||||
public abstract YogaJustify getJustifyContent();
|
||||
|
||||
public abstract void setJustifyContent(YogaJustify justifyContent);
|
||||
|
||||
public abstract YogaAlign getAlignItems();
|
||||
|
||||
public abstract void setAlignItems(YogaAlign alignItems);
|
||||
|
||||
public abstract YogaAlign getAlignSelf();
|
||||
|
||||
public abstract void setAlignSelf(YogaAlign alignSelf);
|
||||
|
||||
public abstract YogaAlign getAlignContent();
|
||||
|
||||
public abstract void setAlignContent(YogaAlign alignContent);
|
||||
|
||||
public abstract YogaPositionType getPositionType();
|
||||
|
||||
public abstract void setPositionType(YogaPositionType positionType);
|
||||
|
||||
public abstract YogaWrap getWrap();
|
||||
|
||||
public abstract void setWrap(YogaWrap flexWrap);
|
||||
|
||||
public abstract YogaOverflow getOverflow();
|
||||
|
||||
public abstract void setOverflow(YogaOverflow overflow);
|
||||
|
||||
public abstract YogaDisplay getDisplay();
|
||||
|
||||
public abstract void setDisplay(YogaDisplay display);
|
||||
|
||||
public abstract float getFlex();
|
||||
|
||||
public abstract void setFlex(float flex);
|
||||
|
||||
public abstract float getFlexGrow();
|
||||
|
||||
public abstract void setFlexGrow(float flexGrow);
|
||||
|
||||
public abstract float getFlexShrink();
|
||||
|
||||
public abstract void setFlexShrink(float flexShrink);
|
||||
|
||||
public abstract YogaValue getFlexBasis();
|
||||
|
||||
public abstract void setFlexBasis(float flexBasis);
|
||||
|
||||
public abstract void setFlexBasisPercent(float percent);
|
||||
|
||||
public abstract void setFlexBasisAuto();
|
||||
|
||||
public abstract YogaValue getMargin(YogaEdge edge);
|
||||
|
||||
public abstract void setMargin(YogaEdge edge, float margin);
|
||||
|
||||
public abstract void setMarginPercent(YogaEdge edge, float percent);
|
||||
|
||||
public abstract void setMarginAuto(YogaEdge edge);
|
||||
|
||||
public abstract YogaValue getPadding(YogaEdge edge);
|
||||
|
||||
public abstract void setPadding(YogaEdge edge, float padding);
|
||||
|
||||
public abstract void setPaddingPercent(YogaEdge edge, float percent);
|
||||
|
||||
public abstract float getBorder(YogaEdge edge);
|
||||
|
||||
public abstract void setBorder(YogaEdge edge, float border);
|
||||
|
||||
public abstract YogaValue getPosition(YogaEdge edge);
|
||||
|
||||
public abstract void setPosition(YogaEdge edge, float position);
|
||||
|
||||
public abstract void setPositionPercent(YogaEdge edge, float percent);
|
||||
|
||||
public abstract YogaValue getWidth();
|
||||
|
||||
public abstract void setWidth(float width);
|
||||
|
||||
public abstract void setWidthPercent(float percent);
|
||||
|
||||
public abstract void setWidthAuto();
|
||||
|
||||
public abstract YogaValue getHeight();
|
||||
|
||||
public abstract void setHeight(float height);
|
||||
|
||||
public abstract void setHeightPercent(float percent);
|
||||
|
||||
public abstract void setHeightAuto();
|
||||
|
||||
public abstract YogaValue getMinWidth();
|
||||
|
||||
public abstract void setMinWidth(float minWidth);
|
||||
|
||||
public abstract void setMinWidthPercent(float percent);
|
||||
|
||||
public abstract YogaValue getMinHeight();
|
||||
|
||||
public abstract void setMinHeight(float minHeight);
|
||||
|
||||
public abstract void setMinHeightPercent(float percent);
|
||||
|
||||
public abstract YogaValue getMaxWidth();
|
||||
|
||||
public abstract void setMaxWidth(float maxWidth);
|
||||
|
||||
public abstract void setMaxWidthPercent(float percent);
|
||||
|
||||
public abstract YogaValue getMaxHeight();
|
||||
|
||||
public abstract void setMaxHeight(float maxheight);
|
||||
|
||||
public abstract void setMaxHeightPercent(float percent);
|
||||
|
||||
public abstract float getAspectRatio();
|
||||
|
||||
public abstract void setAspectRatio(float aspectRatio);
|
||||
|
||||
public abstract float getLayoutX();
|
||||
|
||||
public abstract float getLayoutY();
|
||||
|
||||
public abstract float getLayoutWidth();
|
||||
|
||||
public abstract float getLayoutHeight();
|
||||
|
||||
public abstract float getLayoutMargin(YogaEdge edge);
|
||||
|
||||
public abstract float getLayoutPadding(YogaEdge edge);
|
||||
|
||||
public abstract float getLayoutBorder(YogaEdge edge);
|
||||
|
||||
public abstract YogaDirection getLayoutDirection();
|
||||
|
||||
public abstract void setMeasureFunction(YogaMeasureFunction measureFunction);
|
||||
|
||||
public abstract void setBaselineFunction(YogaBaselineFunction baselineFunction);
|
||||
|
||||
public abstract boolean isMeasureDefined();
|
||||
|
||||
public abstract void setData(Object data);
|
||||
|
||||
public abstract Object getData();
|
||||
|
||||
public abstract void print();
|
||||
|
||||
public abstract void setStyleInputs(float[] styleInputs, int size);
|
||||
}
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
21
java/com/facebook/yoga/YogaNodeJNI.java
Normal file
21
java/com/facebook/yoga/YogaNodeJNI.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaNodeJNI extends YogaNodeJNIBase {
|
||||
|
||||
public YogaNodeJNI() {
|
||||
super();
|
||||
}
|
||||
|
||||
public YogaNodeJNI(YogaConfig config) {
|
||||
super(config);
|
||||
}
|
||||
}
|
659
java/com/facebook/yoga/YogaNodeJNIBase.java
Normal file
659
java/com/facebook/yoga/YogaNodeJNIBase.java
Normal file
@@ -0,0 +1,659 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@DoNotStrip
|
||||
public abstract class YogaNodeJNIBase extends YogaNode {
|
||||
|
||||
private YogaNodeJNIBase mOwner;
|
||||
@Nullable private List<YogaNodeJNIBase> mChildren;
|
||||
private YogaMeasureFunction mMeasureFunction;
|
||||
private YogaBaselineFunction mBaselineFunction;
|
||||
private long mNativePointer;
|
||||
private Object mData;
|
||||
|
||||
/* Those flags needs be in sync with YGJNI.cpp */
|
||||
private static final int MARGIN = 1;
|
||||
private static final int PADDING = 2;
|
||||
private static final int BORDER = 4;
|
||||
|
||||
@DoNotStrip
|
||||
private float mWidth = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mHeight = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mTop = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mLeft = YogaConstants.UNDEFINED;
|
||||
@DoNotStrip
|
||||
private float mMarginLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginTop = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginRight = 0;
|
||||
@DoNotStrip
|
||||
private float mMarginBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingTop = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingRight = 0;
|
||||
@DoNotStrip
|
||||
private float mPaddingBottom = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderLeft = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderTop = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderRight = 0;
|
||||
@DoNotStrip
|
||||
private float mBorderBottom = 0;
|
||||
@DoNotStrip
|
||||
private int mLayoutDirection = 0;
|
||||
@DoNotStrip
|
||||
private boolean mHasNewLayout = true;
|
||||
@DoNotStrip private boolean mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
public YogaNodeJNIBase() {
|
||||
mNativePointer = YogaNative.jni_YGNodeNew();
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase(YogaConfig config) {
|
||||
mNativePointer = YogaNative.jni_YGNodeNewWithConfig(config.mNativePointer);
|
||||
if (mNativePointer == 0) {
|
||||
throw new IllegalStateException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
freeNatives();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
/* frees the native underlying YGNode. Useful for testing. */
|
||||
public void freeNatives() {
|
||||
if (mNativePointer > 0) {
|
||||
long nativePointer = mNativePointer;
|
||||
mNativePointer = 0;
|
||||
YogaNative.jni_YGNodeFree(nativePointer);
|
||||
}
|
||||
}
|
||||
public void reset() {
|
||||
mHasNewLayout = true;
|
||||
|
||||
mWidth = YogaConstants.UNDEFINED;
|
||||
mHeight = YogaConstants.UNDEFINED;
|
||||
mTop = YogaConstants.UNDEFINED;
|
||||
mLeft = YogaConstants.UNDEFINED;
|
||||
mMarginLeft = 0;
|
||||
mMarginTop = 0;
|
||||
mMarginRight = 0;
|
||||
mMarginBottom = 0;
|
||||
mPaddingLeft = 0;
|
||||
mPaddingTop = 0;
|
||||
mPaddingRight = 0;
|
||||
mPaddingBottom = 0;
|
||||
mBorderLeft = 0;
|
||||
mBorderTop = 0;
|
||||
mBorderRight = 0;
|
||||
mBorderBottom = 0;
|
||||
mLayoutDirection = 0;
|
||||
|
||||
mMeasureFunction = null;
|
||||
mBaselineFunction = null;
|
||||
mData = null;
|
||||
mDoesLegacyStretchFlagAffectsLayout = false;
|
||||
|
||||
YogaNative.jni_YGNodeReset(mNativePointer);
|
||||
}
|
||||
|
||||
public int getChildCount() {
|
||||
return mChildren == null ? 0 : mChildren.size();
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase getChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("YogaNode does not have children");
|
||||
}
|
||||
return mChildren.get(i);
|
||||
}
|
||||
|
||||
public void addChildAt(YogaNode c, int i) {
|
||||
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
|
||||
if (child.mOwner != null) {
|
||||
throw new IllegalStateException("Child already has a parent, it must be removed first.");
|
||||
}
|
||||
|
||||
if (mChildren == null) {
|
||||
mChildren = new ArrayList<>(4);
|
||||
}
|
||||
mChildren.add(i, child);
|
||||
child.mOwner = this;
|
||||
YogaNative.jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
|
||||
}
|
||||
|
||||
public void setIsReferenceBaseline(boolean isReferenceBaseline) {
|
||||
YogaNative.jni_YGNodeSetIsReferenceBaseline(mNativePointer, isReferenceBaseline);
|
||||
}
|
||||
|
||||
public boolean isReferenceBaseline() {
|
||||
return YogaNative.jni_YGNodeIsReferenceBaseline(mNativePointer);
|
||||
}
|
||||
|
||||
private void clearChildren() {
|
||||
mChildren = null;
|
||||
YogaNative.jni_YGNodeClearChildren(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaNodeJNIBase removeChildAt(int i) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException(
|
||||
"Trying to remove a child of a YogaNode that does not have children");
|
||||
}
|
||||
final YogaNodeJNIBase child = mChildren.remove(i);
|
||||
child.mOwner = null;
|
||||
YogaNative.jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
|
||||
* to.
|
||||
* This method will return the parent of the {@link YogaNode} when the
|
||||
* {@link YogaNode} only belongs to one YogaTree or null when the
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
*/
|
||||
@Nullable
|
||||
public YogaNodeJNIBase getOwner() {
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
/** @deprecated Use #getOwner() instead. This will be removed in the next version. */
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public YogaNodeJNIBase getParent() {
|
||||
return getOwner();
|
||||
}
|
||||
|
||||
public int indexOf(YogaNode child) {
|
||||
return mChildren == null ? -1 : mChildren.indexOf(child);
|
||||
}
|
||||
|
||||
public void calculateLayout(float width, float height) {
|
||||
long[] nativePointers = null;
|
||||
YogaNodeJNIBase[] nodes = null;
|
||||
|
||||
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
|
||||
n.add(this);
|
||||
for (int i = 0; i < n.size(); ++i) {
|
||||
List<YogaNodeJNIBase> children = n.get(i).mChildren;
|
||||
if (children != null) {
|
||||
n.addAll(children);
|
||||
}
|
||||
}
|
||||
|
||||
nodes = n.toArray(new YogaNodeJNIBase[n.size()]);
|
||||
nativePointers = new long[nodes.length];
|
||||
for (int i = 0; i < nodes.length; ++i) {
|
||||
nativePointers[i] = nodes[i].mNativePointer;
|
||||
}
|
||||
|
||||
YogaNative.jni_YGNodeCalculateLayout(mNativePointer, width, height, nativePointers, nodes);
|
||||
}
|
||||
|
||||
public boolean hasNewLayout() {
|
||||
return mHasNewLayout;
|
||||
}
|
||||
|
||||
public void dirty() {
|
||||
YogaNative.jni_YGNodeMarkDirty(mNativePointer);
|
||||
}
|
||||
|
||||
public void dirtyAllDescendants() {
|
||||
YogaNative.jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer);
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
return YogaNative.jni_YGNodeIsDirty(mNativePointer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyStyle(YogaNode srcNode) {
|
||||
YogaNative.jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
|
||||
}
|
||||
|
||||
public void markLayoutSeen() {
|
||||
mHasNewLayout = false;
|
||||
}
|
||||
|
||||
public YogaDirection getStyleDirection() {
|
||||
return YogaDirection.fromInt(YogaNative.jni_YGNodeStyleGetDirection(mNativePointer));
|
||||
}
|
||||
|
||||
public void setDirection(YogaDirection direction) {
|
||||
YogaNative.jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
|
||||
}
|
||||
|
||||
public YogaFlexDirection getFlexDirection() {
|
||||
return YogaFlexDirection.fromInt(YogaNative.jni_YGNodeStyleGetFlexDirection(mNativePointer));
|
||||
}
|
||||
|
||||
public void setFlexDirection(YogaFlexDirection flexDirection) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
|
||||
}
|
||||
|
||||
public YogaJustify getJustifyContent() {
|
||||
return YogaJustify.fromInt(YogaNative.jni_YGNodeStyleGetJustifyContent(mNativePointer));
|
||||
}
|
||||
|
||||
public void setJustifyContent(YogaJustify justifyContent) {
|
||||
YogaNative.jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignItems() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignItems(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignItems(YogaAlign alignItems) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignSelf() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignSelf(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignSelf(YogaAlign alignSelf) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
|
||||
}
|
||||
|
||||
public YogaAlign getAlignContent() {
|
||||
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignContent(mNativePointer));
|
||||
}
|
||||
|
||||
public void setAlignContent(YogaAlign alignContent) {
|
||||
YogaNative.jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
|
||||
}
|
||||
|
||||
public YogaPositionType getPositionType() {
|
||||
return YogaPositionType.fromInt(YogaNative.jni_YGNodeStyleGetPositionType(mNativePointer));
|
||||
}
|
||||
|
||||
public void setPositionType(YogaPositionType positionType) {
|
||||
YogaNative.jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
|
||||
}
|
||||
|
||||
public YogaWrap getWrap() {
|
||||
return YogaWrap.fromInt(YogaNative.jni_YGNodeStyleGetFlexWrap(mNativePointer));
|
||||
}
|
||||
|
||||
public void setWrap(YogaWrap flexWrap) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
|
||||
}
|
||||
|
||||
public YogaOverflow getOverflow() {
|
||||
return YogaOverflow.fromInt(YogaNative.jni_YGNodeStyleGetOverflow(mNativePointer));
|
||||
}
|
||||
|
||||
public void setOverflow(YogaOverflow overflow) {
|
||||
YogaNative.jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
|
||||
}
|
||||
|
||||
public YogaDisplay getDisplay() {
|
||||
return YogaDisplay.fromInt(YogaNative.jni_YGNodeStyleGetDisplay(mNativePointer));
|
||||
}
|
||||
|
||||
public void setDisplay(YogaDisplay display) {
|
||||
YogaNative.jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
|
||||
}
|
||||
|
||||
public float getFlex() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlex(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlex(float flex) {
|
||||
YogaNative.jni_YGNodeStyleSetFlex(mNativePointer, flex);
|
||||
}
|
||||
|
||||
public float getFlexGrow() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlexGrow(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexGrow(float flexGrow) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
|
||||
}
|
||||
|
||||
public float getFlexShrink() {
|
||||
return YogaNative.jni_YGNodeStyleGetFlexShrink(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexShrink(float flexShrink) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
|
||||
}
|
||||
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
}
|
||||
|
||||
public void setFlexBasis(float flexBasis) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
|
||||
}
|
||||
|
||||
public void setFlexBasisPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setFlexBasisAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setMargin(YogaEdge edge, float margin) {
|
||||
YogaNative.jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
|
||||
}
|
||||
|
||||
public void setMarginPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public void setMarginAuto(YogaEdge edge) {
|
||||
YogaNative.jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setPadding(YogaEdge edge, float padding) {
|
||||
YogaNative.jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
|
||||
}
|
||||
|
||||
public void setPaddingPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public float getBorder(YogaEdge edge) {
|
||||
return YogaNative.jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setBorder(YogaEdge edge, float border) {
|
||||
YogaNative.jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
|
||||
}
|
||||
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
public void setPosition(YogaEdge edge, float position) {
|
||||
YogaNative.jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
|
||||
}
|
||||
|
||||
public void setPositionPercent(YogaEdge edge, float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
YogaNative.jni_YGNodeStyleSetWidth(mNativePointer, width);
|
||||
}
|
||||
|
||||
public void setWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setWidthAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetWidthAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setHeight(float height) {
|
||||
YogaNative.jni_YGNodeStyleSetHeight(mNativePointer, height);
|
||||
}
|
||||
|
||||
public void setHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public void setHeightAuto() {
|
||||
YogaNative.jni_YGNodeStyleSetHeightAuto(mNativePointer);
|
||||
}
|
||||
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMinWidth(float minWidth) {
|
||||
YogaNative.jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
|
||||
}
|
||||
|
||||
public void setMinWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMinHeight(float minHeight) {
|
||||
YogaNative.jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
|
||||
}
|
||||
|
||||
public void setMinHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMaxWidth(float maxWidth) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
|
||||
}
|
||||
|
||||
public void setMaxWidthPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
}
|
||||
|
||||
public void setMaxHeight(float maxheight) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
|
||||
}
|
||||
|
||||
public void setMaxHeightPercent(float percent) {
|
||||
YogaNative.jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
public float getAspectRatio() {
|
||||
return YogaNative.jni_YGNodeStyleGetAspectRatio(mNativePointer);
|
||||
}
|
||||
|
||||
public void setAspectRatio(float aspectRatio) {
|
||||
YogaNative.jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
|
||||
}
|
||||
|
||||
public float getLayoutX() {
|
||||
return mLeft;
|
||||
}
|
||||
|
||||
public float getLayoutY() {
|
||||
return mTop;
|
||||
}
|
||||
|
||||
public float getLayoutWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public float getLayoutHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public boolean getDoesLegacyStretchFlagAffectsLayout() {
|
||||
return mDoesLegacyStretchFlagAffectsLayout;
|
||||
}
|
||||
|
||||
public float getLayoutMargin(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mMarginLeft;
|
||||
case TOP:
|
||||
return mMarginTop;
|
||||
case RIGHT:
|
||||
return mMarginRight;
|
||||
case BOTTOM:
|
||||
return mMarginBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginRight : mMarginLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mMarginLeft : mMarginRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutPadding(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mPaddingLeft;
|
||||
case TOP:
|
||||
return mPaddingTop;
|
||||
case RIGHT:
|
||||
return mPaddingRight;
|
||||
case BOTTOM:
|
||||
return mPaddingBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingRight : mPaddingLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mPaddingLeft : mPaddingRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public float getLayoutBorder(YogaEdge edge) {
|
||||
switch (edge) {
|
||||
case LEFT:
|
||||
return mBorderLeft;
|
||||
case TOP:
|
||||
return mBorderTop;
|
||||
case RIGHT:
|
||||
return mBorderRight;
|
||||
case BOTTOM:
|
||||
return mBorderBottom;
|
||||
case START:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderRight : mBorderLeft;
|
||||
case END:
|
||||
return getLayoutDirection() == YogaDirection.RTL ? mBorderLeft : mBorderRight;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaDirection getLayoutDirection() {
|
||||
return YogaDirection.fromInt(mLayoutDirection);
|
||||
}
|
||||
|
||||
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
|
||||
mMeasureFunction = measureFunction;
|
||||
YogaNative.jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
|
||||
}
|
||||
|
||||
// Implementation Note: Why this method needs to stay final
|
||||
//
|
||||
// We cache the jmethodid for this method in Yoga code. This means that even if a subclass
|
||||
// were to override measure, we'd still call this implementation from layout code since the
|
||||
// overriding method will have a different jmethodid. This is final to prevent that mistake.
|
||||
@DoNotStrip
|
||||
public final long measure(float width, int widthMode, float height, int heightMode) {
|
||||
if (!isMeasureDefined()) {
|
||||
throw new RuntimeException("Measure function isn't defined!");
|
||||
}
|
||||
|
||||
return mMeasureFunction.measure(
|
||||
this,
|
||||
width,
|
||||
YogaMeasureMode.fromInt(widthMode),
|
||||
height,
|
||||
YogaMeasureMode.fromInt(heightMode));
|
||||
}
|
||||
|
||||
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
|
||||
mBaselineFunction = baselineFunction;
|
||||
YogaNative.jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
public final float baseline(float width, float height) {
|
||||
return mBaselineFunction.baseline(this, width, height);
|
||||
}
|
||||
|
||||
public boolean isMeasureDefined() {
|
||||
return mMeasureFunction != null;
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the set logger (defaults to adb log) to print out the styles, children, and computed
|
||||
* layout of the tree rooted at this node.
|
||||
*/
|
||||
public void print() {
|
||||
YogaNative.jni_YGNodePrint(mNativePointer);
|
||||
}
|
||||
|
||||
public void setStyleInputs(float[] styleInputsArray, int size) {
|
||||
YogaNative.jni_YGNodeSetStyleInputs(mNativePointer, styleInputsArray, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method replaces the child at childIndex position with the newNode received by parameter.
|
||||
* This is different than calling removeChildAt and addChildAt because this method ONLY replaces
|
||||
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
|
||||
*
|
||||
* @return the nativePointer of the newNode {@linl YogaNode}
|
||||
*/
|
||||
@DoNotStrip
|
||||
private final long replaceChild(YogaNodeJNIBase newNode, int childIndex) {
|
||||
if (mChildren == null) {
|
||||
throw new IllegalStateException("Cannot replace child. YogaNode does not have children");
|
||||
}
|
||||
mChildren.remove(childIndex);
|
||||
mChildren.add(childIndex, newNode);
|
||||
newNode.mOwner = this;
|
||||
return newNode.mNativePointer;
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
53
java/com/facebook/yoga/YogaStyleInputs.java
Normal file
53
java/com/facebook/yoga/YogaStyleInputs.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaStyleInputs {
|
||||
public static final short LAYOUT_DIRECTION = 0;
|
||||
public static final short FLEX_DIRECTION = 1;
|
||||
public static final short FLEX = 2;
|
||||
public static final short FLEX_GROW = 3;
|
||||
public static final short FLEX_SHRINK = 4;
|
||||
public static final short FLEX_BASIS = 5;
|
||||
public static final short FLEX_BASIS_PERCENT = 6;
|
||||
public static final short FLEX_BASIS_AUTO = 7;
|
||||
public static final short FLEX_WRAP = 8;
|
||||
public static final short WIDTH = 9;
|
||||
public static final short WIDTH_PERCENT = 10;
|
||||
public static final short WIDTH_AUTO = 11;
|
||||
public static final short MIN_WIDTH = 12;
|
||||
public static final short MIN_WIDTH_PERCENT = 13;
|
||||
public static final short MAX_WIDTH = 14;
|
||||
public static final short MAX_WIDTH_PERCENT = 15;
|
||||
public static final short HEIGHT = 16;
|
||||
public static final short HEIGHT_PERCENT = 17;
|
||||
public static final short HEIGHT_AUTO = 18;
|
||||
public static final short MIN_HEIGHT = 19;
|
||||
public static final short MIN_HEIGHT_PERCENT = 20;
|
||||
public static final short MAX_HEIGHT = 21;
|
||||
public static final short MAX_HEIGHT_PERCENT = 22;
|
||||
public static final short JUSTIFY_CONTENT = 23;
|
||||
public static final short ALIGN_ITEMS = 24;
|
||||
public static final short ALIGN_SELF = 25;
|
||||
public static final short ALIGN_CONTENT = 26;
|
||||
public static final short POSITION_TYPE = 27;
|
||||
public static final short ASPECT_RATIO = 28;
|
||||
public static final short OVERFLOW = 29;
|
||||
public static final short DISPLAY = 30;
|
||||
public static final short MARGIN = 31;
|
||||
public static final short MARGIN_PERCENT = 32;
|
||||
public static final short MARGIN_AUTO = 33;
|
||||
public static final short PADDING = 34;
|
||||
public static final short PADDING_PERCENT = 35;
|
||||
public static final short BORDER = 36;
|
||||
public static final short POSITION = 37;
|
||||
public static final short POSITION_PERCENT = 38;
|
||||
public static final short IS_REFERENCE_BASELINE = 39;
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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;
|
||||
|
||||
|
@@ -7,33 +7,133 @@
|
||||
#include <fb/fbjni.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/log.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "YGJTypes.h"
|
||||
|
||||
using namespace facebook::jni;
|
||||
using namespace std;
|
||||
using facebook::yoga::detail::Log;
|
||||
|
||||
struct JYogaNode : public JavaClass<JYogaNode> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNode;";
|
||||
enum YGStyleInput {
|
||||
LayoutDirection,
|
||||
FlexDirection,
|
||||
Flex,
|
||||
FlexGrow,
|
||||
FlexShrink,
|
||||
FlexBasis,
|
||||
FlexBasisPercent,
|
||||
FlexBasisAuto,
|
||||
FlexWrap,
|
||||
Width,
|
||||
WidthPercent,
|
||||
WidthAuto,
|
||||
MinWidth,
|
||||
MinWidthPercent,
|
||||
MaxWidth,
|
||||
MaxWidthPercent,
|
||||
Height,
|
||||
HeightPercent,
|
||||
HeightAuto,
|
||||
MinHeight,
|
||||
MinHeightPercent,
|
||||
MaxHeight,
|
||||
MaxHeightPercent,
|
||||
JustifyContent,
|
||||
AlignItems,
|
||||
AlignSelf,
|
||||
AlignContent,
|
||||
PositionType,
|
||||
AspectRatio,
|
||||
Overflow,
|
||||
Display,
|
||||
Margin,
|
||||
MarginPercent,
|
||||
MarginAuto,
|
||||
Padding,
|
||||
PaddingPercent,
|
||||
Border,
|
||||
Position,
|
||||
PositionPercent,
|
||||
IsReferenceBaseline,
|
||||
};
|
||||
|
||||
struct JYogaConfig : public JavaClass<JYogaConfig> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaConfig;";
|
||||
};
|
||||
class PtrJNodeMap {
|
||||
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
|
||||
std::map<YGNodeRef, size_t> ptrsToIdxs_;
|
||||
alias_ref<JNodeArray> javaNodes_;
|
||||
|
||||
struct YGConfigContext {
|
||||
global_ref<jobject>* logger;
|
||||
global_ref<jobject>* config;
|
||||
YGConfigContext() : logger(nullptr), config(nullptr) {}
|
||||
~YGConfigContext() {
|
||||
delete config;
|
||||
config = nullptr;
|
||||
delete logger;
|
||||
logger = nullptr;
|
||||
public:
|
||||
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
|
||||
PtrJNodeMap(
|
||||
alias_ref<JArrayLong> nativePointers,
|
||||
alias_ref<JNodeArray> javaNodes)
|
||||
: javaNodes_{javaNodes} {
|
||||
auto pin = nativePointers->pinCritical();
|
||||
auto ptrs = pin.get();
|
||||
for (size_t i = 0, n = pin.size(); i < n; ++i) {
|
||||
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
local_ref<JYogaNode> ref(YGNodeRef node) {
|
||||
auto idx = ptrsToIdxs_.find(node);
|
||||
if (idx == ptrsToIdxs_.end()) {
|
||||
return local_ref<JYogaNode>{};
|
||||
} else {
|
||||
return javaNodes_->getElement(idx->second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static inline weak_ref<JYogaNode>* YGNodeJobject(YGNodeRef node) {
|
||||
return reinterpret_cast<weak_ref<JYogaNode>*>(node->getContext());
|
||||
namespace {
|
||||
|
||||
union YGNodeContext {
|
||||
uintptr_t edgesSet = 0;
|
||||
void* asVoidPtr;
|
||||
};
|
||||
|
||||
class YGNodeEdges {
|
||||
uintptr_t edges_;
|
||||
|
||||
public:
|
||||
enum Edge {
|
||||
MARGIN = 1,
|
||||
PADDING = 2,
|
||||
BORDER = 4,
|
||||
};
|
||||
|
||||
YGNodeEdges(YGNodeRef node) {
|
||||
auto context = YGNodeContext{};
|
||||
context.asVoidPtr = node->getContext();
|
||||
edges_ = context.edgesSet;
|
||||
}
|
||||
|
||||
void setOn(YGNodeRef node) {
|
||||
auto context = YGNodeContext{};
|
||||
context.edgesSet = edges_;
|
||||
node->setContext(context.asVoidPtr);
|
||||
}
|
||||
|
||||
bool has(Edge edge) {
|
||||
return (edges_ & edge) == edge;
|
||||
}
|
||||
|
||||
YGNodeEdges& add(Edge edge) {
|
||||
edges_ |= edge;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
static inline local_ref<JYogaNode> YGNodeJobject(
|
||||
YGNodeRef node,
|
||||
void* layoutContext) {
|
||||
return reinterpret_cast<PtrJNodeMap*>(layoutContext)->ref(node);
|
||||
}
|
||||
|
||||
static void YGTransferLayoutDirection(
|
||||
@@ -45,19 +145,24 @@ static void YGTransferLayoutDirection(
|
||||
layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
|
||||
}
|
||||
|
||||
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
static void YGTransferLayoutOutputsRecursive(
|
||||
YGNodeRef root,
|
||||
void* layoutContext) {
|
||||
if (!root->getHasNewLayout()) {
|
||||
return;
|
||||
}
|
||||
auto obj = YGNodeJobject(root)->lockLocal();
|
||||
auto obj = YGNodeJobject(root, layoutContext);
|
||||
if (!obj) {
|
||||
YGLog(
|
||||
Log::log(
|
||||
root,
|
||||
YGLogLevelError,
|
||||
nullptr,
|
||||
"Java YGNode was GCed during layout calculation\n");
|
||||
return;
|
||||
}
|
||||
|
||||
auto edgesSet = YGNodeEdges{root};
|
||||
|
||||
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
|
||||
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
|
||||
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
|
||||
@@ -88,20 +193,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
static auto borderBottomField =
|
||||
obj->getClass()->getField<jfloat>("mBorderBottom");
|
||||
|
||||
static auto edgeSetFlagField =
|
||||
obj->getClass()->getField<jint>("mEdgeSetFlag");
|
||||
static auto hasNewLayoutField =
|
||||
obj->getClass()->getField<jboolean>("mHasNewLayout");
|
||||
static auto doesLegacyStretchBehaviour = obj->getClass()->getField<jboolean>(
|
||||
"mDoesLegacyStretchFlagAffectsLayout");
|
||||
|
||||
/* Those flags needs be in sync with YogaNode.java */
|
||||
const int MARGIN = 1;
|
||||
const int PADDING = 2;
|
||||
const int BORDER = 4;
|
||||
|
||||
int hasEdgeSetFlag = (int) obj->getFieldValue(edgeSetFlagField);
|
||||
|
||||
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
|
||||
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
|
||||
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
|
||||
@@ -109,8 +205,10 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
obj->setFieldValue<jboolean>(
|
||||
doesLegacyStretchBehaviour,
|
||||
YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root));
|
||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||
YGTransferLayoutDirection(root, obj);
|
||||
|
||||
if ((hasEdgeSetFlag & MARGIN) == MARGIN) {
|
||||
if (edgesSet.has(YGNodeEdges::MARGIN)) {
|
||||
obj->setFieldValue(
|
||||
marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
|
||||
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
|
||||
@@ -120,7 +218,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
if ((hasEdgeSetFlag & PADDING) == PADDING) {
|
||||
if (edgesSet.has(YGNodeEdges::PADDING)) {
|
||||
obj->setFieldValue(
|
||||
paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
|
||||
obj->setFieldValue(
|
||||
@@ -131,7 +229,7 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
if ((hasEdgeSetFlag & BORDER) == BORDER) {
|
||||
if (edgesSet.has(YGNodeEdges::BORDER)) {
|
||||
obj->setFieldValue(
|
||||
borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
|
||||
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
|
||||
@@ -141,32 +239,32 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
|
||||
borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
|
||||
}
|
||||
|
||||
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
|
||||
YGTransferLayoutDirection(root, obj);
|
||||
root->setHasNewLayout(false);
|
||||
|
||||
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
|
||||
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
|
||||
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i), layoutContext);
|
||||
}
|
||||
}
|
||||
|
||||
static void YGPrint(YGNodeRef node) {
|
||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||
static void YGPrint(YGNodeRef node, void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
cout << obj->toString() << endl;
|
||||
} else {
|
||||
YGLog(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelError,
|
||||
nullptr,
|
||||
"Java YGNode was GCed during layout calculation\n");
|
||||
}
|
||||
}
|
||||
|
||||
static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) {
|
||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||
static auto baselineFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaNode")
|
||||
->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
||||
return baselineFunc(obj, width, height);
|
||||
static float YGJNIBaselineFunc(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
float height,
|
||||
void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
return obj->baseline(width, height);
|
||||
} else {
|
||||
return height;
|
||||
}
|
||||
@@ -180,53 +278,17 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
|
||||
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
||||
}
|
||||
|
||||
static YGNodeRef YGJNIOnNodeClonedFunc(
|
||||
YGNodeRef oldNode,
|
||||
YGNodeRef owner,
|
||||
int childIndex) {
|
||||
auto config = oldNode->getConfig();
|
||||
if (!config) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static auto onNodeClonedFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaConfig")
|
||||
->getMethod<alias_ref<JYogaNode>(
|
||||
local_ref<JYogaNode>, local_ref<JYogaNode>, jint)>("cloneNode");
|
||||
|
||||
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
||||
auto javaConfig = context->config;
|
||||
|
||||
auto newNode = onNodeClonedFunc(
|
||||
javaConfig->get(),
|
||||
YGNodeJobject(oldNode)->lockLocal(),
|
||||
YGNodeJobject(owner)->lockLocal(),
|
||||
childIndex);
|
||||
|
||||
static auto replaceChild =
|
||||
findClassStatic("com/facebook/yoga/YogaNode")
|
||||
->getMethod<jlong(local_ref<JYogaNode>, jint)>("replaceChild");
|
||||
|
||||
jlong newNodeNativePointer =
|
||||
replaceChild(YGNodeJobject(owner)->lockLocal(), newNode, childIndex);
|
||||
|
||||
return _jlong2YGNodeRef(newNodeNativePointer);
|
||||
}
|
||||
|
||||
static YGSize YGJNIMeasureFunc(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||
static auto measureFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaNode")
|
||||
->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||
|
||||
YGMeasureMode heightMode,
|
||||
void* layoutContext) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
YGTransferLayoutDirection(node, obj);
|
||||
const auto measureResult =
|
||||
measureFunc(obj, width, widthMode, height, heightMode);
|
||||
obj->measure(width, widthMode, height, heightMode);
|
||||
|
||||
static_assert(
|
||||
sizeof(measureResult) == 8,
|
||||
@@ -240,9 +302,10 @@ static YGSize YGJNIMeasureFunc(
|
||||
|
||||
return YGSize{*measuredWidth, *measuredHeight};
|
||||
} else {
|
||||
YGLog(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelError,
|
||||
nullptr,
|
||||
"Java YGNode was GCed during layout calculation\n");
|
||||
return YGSize{
|
||||
widthMode == YGMeasureModeUndefined ? 0 : width,
|
||||
@@ -251,82 +314,50 @@ static YGSize YGJNIMeasureFunc(
|
||||
}
|
||||
}
|
||||
|
||||
struct JYogaLogLevel : public JavaClass<JYogaLogLevel> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||
};
|
||||
|
||||
static int YGJNILogFunc(
|
||||
const YGConfigRef config,
|
||||
const YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
void* layoutContext,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
int result = vsnprintf(NULL, 0, format, args);
|
||||
std::vector<char> buffer(1 + result);
|
||||
vsnprintf(buffer.data(), buffer.size(), format, args);
|
||||
|
||||
static auto logFunc =
|
||||
findClassStatic("com/facebook/yoga/YogaLogger")
|
||||
->getMethod<void(
|
||||
local_ref<JYogaNode>, local_ref<JYogaLogLevel>, jstring)>("log");
|
||||
|
||||
static auto logLevelFromInt =
|
||||
JYogaLogLevel::javaClassStatic()
|
||||
->getStaticMethod<JYogaLogLevel::javaobject(jint)>("fromInt");
|
||||
|
||||
if (auto obj = YGNodeJobject(node)->lockLocal()) {
|
||||
auto jlogger =
|
||||
reinterpret_cast<global_ref<jobject>*>(YGConfigGetContext(config));
|
||||
logFunc(
|
||||
jlogger->get(),
|
||||
obj,
|
||||
logLevelFromInt(
|
||||
JYogaLogLevel::javaClassStatic(), static_cast<jint>(level)),
|
||||
Environment::current()->NewStringUTF(buffer.data()));
|
||||
auto jloggerPtr =
|
||||
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||
if (jloggerPtr != nullptr) {
|
||||
if (auto obj = YGNodeJobject(node, layoutContext)) {
|
||||
(*jloggerPtr)
|
||||
->log(
|
||||
obj,
|
||||
JYogaLogLevel::fromInt(level),
|
||||
Environment::current()->NewStringUTF(buffer.data()));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
|
||||
jlong jni_YGNodeNew(alias_ref<jclass>) {
|
||||
const YGNodeRef node = YGNodeNew();
|
||||
node->setContext(new weak_ref<jobject>(make_weak(thiz)));
|
||||
// YGNodeSetContext(node, new weak_ref<jobject>(make_weak(thiz)));
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
node->setPrintFunc(YGPrint);
|
||||
// YGNodeSetPrintFunc(node, YGPrint);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
jlong jni_YGNodeNewWithConfig(alias_ref<jobject> thiz, jlong configPointer) {
|
||||
jlong jni_YGNodeNewWithConfig(alias_ref<jclass>, jlong configPointer) {
|
||||
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
|
||||
node->setContext(new weak_ref<jobject>(make_weak(thiz)));
|
||||
node->setPrintFunc(YGPrint);
|
||||
node->setContext(YGNodeContext{}.asVoidPtr);
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
void jni_YGNodeSetOwner(jlong nativePointer, jlong newOwnerNativePointer) {
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
const YGNodeRef newOwnerNode = _jlong2YGNodeRef(newOwnerNativePointer);
|
||||
|
||||
node->setOwner(newOwnerNode);
|
||||
}
|
||||
|
||||
jlong jni_YGNodeClone(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong nativePointer,
|
||||
alias_ref<jobject> clonedJavaObject) {
|
||||
const YGNodeRef clonedYogaNode = YGNodeClone(_jlong2YGNodeRef(nativePointer));
|
||||
clonedYogaNode->setContext(
|
||||
new weak_ref<jobject>(make_weak(clonedJavaObject)));
|
||||
return reinterpret_cast<jlong>(clonedYogaNode);
|
||||
}
|
||||
|
||||
void jni_YGNodeFree(jlong nativePointer) {
|
||||
void jni_YGNodeFree(alias_ref<jclass>, jlong nativePointer) {
|
||||
if (nativePointer == 0) {
|
||||
return;
|
||||
}
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
delete YGNodeJobject(node);
|
||||
YGNodeFree(node);
|
||||
}
|
||||
|
||||
@@ -340,15 +371,16 @@ void jni_YGNodeReset(jlong nativePointer) {
|
||||
void* context = node->getContext();
|
||||
YGNodeReset(node);
|
||||
node->setContext(context);
|
||||
node->setPrintFunc(YGPrint);
|
||||
}
|
||||
|
||||
void jni_YGNodePrint(jlong nativePointer) {
|
||||
#ifdef DEBUG
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodePrint(
|
||||
node,
|
||||
(YGPrintOptions)(
|
||||
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
|
||||
#endif
|
||||
}
|
||||
|
||||
void jni_YGNodeInsertChild(
|
||||
@@ -379,14 +411,25 @@ void jni_YGNodeCalculateLayout(
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jfloat width,
|
||||
jfloat height) {
|
||||
jfloat height,
|
||||
alias_ref<JArrayLong> nativePointers,
|
||||
alias_ref<JArrayClass<JYogaNode::javaobject>> javaNodes) {
|
||||
|
||||
void* layoutContext = nullptr;
|
||||
auto map = PtrJNodeMap{};
|
||||
if (nativePointers) {
|
||||
map = PtrJNodeMap{nativePointers, javaNodes};
|
||||
layoutContext = ↦
|
||||
}
|
||||
|
||||
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeCalculateLayout(
|
||||
YGNodeCalculateLayoutWithContext(
|
||||
root,
|
||||
static_cast<float>(width),
|
||||
static_cast<float>(height),
|
||||
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)));
|
||||
YGTransferLayoutOutputsRecursive(root);
|
||||
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
|
||||
layoutContext);
|
||||
YGTransferLayoutOutputsRecursive(root, layoutContext);
|
||||
}
|
||||
|
||||
void jni_YGNodeMarkDirty(jlong nativePointer) {
|
||||
@@ -410,7 +453,7 @@ void jni_YGNodeSetHasBaselineFunc(
|
||||
jlong nativePointer,
|
||||
jboolean hasBaselineFunc) {
|
||||
_jlong2YGNodeRef(nativePointer)
|
||||
->setBaseLineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
||||
->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
|
||||
}
|
||||
|
||||
void jni_YGNodeCopyStyle(jlong dstNativePointer, jlong srcNativePointer) {
|
||||
@@ -418,14 +461,6 @@ void jni_YGNodeCopyStyle(jlong dstNativePointer, jlong srcNativePointer) {
|
||||
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
|
||||
}
|
||||
|
||||
struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/yoga/YogaValue;";
|
||||
|
||||
static local_ref<javaobject> create(YGValue value) {
|
||||
return newInstance(value.value, static_cast<int>(value.unit));
|
||||
}
|
||||
};
|
||||
|
||||
#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \
|
||||
javatype jni_YGNodeStyleGet##name(jlong nativePointer) { \
|
||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
|
||||
@@ -438,7 +473,7 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
|
||||
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||
alias_ref<jobject>, jlong nativePointer) { \
|
||||
alias_ref<jclass>, jlong nativePointer) { \
|
||||
return JYogaValue::create( \
|
||||
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
|
||||
} \
|
||||
@@ -475,7 +510,7 @@ struct JYogaValue : public JavaClass<JYogaValue> {
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name( \
|
||||
alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||
alias_ref<jclass>, jlong nativePointer, jint edge) { \
|
||||
return JYogaValue::create(YGNodeStyleGet##name( \
|
||||
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
|
||||
} \
|
||||
@@ -514,6 +549,9 @@ YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
|
||||
|
||||
jfloat jni_YGNodeStyleGetFlex(jlong nativePointer) {
|
||||
return YGNodeStyleGetFlex(_jlong2YGNodeRef(nativePointer));
|
||||
}
|
||||
void jni_YGNodeStyleSetFlex(jlong nativePointer, jfloat value) {
|
||||
YGNodeStyleSetFlex(
|
||||
_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
|
||||
@@ -523,9 +561,6 @@ YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(FlexBasis);
|
||||
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Position);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(Margin);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Padding);
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Border);
|
||||
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Width);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MinWidth);
|
||||
@@ -537,21 +572,20 @@ YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight);
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
|
||||
|
||||
jlong jni_YGConfigNew(alias_ref<jobject>) {
|
||||
jlong jni_YGConfigNew(alias_ref<jclass>) {
|
||||
return reinterpret_cast<jlong>(YGConfigNew());
|
||||
}
|
||||
|
||||
void jni_YGConfigFree(alias_ref<jobject>, jlong nativePointer) {
|
||||
void jni_YGConfigFree(alias_ref<jclass>, jlong nativePointer) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
||||
if (context) {
|
||||
delete context;
|
||||
}
|
||||
// unique_ptr will destruct the underlying global_ref, if present.
|
||||
auto context = std::unique_ptr<global_ref<JYogaLogger>>{
|
||||
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config))};
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint feature,
|
||||
jboolean enabled) {
|
||||
@@ -561,7 +595,7 @@ void jni_YGConfigSetExperimentalFeatureEnabled(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean enabled) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -569,7 +603,7 @@ void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetUseWebDefaults(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean useWebDefaults) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -577,7 +611,7 @@ void jni_YGConfigSetUseWebDefaults(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetPrintTreeFlag(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean enable) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -585,7 +619,7 @@ void jni_YGConfigSetPrintTreeFlag(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetPointScaleFactor(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jfloat pixelsInPoint) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
@@ -593,74 +627,311 @@ void jni_YGConfigSetPointScaleFactor(
|
||||
}
|
||||
|
||||
void jni_YGConfigSetUseLegacyStretchBehaviour(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jboolean useLegacyStretchBehaviour) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
|
||||
}
|
||||
|
||||
void jni_YGConfigSetHasCloneNodeFunc(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong nativePointer,
|
||||
jboolean hasCloneNodeFunc) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
||||
if (context && context->config) {
|
||||
delete context->config;
|
||||
context->config = nullptr;
|
||||
}
|
||||
|
||||
if (hasCloneNodeFunc) {
|
||||
if (!context) {
|
||||
context = new YGConfigContext();
|
||||
YGConfigSetContext(config, context);
|
||||
}
|
||||
context->config = new global_ref<jobject>(make_global(thiz));
|
||||
YGConfigSetCloneNodeFunc(config, YGJNIOnNodeClonedFunc);
|
||||
} else {
|
||||
YGConfigSetCloneNodeFunc(config, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void jni_YGConfigSetLogger(
|
||||
alias_ref<jobject>,
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
alias_ref<jobject> logger) {
|
||||
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
|
||||
auto context = reinterpret_cast<YGConfigContext*>(YGConfigGetContext(config));
|
||||
if (context && context->logger) {
|
||||
delete context->logger;
|
||||
context->logger = nullptr;
|
||||
}
|
||||
auto context =
|
||||
reinterpret_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
|
||||
|
||||
if (logger) {
|
||||
if (!context) {
|
||||
context = new YGConfigContext();
|
||||
if (context == nullptr) {
|
||||
context = new global_ref<JYogaLogger>{};
|
||||
YGConfigSetContext(config, context);
|
||||
}
|
||||
context->logger = new global_ref<jobject>(make_global(logger));
|
||||
YGConfigSetLogger(config, YGJNILogFunc);
|
||||
|
||||
*context = make_global(static_ref_cast<JYogaLogger::javaobject>(logger));
|
||||
config->setLogger(YGJNILogFunc);
|
||||
} else {
|
||||
YGConfigSetLogger(config, NULL);
|
||||
if (context != nullptr) {
|
||||
delete context;
|
||||
YGConfigSetContext(config, nullptr);
|
||||
}
|
||||
config->setLogger(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
static void YGNodeSetStyleInputs(
|
||||
const YGNodeRef node,
|
||||
float* styleInputs,
|
||||
int size) {
|
||||
const auto end = styleInputs + size;
|
||||
auto edgesSet = YGNodeEdges{node};
|
||||
while (styleInputs < end) {
|
||||
auto styleInputKey = static_cast<YGStyleInput>((int) *styleInputs++);
|
||||
switch (styleInputKey) {
|
||||
case LayoutDirection:
|
||||
YGNodeStyleSetDirection(node, static_cast<YGDirection>(*styleInputs++));
|
||||
break;
|
||||
case FlexDirection:
|
||||
YGNodeStyleSetFlexDirection(
|
||||
node, static_cast<YGFlexDirection>(*styleInputs++));
|
||||
break;
|
||||
case Flex:
|
||||
YGNodeStyleSetFlex(node, *styleInputs++);
|
||||
break;
|
||||
case FlexGrow:
|
||||
YGNodeStyleSetFlexGrow(node, *styleInputs++);
|
||||
break;
|
||||
case FlexShrink:
|
||||
YGNodeStyleSetFlexShrink(node, *styleInputs++);
|
||||
break;
|
||||
case FlexBasis:
|
||||
YGNodeStyleSetFlexBasis(node, *styleInputs++);
|
||||
break;
|
||||
case FlexBasisPercent:
|
||||
YGNodeStyleSetFlexBasisPercent(node, *styleInputs++);
|
||||
break;
|
||||
case FlexBasisAuto:
|
||||
YGNodeStyleSetFlexBasisAuto(node);
|
||||
break;
|
||||
case FlexWrap:
|
||||
YGNodeStyleSetFlexWrap(node, static_cast<YGWrap>(*styleInputs++));
|
||||
break;
|
||||
case Width:
|
||||
YGNodeStyleSetWidth(node, *styleInputs++);
|
||||
break;
|
||||
case WidthPercent:
|
||||
YGNodeStyleSetWidthPercent(node, *styleInputs++);
|
||||
break;
|
||||
case WidthAuto:
|
||||
YGNodeStyleSetWidthAuto(node);
|
||||
break;
|
||||
case MinWidth:
|
||||
YGNodeStyleSetMinWidth(node, *styleInputs++);
|
||||
break;
|
||||
case MinWidthPercent:
|
||||
YGNodeStyleSetMinWidthPercent(node, *styleInputs++);
|
||||
break;
|
||||
case MaxWidth:
|
||||
YGNodeStyleSetMaxWidth(node, *styleInputs++);
|
||||
break;
|
||||
case MaxWidthPercent:
|
||||
YGNodeStyleSetMaxWidthPercent(node, *styleInputs++);
|
||||
break;
|
||||
case Height:
|
||||
YGNodeStyleSetHeight(node, *styleInputs++);
|
||||
break;
|
||||
case HeightPercent:
|
||||
YGNodeStyleSetHeightPercent(node, *styleInputs++);
|
||||
break;
|
||||
case HeightAuto:
|
||||
YGNodeStyleSetHeightAuto(node);
|
||||
break;
|
||||
case MinHeight:
|
||||
YGNodeStyleSetMinHeight(node, *styleInputs++);
|
||||
break;
|
||||
case MinHeightPercent:
|
||||
YGNodeStyleSetMinHeightPercent(node, *styleInputs++);
|
||||
break;
|
||||
case MaxHeight:
|
||||
YGNodeStyleSetMaxHeight(node, *styleInputs++);
|
||||
break;
|
||||
case MaxHeightPercent:
|
||||
YGNodeStyleSetMaxHeightPercent(node, *styleInputs++);
|
||||
break;
|
||||
case JustifyContent:
|
||||
YGNodeStyleSetJustifyContent(
|
||||
node, static_cast<YGJustify>(*styleInputs++));
|
||||
break;
|
||||
case AlignItems:
|
||||
YGNodeStyleSetAlignItems(node, static_cast<YGAlign>(*styleInputs++));
|
||||
break;
|
||||
case AlignSelf:
|
||||
YGNodeStyleSetAlignSelf(node, static_cast<YGAlign>(*styleInputs++));
|
||||
break;
|
||||
case AlignContent:
|
||||
YGNodeStyleSetAlignContent(node, static_cast<YGAlign>(*styleInputs++));
|
||||
break;
|
||||
case PositionType:
|
||||
YGNodeStyleSetPositionType(
|
||||
node, static_cast<YGPositionType>(*styleInputs++));
|
||||
break;
|
||||
case AspectRatio:
|
||||
YGNodeStyleSetAspectRatio(node, *styleInputs++);
|
||||
break;
|
||||
case Overflow:
|
||||
YGNodeStyleSetOverflow(node, static_cast<YGOverflow>(*styleInputs++));
|
||||
break;
|
||||
case Display:
|
||||
YGNodeStyleSetDisplay(node, static_cast<YGDisplay>(*styleInputs++));
|
||||
break;
|
||||
case Margin: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float marginValue = *styleInputs++;
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMargin(node, edge, marginValue);
|
||||
break;
|
||||
}
|
||||
case MarginPercent: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float marginPercent = *styleInputs++;
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMarginPercent(node, edge, marginPercent);
|
||||
break;
|
||||
}
|
||||
case MarginAuto: {
|
||||
edgesSet.add(YGNodeEdges::MARGIN);
|
||||
YGNodeStyleSetMarginAuto(node, static_cast<YGEdge>(*styleInputs++));
|
||||
break;
|
||||
}
|
||||
case Padding: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float paddingValue = *styleInputs++;
|
||||
edgesSet.add(YGNodeEdges::PADDING);
|
||||
YGNodeStyleSetPadding(node, edge, paddingValue);
|
||||
break;
|
||||
}
|
||||
case PaddingPercent: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float paddingPercent = *styleInputs++;
|
||||
edgesSet.add(YGNodeEdges::PADDING);
|
||||
YGNodeStyleSetPaddingPercent(node, edge, paddingPercent);
|
||||
break;
|
||||
}
|
||||
case Border: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float borderValue = *styleInputs++;
|
||||
edgesSet.add(YGNodeEdges::BORDER);
|
||||
YGNodeStyleSetBorder(node, edge, borderValue);
|
||||
break;
|
||||
}
|
||||
case Position: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float positionValue = *styleInputs++;
|
||||
YGNodeStyleSetPosition(node, edge, positionValue);
|
||||
break;
|
||||
}
|
||||
case PositionPercent: {
|
||||
auto edge = static_cast<YGEdge>(*styleInputs++);
|
||||
float positionPercent = *styleInputs++;
|
||||
YGNodeStyleSetPositionPercent(node, edge, positionPercent);
|
||||
break;
|
||||
}
|
||||
case IsReferenceBaseline: {
|
||||
YGNodeSetIsReferenceBaseline(node, *styleInputs++ == 1 ? true : false);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
edgesSet.setOn(node);
|
||||
}
|
||||
|
||||
void jni_YGNodeSetStyleInputs(
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
alias_ref<JArrayFloat> styleInputs,
|
||||
jint size) {
|
||||
float result[size];
|
||||
styleInputs->getRegion(0, size, result);
|
||||
YGNodeSetStyleInputs(_jlong2YGNodeRef(nativePointer), result, size);
|
||||
}
|
||||
|
||||
jint jni_YGNodeGetInstanceCount() {
|
||||
return YGNodeGetInstanceCount();
|
||||
}
|
||||
|
||||
local_ref<jobject> jni_YGNodeStyleGetMargin(
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) {
|
||||
return JYogaValue::create(YGValueUndefined);
|
||||
}
|
||||
return JYogaValue::create(
|
||||
YGNodeStyleGetMargin(yogaNodeRef, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetMargin(jlong nativePointer, jint edge, jfloat margin) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMargin(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(margin));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetMarginPercent(
|
||||
jlong nativePointer,
|
||||
jint edge,
|
||||
jfloat percent) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMarginPercent(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetMarginAuto(jlong nativePointer, jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetMarginAuto(yogaNodeRef, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
local_ref<jobject> jni_YGNodeStyleGetPadding(
|
||||
alias_ref<jclass>,
|
||||
jlong nativePointer,
|
||||
jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::PADDING)) {
|
||||
return JYogaValue::create(YGValueUndefined);
|
||||
}
|
||||
return JYogaValue::create(
|
||||
YGNodeStyleGetPadding(yogaNodeRef, static_cast<YGEdge>(edge)));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetPadding(jlong nativePointer, jint edge, jfloat padding) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetPadding(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(padding));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetPaddingPercent(
|
||||
jlong nativePointer,
|
||||
jint edge,
|
||||
jfloat percent) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetPaddingPercent(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
|
||||
}
|
||||
|
||||
jfloat jni_YGNodeStyleGetBorder(jlong nativePointer, jint edge) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::BORDER)) {
|
||||
return (jfloat) YGUndefined;
|
||||
}
|
||||
return (jfloat) YGNodeStyleGetBorder(yogaNodeRef, static_cast<YGEdge>(edge));
|
||||
}
|
||||
|
||||
void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) {
|
||||
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
|
||||
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::BORDER).setOn(yogaNodeRef);
|
||||
YGNodeStyleSetBorder(
|
||||
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
|
||||
}
|
||||
|
||||
#define YGMakeNativeMethod(name) makeNativeMethod(#name, name)
|
||||
#define YGMakeCriticalNativeMethod(name) makeCriticalNativeMethod(#name, name)
|
||||
#define YGMakeCriticalNativeMethod(name) \
|
||||
makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(#name, name)
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
return initialize(vm, [] {
|
||||
registerNatives(
|
||||
"com/facebook/yoga/YogaNode",
|
||||
"com/facebook/yoga/YogaNative",
|
||||
{
|
||||
YGMakeNativeMethod(jni_YGNodeNew),
|
||||
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeFree),
|
||||
YGMakeNativeMethod(jni_YGNodeFree),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeReset),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeClearChildren),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeInsertChild),
|
||||
@@ -689,11 +960,13 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignContent),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPositionType),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionType),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexWrap),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexWrap),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetOverflow),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetOverflow),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDisplay),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDisplay),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlex),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlex),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexGrow),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexGrow),
|
||||
@@ -739,12 +1012,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
||||
YGMakeNativeMethod(jni_YGNodeClone),
|
||||
YGMakeCriticalNativeMethod(jni_YGNodeSetOwner),
|
||||
});
|
||||
registerNatives(
|
||||
"com/facebook/yoga/YogaConfig",
|
||||
{
|
||||
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
||||
YGMakeNativeMethod(jni_YGConfigNew),
|
||||
YGMakeNativeMethod(jni_YGConfigFree),
|
||||
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled),
|
||||
@@ -753,7 +1021,6 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
||||
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
|
||||
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
|
||||
YGMakeNativeMethod(jni_YGConfigSetLogger),
|
||||
YGMakeNativeMethod(jni_YGConfigSetHasCloneNodeFunc),
|
||||
YGMakeNativeMethod(
|
||||
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
|
||||
});
|
||||
|
44
java/jni/YGJTypes.cpp
Normal file
44
java/jni/YGJTypes.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include "YGJTypes.h"
|
||||
|
||||
using facebook::jni::alias_ref;
|
||||
using facebook::jni::local_ref;
|
||||
|
||||
jfloat JYogaNode::baseline(jfloat width, jfloat height) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()->getMethod<jfloat(jfloat, jfloat)>("baseline");
|
||||
return javaMethod(self(), width, height);
|
||||
}
|
||||
|
||||
jlong JYogaNode::measure(
|
||||
jfloat width,
|
||||
jint widthMode,
|
||||
jfloat height,
|
||||
jint heightMode) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
|
||||
return javaMethod(self(), width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
facebook::jni::local_ref<JYogaLogLevel> JYogaLogLevel::fromInt(jint logLevel) {
|
||||
static auto javaMethod =
|
||||
javaClassStatic()->getStaticMethod<alias_ref<JYogaLogLevel>(jint)>(
|
||||
"fromInt");
|
||||
return javaMethod(javaClassStatic(), logLevel);
|
||||
}
|
||||
|
||||
void JYogaLogger::log(
|
||||
facebook::jni::alias_ref<JYogaNode> node,
|
||||
facebook::jni::alias_ref<JYogaLogLevel> logLevel,
|
||||
jstring message) {
|
||||
static auto javaMethod =
|
||||
javaClassLocal()
|
||||
->getMethod<void(
|
||||
alias_ref<JYogaNode>, alias_ref<JYogaLogLevel>, jstring)>("log");
|
||||
javaMethod(self(), node, logLevel, message);
|
||||
}
|
38
java/jni/YGJTypes.h
Normal file
38
java/jni/YGJTypes.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include <fb/fbjni.h>
|
||||
#include <yoga/YGValue.h>
|
||||
|
||||
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
|
||||
|
||||
jfloat baseline(jfloat width, jfloat height);
|
||||
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
|
||||
};
|
||||
|
||||
struct JYogaLogLevel : public facebook::jni::JavaClass<JYogaLogLevel> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
|
||||
|
||||
static facebook::jni::local_ref<JYogaLogLevel> fromInt(jint);
|
||||
};
|
||||
|
||||
struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogger";
|
||||
|
||||
void log(
|
||||
facebook::jni::alias_ref<JYogaNode>,
|
||||
facebook::jni::alias_ref<JYogaLogLevel>,
|
||||
jstring);
|
||||
};
|
||||
|
||||
struct JYogaValue : public facebook::jni::JavaClass<JYogaValue> {
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/yoga/YogaValue;";
|
||||
|
||||
static facebook::jni::local_ref<javaobject> create(YGValue value) {
|
||||
return newInstance(value.value, static_cast<int>(value.unit));
|
||||
}
|
||||
};
|
500
java/tests/com/facebook/yoga/BatchingAPITests.java
Normal file
500
java/tests/com/facebook/yoga/BatchingAPITests.java
Normal file
@@ -0,0 +1,500 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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 org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class BatchingAPITests {
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
|
||||
return TestParametrization.nodeFactories();
|
||||
}
|
||||
|
||||
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
|
||||
|
||||
@Test
|
||||
public void testStyleInputLayoutDirection() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.LAYOUT_DIRECTION, YogaDirection.LTR.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
assertEquals(root.getLayoutDirection(), YogaDirection.LTR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexDirection() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_DIRECTION, YogaFlexDirection.ROW.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlexDirection(), YogaFlexDirection.ROW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlex() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlex(), 5f, 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexGrow() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_GROW, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlexGrow(), 5f, 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexShrink() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_SHRINK, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlexShrink(), 5f, 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexBasis() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_BASIS, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlexBasis(), new YogaValue(5f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexBasisPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_BASIS_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getFlexBasis(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexBasisAuto() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_BASIS_AUTO};
|
||||
root.setStyleInputs(arr, 1);
|
||||
assertEquals(root.getFlexBasis(), YogaValue.AUTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputFlexWrap() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.FLEX_WRAP, YogaWrap.WRAP.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getWrap(), YogaWrap.WRAP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputWidth() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.WIDTH, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputWidthPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.WIDTH_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getWidth(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputWidthAuto() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.WIDTH_AUTO};
|
||||
root.setStyleInputs(arr, 1);
|
||||
assertEquals(root.getWidth(), YogaValue.AUTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMinWidth() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MIN_WIDTH, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMinWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMinWidthPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MIN_WIDTH_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMinWidth(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMaxWidth() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MAX_WIDTH, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMaxWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMaxWidthPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MAX_WIDTH_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMaxWidth(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputHeight() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.HEIGHT, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getHeight(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputHeightPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.HEIGHT_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getHeight(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputHeightAuto() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.HEIGHT_AUTO};
|
||||
root.setStyleInputs(arr, 1);
|
||||
assertEquals(root.getHeight(), YogaValue.AUTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMinHeight() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MIN_HEIGHT, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMinHeight(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMinHeightPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MIN_HEIGHT_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMinHeight(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMaxHeight() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MAX_HEIGHT, 50f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMaxHeight(), new YogaValue(50f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMaxHeightPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MAX_HEIGHT_PERCENT, 5f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMaxHeight(), new YogaValue(5f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputJustiyContent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.JUSTIFY_CONTENT, YogaJustify.CENTER.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getJustifyContent(), YogaJustify.CENTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputAlignItems() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.ALIGN_ITEMS, YogaAlign.BASELINE.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getAlignItems(), YogaAlign.BASELINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputAlignSelf() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.ALIGN_SELF, YogaAlign.BASELINE.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getAlignSelf(), YogaAlign.BASELINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputAlignContent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.ALIGN_CONTENT, YogaAlign.BASELINE.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getAlignContent(), YogaAlign.BASELINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputPositionType() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.POSITION_TYPE, YogaPositionType.ABSOLUTE.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getPositionType(), YogaPositionType.ABSOLUTE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputAspectRatio() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.ASPECT_RATIO, 2f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getAspectRatio(), 2f, 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputOverflow() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.OVERFLOW, YogaOverflow.HIDDEN.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getOverflow(), YogaOverflow.HIDDEN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputDisplay() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.DISPLAY, YogaDisplay.NONE.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getDisplay(), YogaDisplay.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMargin() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MARGIN, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getMargin(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMarginPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MARGIN_PERCENT, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getMargin(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputMarginAuto() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.MARGIN_AUTO, YogaEdge.LEFT.intValue()};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.getMargin(YogaEdge.LEFT), YogaValue.AUTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputPadding() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.PADDING, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getPadding(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputPaddingPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.PADDING_PERCENT, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getPadding(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputBorder() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.BORDER, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getBorder(YogaEdge.LEFT), 12f, 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputPosition() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.POSITION, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getPosition(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputPositionPercent() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.POSITION_PERCENT, YogaEdge.LEFT.intValue(), 12f};
|
||||
root.setStyleInputs(arr, 3);
|
||||
assertEquals(root.getPosition(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.PERCENT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputIsReferenceBaseline() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
float[] arr = new float[]{YogaStyleInputs.IS_REFERENCE_BASELINE, 1f};
|
||||
root.setStyleInputs(arr, 2);
|
||||
assertEquals(root.isReferenceBaseline(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStyleInputs() {
|
||||
YogaConfig config = new YogaConfig();
|
||||
final YogaNode root = createNode(config);
|
||||
int count = 0;
|
||||
float[] arr = new float[100];
|
||||
arr[count++] = YogaStyleInputs.FLEX_DIRECTION;
|
||||
arr[count++] = YogaFlexDirection.ROW.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.FLEX;
|
||||
arr[count++] = 5f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.FLEX_GROW;
|
||||
arr[count++] = 5f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.FLEX_SHRINK;
|
||||
arr[count++] = 5f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.FLEX_BASIS_AUTO;
|
||||
|
||||
arr[count++] = YogaStyleInputs.FLEX_WRAP;
|
||||
arr[count++] = YogaWrap.WRAP.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.WIDTH;
|
||||
arr[count++] = 50f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.MIN_WIDTH;
|
||||
arr[count++] = 50f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.MAX_WIDTH;
|
||||
arr[count++] = 50f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.HEIGHT;
|
||||
arr[count++] = 5f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.MIN_HEIGHT;
|
||||
arr[count++] = 50f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.MAX_HEIGHT;
|
||||
arr[count++] = 50f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.JUSTIFY_CONTENT;
|
||||
arr[count++] = YogaJustify.CENTER.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.ALIGN_ITEMS;
|
||||
arr[count++] = YogaAlign.BASELINE.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.ALIGN_SELF;
|
||||
arr[count++] = YogaAlign.BASELINE.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.ALIGN_CONTENT;
|
||||
arr[count++] = YogaAlign.BASELINE.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.POSITION_TYPE;
|
||||
arr[count++] = YogaPositionType.ABSOLUTE.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.ASPECT_RATIO;
|
||||
arr[count++] = 2f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.OVERFLOW;
|
||||
arr[count++] = YogaOverflow.HIDDEN.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.DISPLAY;
|
||||
arr[count++] = YogaDisplay.NONE.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.MARGIN_AUTO;
|
||||
arr[count++] = YogaEdge.LEFT.intValue();
|
||||
|
||||
arr[count++] = YogaStyleInputs.PADDING;
|
||||
arr[count++] = YogaEdge.LEFT.intValue();
|
||||
arr[count++] = 12f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.BORDER;
|
||||
arr[count++] = YogaEdge.LEFT.intValue();
|
||||
arr[count++] = 12f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.POSITION_PERCENT;
|
||||
arr[count++] = YogaEdge.LEFT.intValue();
|
||||
arr[count++] = 12f;
|
||||
|
||||
arr[count++] = YogaStyleInputs.IS_REFERENCE_BASELINE;
|
||||
arr[count++] = 1f;
|
||||
|
||||
root.setStyleInputs(arr, count);
|
||||
|
||||
assertEquals(root.getFlexDirection(), YogaFlexDirection.ROW);
|
||||
assertEquals(root.getFlex(), 5f, 0.0f);
|
||||
assertEquals(root.getFlexGrow(), 5f, 0.0f);
|
||||
assertEquals(root.getFlexShrink(), 5f, 0.0f);
|
||||
assertEquals(root.getFlexBasis(), YogaValue.AUTO);
|
||||
assertEquals(root.getWrap(), YogaWrap.WRAP);
|
||||
assertEquals(root.getWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
assertEquals(root.getMinWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
assertEquals(root.getMaxWidth(), new YogaValue(50f, YogaUnit.POINT));
|
||||
assertEquals(root.getHeight(), new YogaValue(5f, YogaUnit.POINT));
|
||||
assertEquals(root.getMinHeight(), new YogaValue(50f, YogaUnit.POINT));
|
||||
assertEquals(root.getMaxHeight(), new YogaValue(50f, YogaUnit.POINT));
|
||||
assertEquals(root.getJustifyContent(), YogaJustify.CENTER);
|
||||
assertEquals(root.getAlignItems(), YogaAlign.BASELINE);
|
||||
assertEquals(root.getAlignSelf(), YogaAlign.BASELINE);
|
||||
assertEquals(root.getAlignContent(), YogaAlign.BASELINE);
|
||||
assertEquals(root.getPositionType(), YogaPositionType.ABSOLUTE);
|
||||
assertEquals(root.getAspectRatio(), 2f, 0.0f);
|
||||
assertEquals(root.getOverflow(), YogaOverflow.HIDDEN);
|
||||
assertEquals(root.getDisplay(), YogaDisplay.NONE);
|
||||
assertEquals(root.getMargin(YogaEdge.LEFT), YogaValue.AUTO);
|
||||
assertEquals(root.getPadding(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.POINT));
|
||||
assertEquals(root.getBorder(YogaEdge.LEFT), 12f, 0.0f);
|
||||
assertEquals(root.getPosition(YogaEdge.LEFT), new YogaValue(12f, YogaUnit.PERCENT));
|
||||
assertEquals(root.isReferenceBaseline(), true);
|
||||
}
|
||||
|
||||
private YogaNode createNode(YogaConfig config) {
|
||||
return mNodeFactory.create(config);
|
||||
}
|
||||
}
|
@@ -15,12 +15,12 @@ public class TestParametrization {
|
||||
NodeFactory nodeFactory = new NodeFactory() {
|
||||
@Override
|
||||
public YogaNode create() {
|
||||
return new YogaNode();
|
||||
return YogaNode.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YogaNode create(YogaConfig config) {
|
||||
return new YogaNode(config);
|
||||
return YogaNode.create(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -30,9 +30,9 @@ public class YogaNodeTest {
|
||||
|
||||
@Test
|
||||
public void testInit() {
|
||||
final int refCount = YogaNode.jni_YGNodeGetInstanceCount();
|
||||
final int refCount = YogaNative.jni_YGNodeGetInstanceCount();
|
||||
final YogaNode node = createNode();
|
||||
assertEquals(refCount + 1, YogaNode.jni_YGNodeGetInstanceCount());
|
||||
assertEquals(refCount + 1, YogaNative.jni_YGNodeGetInstanceCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -233,112 +233,6 @@ public class YogaNodeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNode() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
YogaNode root = createNode(config);
|
||||
YogaNode child = createNode(config);
|
||||
YogaNode grandChild = createNode(config);
|
||||
root.addChildAt(child, 0);
|
||||
child.addChildAt(grandChild, 0);
|
||||
child.setFlexDirection(YogaFlexDirection.ROW);
|
||||
|
||||
YogaNode clonedChild = child.clone();
|
||||
|
||||
assertNotSame(clonedChild, child);
|
||||
|
||||
assertEquals(YogaFlexDirection.ROW, child.getFlexDirection());
|
||||
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
|
||||
|
||||
// Verify the cloning is shallow on the List of children
|
||||
assertEquals(1, child.getChildCount());
|
||||
assertEquals(child.getChildCount(), clonedChild.getChildCount());
|
||||
assertEquals(child.getChildAt(0), clonedChild.getChildAt(0));
|
||||
|
||||
child.removeChildAt(0);
|
||||
assertEquals(0, child.getChildCount());
|
||||
assertEquals(1, clonedChild.getChildCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneWithNewChildren() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
YogaNode root = createNode(config);
|
||||
YogaNode child = createNode(config);
|
||||
YogaNode grandChild = createNode(config);
|
||||
root.addChildAt(child, 0);
|
||||
child.addChildAt(grandChild, 0);
|
||||
child.setFlexDirection(YogaFlexDirection.ROW);
|
||||
|
||||
YogaNode clonedChild = child.cloneWithNewChildren();
|
||||
|
||||
assertNotSame(clonedChild, child);
|
||||
assertEquals(YogaFlexDirection.ROW, clonedChild.getFlexDirection());
|
||||
assertEquals(child.getFlexDirection(), clonedChild.getFlexDirection());
|
||||
assertEquals(0, clonedChild.getChildCount());
|
||||
assertEquals(1, child.getChildCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneNodeListener() throws Exception {
|
||||
final AtomicBoolean onNodeClonedExecuted = new AtomicBoolean(false);
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setOnCloneNode(
|
||||
new YogaNodeCloneFunction() {
|
||||
@Override
|
||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||
onNodeClonedExecuted.set(true);
|
||||
return oldNode.clone();
|
||||
}
|
||||
});
|
||||
YogaNode root = createNode(config);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(100f);
|
||||
YogaNode child0 = createNode(config);
|
||||
root.addChildAt(child0, 0);
|
||||
child0.setWidth(50f);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
// Force a clone to happen.
|
||||
final YogaNode root2 = root.clone();
|
||||
root2.setWidth(200f);
|
||||
root2.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
|
||||
assertTrue(onNodeClonedExecuted.get());
|
||||
assertEquals(1, root2.getChildCount());
|
||||
YogaNode clonedNode = root2.getChildAt(0);
|
||||
assertNotSame(child0, clonedNode);
|
||||
assertEquals(child0.getWidth(), clonedNode.getWidth());
|
||||
assertEquals(50f, clonedNode.getWidth().value, 0.01f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnNodeClonedLeak() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.setOnCloneNode(
|
||||
new YogaNodeCloneFunction() {
|
||||
@Override
|
||||
public YogaNode cloneNode(YogaNode oldNode, YogaNode owner, int childIndex) {
|
||||
return oldNode.clone();
|
||||
}
|
||||
});
|
||||
config.setOnCloneNode(null);
|
||||
WeakReference<Object> ref = new WeakReference<Object>(config);
|
||||
// noinspection UnusedAssignment
|
||||
config = null;
|
||||
// try and free for the next 5 seconds, usually it works after the
|
||||
// first GC attempt.
|
||||
for (int i = 0; i < 50; i++) {
|
||||
System.gc();
|
||||
if (ref.get() == null) {
|
||||
// free successfully
|
||||
return;
|
||||
}
|
||||
Thread.sleep(100);
|
||||
}
|
||||
fail("YogaConfig leaked");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlagShouldDiffLayoutWithoutLegacyStretchBehaviour() throws Exception {
|
||||
YogaConfig config = new YogaConfig();
|
||||
@@ -359,7 +253,7 @@ public class YogaNodeTest {
|
||||
root_child0_child0_child0.setFlexShrink(1);
|
||||
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
||||
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
assertFalse(root.getDoesLegacyStretchFlagAffectsLayout());
|
||||
assertFalse(((YogaNodeJNIBase) root).getDoesLegacyStretchFlagAffectsLayout());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -32,7 +32,7 @@ yoga_cxx_library(
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-Wno-unused-parameter",
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
],
|
||||
platforms = (ANDROID,),
|
||||
visibility = ["PUBLIC"],
|
||||
|
@@ -234,9 +234,9 @@ class FBEXPORT JClass : public JavaClass<JClass, JObject, jclass> {
|
||||
/// makeNativeMethod("nativeMethodWithExplicitDescriptor",
|
||||
/// "(Lcom/facebook/example/MyClass;)V",
|
||||
/// methodWithExplicitDescriptor),
|
||||
/// makeCriticalNativeMethod("criticalNativeMethodWithAutomaticDescriptor",
|
||||
/// makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED("criticalNativeMethodWithAutomaticDescriptor",
|
||||
/// criticalNativeMethodWithAutomaticDescriptor),
|
||||
/// makeCriticalNativeMethod("criticalNativeMethodWithExplicitDescriptor",
|
||||
/// makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED("criticalNativeMethodWithExplicitDescriptor",
|
||||
/// "(IIF)Z",
|
||||
/// criticalNativeMethodWithExplicitDescriptor),
|
||||
/// });
|
||||
|
@@ -96,6 +96,55 @@ struct CriticalMethod<R (*)(Args...)> {
|
||||
// signature with an exclamation mark.
|
||||
// Android v8+ supports fast calls by annotating methods:
|
||||
// https://source.android.com/devices/tech/dalvik/improvements#faster-native-methods
|
||||
//
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
//
|
||||
// "Fast" calls are only on the order of a few dozen NANO-seconds faster than
|
||||
// regular JNI calls. If your method does almost aaanything of consequence - if
|
||||
// you loop, if you write to a log, if you call another method, if you even
|
||||
// simply allocate or deallocate - then the method body will significantly
|
||||
// outweigh the method overhead.
|
||||
//
|
||||
// The difference between a regular JNI method and a "FastJNI" method (as
|
||||
// they're called inside the runtime) is that a FastJNI method doesn't mark the
|
||||
// thread as executing native code, and by skipping that avoids the locking and
|
||||
// thread state check overhead of interacting with the Garbage Collector.
|
||||
//
|
||||
// To understand why this is dangerous, you need to understand a bit about the
|
||||
// GC. In order to perform its work the GC needs to have at least one (usually
|
||||
// two in modern implementations) "stop the world" checkpoints where it can
|
||||
// guarantee that all managed-code execution is paused. The VM performs these
|
||||
// checkpoints at allocations, method boundaries, and each backward branch (ie
|
||||
// anytime you loop). When the GC wants to run, it will signal to all managed
|
||||
// threads that they should pause at the next checkpoint, and then it will wait
|
||||
// for every thread in the system to transition from the "runnable" state into a
|
||||
// "waiting" state. Once every thread has stopped, the GC thread can perform the
|
||||
// work it needs to and then it will trigger the execution threads to resume.
|
||||
//
|
||||
// JNI methods fit neatly into the above paradigm: They're still methods, so
|
||||
// they perform GC checkpoints at method entry and method exit. JNI methods also
|
||||
// perform checkpoints at any JNI boundary crossing - ie, any time you call
|
||||
// GetObjectField etc. Because access to managed objects from native code is
|
||||
// tightly controlled, the VM is able to mark threads executing native methods
|
||||
// into a special "native" state which the GC is able to ignore: It knows they
|
||||
// can't touch managed objects (without hitting a checkpoint) so it doesn't care
|
||||
// about them.
|
||||
//
|
||||
// JNI critical methods don't perform that "runnable" -> "native" thread state
|
||||
// transition. Skipping that transition allows them to shave about 20ns off
|
||||
// their total execution time, but it means that the GC has to wait for them to
|
||||
// complete before it can move forward. If a critical method begins blocking,
|
||||
// say on a long loop, or an I/O operation, or on perhaps a mutex, then the GC
|
||||
// will also block, and because the GC is blocking the entire rest of the VM
|
||||
// (which is waiting on the GC) will block. If the critical method is blocking
|
||||
// on a mutex that's already held by the GC - for example, the VM's internal
|
||||
// weak_globals_lock_ which guards modifications to the weak global reference
|
||||
// table (and is required in order to create or free a weak_ref<>) - then you
|
||||
// have a system-wide deadlock.
|
||||
|
||||
// prefixes a JNI method signature as android "fast call".
|
||||
#if defined(__ANDROID__) && defined(FBJNI_WITH_FAST_CALLS)
|
||||
@@ -106,20 +155,25 @@ struct CriticalMethod<R (*)(Args...)> {
|
||||
|
||||
#define makeCriticalNativeMethod3(name, desc, func) \
|
||||
makeNativeMethod3( \
|
||||
name, \
|
||||
FBJNI_PREFIX_FAST_CALL(desc), \
|
||||
::facebook::jni::detail::CriticalMethod<decltype(&func)>::call<&func>)
|
||||
name, \
|
||||
FBJNI_PREFIX_FAST_CALL(desc), \
|
||||
::facebook::jni::detail::CriticalMethod<decltype(&func)>::call<&func>)
|
||||
|
||||
#define makeCriticalNativeMethod2(name, func) \
|
||||
makeCriticalNativeMethod3( \
|
||||
name, \
|
||||
::facebook::jni::detail::CriticalMethod<decltype(&func)>::desc<&func>(), \
|
||||
func)
|
||||
#define makeCriticalNativeMethod2(name, func) \
|
||||
makeCriticalNativeMethod3( \
|
||||
name, \
|
||||
::facebook::jni::detail::CriticalMethod<decltype(&func)>::desc<&func>(), \
|
||||
func)
|
||||
|
||||
#define makeCriticalNativeMethodN(a, b, c, count, ...) \
|
||||
makeCriticalNativeMethod##count
|
||||
#define makeCriticalNativeMethod(...) \
|
||||
makeCriticalNativeMethodN(__VA_ARGS__, 3, 2)(__VA_ARGS__)
|
||||
#define makeCriticalNativeMethodN(a, b, c, count, ...) makeCriticalNativeMethod ## count
|
||||
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// YOU ALMOST CERTAINLY DO NOT NEED THIS AND IT IS DANGEROUS.
|
||||
// See above for an explanation.
|
||||
#define makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...) makeCriticalNativeMethodN(__VA_ARGS__, 3, 2)(__VA_ARGS__)
|
||||
|
||||
}}
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
load("//tools/build_defs/oss:yoga_defs.bzl", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library")
|
||||
|
||||
COMPILER_FLAGS = [
|
||||
"-std=c++11",
|
||||
"-std=c++14",
|
||||
"-Wno-missing-prototypes",
|
||||
]
|
||||
|
||||
|
@@ -55,5 +55,5 @@ function installAndroidSDK {
|
||||
echo > $ANDROID_HOME/licenses/android-sdk-license
|
||||
echo -n d56f5187479451eabf01fb78af6dfcb131a6481e > $ANDROID_HOME/licenses/android-sdk-license
|
||||
|
||||
installsdk 'build-tools;25.0.3' 'build-tools;26.0.2' 'platforms;android-25' 'platforms;android-26' 'ndk-bundle' 'extras;android;m2repository'
|
||||
installsdk 'build-tools;25.0.3' 'build-tools;26.0.2' 'platforms;android-25' 'platforms;android-26' 'ndk-bundle' 'extras;android;m2repository' 'cmake;3.6.4111459'
|
||||
}
|
||||
|
@@ -200,7 +200,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_column_as_reference) {
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -245,7 +245,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -298,7 +298,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -347,7 +347,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -392,7 +392,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -439,7 +439,7 @@ TEST(YogaTest, align_baseline_parent_using_child_in_row_as_reference) {
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -484,7 +484,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetPadding(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -533,7 +533,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeLeft, 100);
|
||||
YGNodeStyleSetMargin(root_child1_child1, YGEdgeRight, 100);
|
||||
@@ -673,7 +673,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
@@ -724,7 +724,7 @@ TEST(
|
||||
|
||||
const YGNodeRef root_child1_child1 =
|
||||
createYGNode(config, YGFlexDirectionColumn, 500, 400, false);
|
||||
root_child1_child1->setBaseLineFunc(_baselineFunc);
|
||||
root_child1_child1->setBaselineFunc(_baselineFunc);
|
||||
YGNodeSetIsReferenceBaseline(root_child1_child1, true);
|
||||
YGNodeInsertChild(root_child1, root_child1_child1, 1);
|
||||
|
||||
|
@@ -34,7 +34,7 @@ TEST(YogaTest, align_baseline_customer_func) {
|
||||
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||
root_child1_child0->setContext(&baselineValue);
|
||||
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||
root_child1_child0->setBaseLineFunc(_baseline);
|
||||
root_child1_child0->setBaselineFunc(_baseline);
|
||||
YGNodeStyleSetHeight(root_child1_child0, 20);
|
||||
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
||||
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
|
69
tests/YGConfigTest.cpp
Normal file
69
tests/YGConfigTest.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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/YGDisplayTest.html
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/YGConfig.h>
|
||||
#include <yoga/YGNode.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
struct ConfigCloningTest : public ::testing::Test {
|
||||
std::unique_ptr<YGConfig, std::function<void(YGConfig*)>> config;
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
|
||||
static YGNode clonedNode;
|
||||
static YGNodeRef cloneNode(YGNodeRef, YGNodeRef, int) {
|
||||
return &clonedNode;
|
||||
}
|
||||
static YGNodeRef doNotClone(YGNodeRef, YGNodeRef, int) {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ConfigCloningTest, uses_values_provided_by_cloning_callback) {
|
||||
config->setCloneNodeCallback(cloneNode);
|
||||
|
||||
YGNode node{}, owner{};
|
||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||
|
||||
ASSERT_EQ(clone, &clonedNode);
|
||||
}
|
||||
|
||||
TEST_F(
|
||||
ConfigCloningTest,
|
||||
falls_back_to_regular_cloning_if_callback_returns_null) {
|
||||
config->setCloneNodeCallback(doNotClone);
|
||||
|
||||
YGNode node{}, owner{};
|
||||
auto clone = config->cloneNode(&node, &owner, 0, nullptr);
|
||||
|
||||
ASSERT_NE(clone, nullptr);
|
||||
YGNodeFree(clone);
|
||||
}
|
||||
|
||||
TEST_F(ConfigCloningTest, can_clone_with_context) {
|
||||
config->setCloneNodeCallback([](YGNodeRef, YGNodeRef, int, void* context) {
|
||||
return (YGNodeRef) context;
|
||||
});
|
||||
|
||||
YGNode node{}, owner{}, clone{};
|
||||
ASSERT_EQ(config->cloneNode(&node, &owner, 0, &clone), &clone);
|
||||
}
|
||||
|
||||
void ConfigCloningTest::SetUp() {
|
||||
config = {YGConfigNew(), YGConfigFree};
|
||||
}
|
||||
|
||||
void ConfigCloningTest::TearDown() {
|
||||
config.reset();
|
||||
}
|
||||
|
||||
YGNode ConfigCloningTest::clonedNode = {};
|
@@ -8,45 +8,51 @@
|
||||
#include <yoga/YGNode.h>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
static YGSize _measure(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*)node->getContext();
|
||||
static YGSize _measure(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
int* measureCount = (int*) node->getContext();
|
||||
if (measureCount) {
|
||||
(*measureCount)++;
|
||||
}
|
||||
|
||||
return YGSize{
|
||||
.width = 10, .height = 10,
|
||||
.width = 10,
|
||||
.height = 10,
|
||||
};
|
||||
}
|
||||
|
||||
static YGSize _simulate_wrapping_text(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _simulate_wrapping_text(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
if (widthMode == YGMeasureModeUndefined || width >= 68) {
|
||||
return YGSize{.width = 68, .height = 16};
|
||||
}
|
||||
|
||||
return YGSize{
|
||||
.width = 50, .height = 32,
|
||||
.width = 50,
|
||||
.height = 32,
|
||||
};
|
||||
}
|
||||
|
||||
static YGSize _measure_assert_negative(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _measure_assert_negative(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
EXPECT_GE(width, 0);
|
||||
EXPECT_GE(height, 0);
|
||||
|
||||
return YGSize{
|
||||
.width = 0, .height = 0,
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -148,7 +154,6 @@ TEST(YogaTest, dont_measure_when_min_equals_max_percentages) {
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
|
||||
TEST(YogaTest, measure_nodes_with_margin_auto_and_stretch) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeStyleSetWidth(root, 500);
|
||||
@@ -593,7 +598,7 @@ TEST(YogaTest, can_nullify_measure_func_on_any_node) {
|
||||
const YGNodeRef root = YGNodeNew();
|
||||
YGNodeInsertChild(root, YGNodeNew(), 0);
|
||||
root->setMeasureFunc(nullptr);
|
||||
ASSERT_TRUE(root->getMeasure() == NULL);
|
||||
ASSERT_TRUE(!root->hasMeasureFunc());
|
||||
YGNodeFreeRecursive(root);
|
||||
}
|
||||
|
||||
@@ -635,14 +640,16 @@ TEST(YogaTest, cant_call_negative_measure_horizontal) {
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
static YGSize _measure_90_10(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
static YGSize _measure_90_10(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode) {
|
||||
|
||||
return YGSize{
|
||||
.width = 90, .height = 10,
|
||||
.width = 90,
|
||||
.height = 10,
|
||||
};
|
||||
}
|
||||
|
||||
|
146
tests/YGNodeCallbackTest.cpp
Normal file
146
tests/YGNodeCallbackTest.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/YGNode.h>
|
||||
#include <ostream>
|
||||
|
||||
inline bool operator==(const YGSize& lhs, const YGSize& rhs) {
|
||||
return lhs.width == rhs.width && lhs.height == rhs.height;
|
||||
}
|
||||
|
||||
void PrintTo(const YGSize&, std::ostream*);
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_initial) {
|
||||
auto n = YGNode{};
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_with_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
return YGSize{};
|
||||
});
|
||||
ASSERT_TRUE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, measure_with_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
return YGSize{w * wm, h / hm};
|
||||
});
|
||||
|
||||
ASSERT_EQ(
|
||||
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr),
|
||||
(YGSize{23, 12}));
|
||||
}
|
||||
|
||||
TEST(YGNode, measure_with_context_measure_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void* ctx) {
|
||||
return *(YGSize*) ctx;
|
||||
});
|
||||
|
||||
auto result = YGSize{123.4, -56.7};
|
||||
ASSERT_EQ(
|
||||
n.measure(0, YGMeasureModeUndefined, 0, YGMeasureModeUndefined, &result),
|
||||
result);
|
||||
}
|
||||
|
||||
TEST(YGNode, switching_measure_fn_types) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
return YGSize{};
|
||||
});
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float w, YGMeasureMode wm, float h, YGMeasureMode hm) {
|
||||
return YGSize{w * wm, h / hm};
|
||||
});
|
||||
|
||||
ASSERT_EQ(
|
||||
n.measure(23, YGMeasureModeExactly, 24, YGMeasureModeAtMost, nullptr),
|
||||
(YGSize{23, 12}));
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_after_unset) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc([](YGNode*, float, YGMeasureMode, float, YGMeasureMode) {
|
||||
return YGSize{};
|
||||
});
|
||||
|
||||
n.setMeasureFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasMeasureFunc_after_unset_context) {
|
||||
auto n = YGNode{};
|
||||
n.setMeasureFunc(
|
||||
[](YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*) {
|
||||
return YGSize{};
|
||||
});
|
||||
|
||||
n.setMeasureFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_initial) {
|
||||
auto n = YGNode{};
|
||||
ASSERT_FALSE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_with_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||
ASSERT_TRUE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, baseline_with_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float w, float h) { return w + h; });
|
||||
|
||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, nullptr), 3.75f);
|
||||
}
|
||||
|
||||
TEST(YGNode, baseline_with_context_baseline_fn) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float w, float h, void* ctx) {
|
||||
return w + h + *(float*) ctx;
|
||||
});
|
||||
|
||||
auto ctx = -10.0f;
|
||||
ASSERT_EQ(n.baseline(1.25f, 2.5f, &ctx), -6.25f);
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_after_unset) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 0.0f; });
|
||||
|
||||
n.setBaselineFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasBaselineFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, hasBaselineFunc_after_unset_context) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||
|
||||
n.setMeasureFunc(nullptr);
|
||||
ASSERT_FALSE(n.hasMeasureFunc());
|
||||
}
|
||||
|
||||
TEST(YGNode, switching_baseline_fn_types) {
|
||||
auto n = YGNode{};
|
||||
n.setBaselineFunc([](YGNode*, float, float, void*) { return 0.0f; });
|
||||
n.setBaselineFunc([](YGNode*, float, float) { return 1.0f; });
|
||||
ASSERT_EQ(n.baseline(1, 2, nullptr), 1.0f);
|
||||
}
|
||||
|
||||
void PrintTo(const YGSize& size, std::ostream* os) {
|
||||
*os << "YGSize{" << size.width << ", " << size.height << "}";
|
||||
}
|
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <yoga/Yoga.h>
|
||||
#include <yoga/YGNode.h>
|
||||
|
||||
TEST(YogaTest, cloning_shared_root) {
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
@@ -104,7 +105,7 @@ TEST(YogaTest, cloning_shared_root) {
|
||||
YGConfigFree(config);
|
||||
}
|
||||
|
||||
TEST(YogaTest, mutating_children_of_a_clone_clones) {
|
||||
TEST(YogaTest, mutating_children_of_a_clone_clones_only_after_layout) {
|
||||
const YGConfigRef config = YGConfigNew();
|
||||
|
||||
const YGNodeRef root = YGNodeNewWithConfig(config);
|
||||
@@ -129,7 +130,7 @@ TEST(YogaTest, mutating_children_of_a_clone_clones) {
|
||||
ASSERT_EQ(1, YGNodeGetChildCount(root2));
|
||||
ASSERT_EQ(2, YGNodeGetChildCount(root3));
|
||||
ASSERT_EQ(root3_child1, YGNodeGetChild(root3, 1));
|
||||
ASSERT_NE(YGNodeGetChild(root2, 0), YGNodeGetChild(root3, 0));
|
||||
ASSERT_EQ(YGNodeGetChild(root2, 0), YGNodeGetChild(root3, 0));
|
||||
|
||||
const YGNodeRef root4 = YGNodeClone(root3);
|
||||
ASSERT_EQ(root3_child1, YGNodeGetChild(root4, 1));
|
||||
@@ -137,7 +138,12 @@ TEST(YogaTest, mutating_children_of_a_clone_clones) {
|
||||
YGNodeRemoveChild(root4, root3_child1);
|
||||
ASSERT_EQ(2, YGNodeGetChildCount(root3));
|
||||
ASSERT_EQ(1, YGNodeGetChildCount(root4));
|
||||
ASSERT_EQ(YGNodeGetChild(root3, 0), YGNodeGetChild(root4, 0));
|
||||
|
||||
YGNodeCalculateLayout(root4, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
ASSERT_NE(YGNodeGetChild(root3, 0), YGNodeGetChild(root4, 0));
|
||||
YGNodeCalculateLayout(root3, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
ASSERT_NE(YGNodeGetChild(root2, 0), YGNodeGetChild(root3, 0));
|
||||
|
||||
YGNodeFreeRecursive(root4);
|
||||
YGNodeFreeRecursive(root3);
|
||||
@@ -245,3 +251,34 @@ TEST(YogaTest, cloning_and_freeing) {
|
||||
|
||||
ASSERT_EQ(initialInstanceCount, YGNodeGetInstanceCount());
|
||||
}
|
||||
|
||||
TEST(YogaTest, mixed_shared_and_owned_children) {
|
||||
// Don't try this at home!
|
||||
|
||||
YGNodeRef root0 = YGNodeNew();
|
||||
YGNodeRef root1 = YGNodeNew();
|
||||
|
||||
YGNodeRef root0_child0 = YGNodeNew();
|
||||
YGNodeRef root0_child0_0 = YGNodeNew();
|
||||
YGNodeInsertChild(root0, root0_child0, 0);
|
||||
YGNodeInsertChild(root0_child0, root0_child0_0, 0);
|
||||
|
||||
YGNodeRef root1_child0 = YGNodeNew();
|
||||
YGNodeRef root1_child2 = YGNodeNew();
|
||||
YGNodeInsertChild(root1, root1_child0, 0);
|
||||
YGNodeInsertChild(root1, root1_child2, 1);
|
||||
|
||||
auto children = root1->getChildren();
|
||||
children.insert(children.begin() + 1, root0_child0);
|
||||
root1->setChildren(children);
|
||||
auto secondChild = YGNodeGetChild(root1, 1);
|
||||
ASSERT_EQ(secondChild, YGNodeGetChild(root0, 0));
|
||||
ASSERT_EQ(YGNodeGetChild(secondChild, 0), YGNodeGetChild(root0_child0, 0));
|
||||
|
||||
YGNodeCalculateLayout(root1, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||
secondChild = YGNodeGetChild(root1, 1);
|
||||
ASSERT_NE(secondChild, YGNodeGetChild(root0, 0));
|
||||
ASSERT_EQ(YGNodeGetOwner(secondChild), root1);
|
||||
ASSERT_NE(YGNodeGetChild(secondChild, 0), YGNodeGetChild(root0_child0, 0));
|
||||
ASSERT_EQ(YGNodeGetOwner(YGNodeGetChild(secondChild, 0)), secondChild);
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ dependencies {
|
||||
### Javascript
|
||||
|
||||
The JavaScript bindings for Yoga can be used from node.js and within the browser.
|
||||
When using Yoga from node.js the native library is used, in browesers a pure JS
|
||||
When using Yoga from node.js the native library is used, in browsers a pure JS
|
||||
version is used (cross-compiled using [emscripten](http://kripken.github.io/emscripten-site/)).
|
||||
|
||||
```
|
||||
|
@@ -32,6 +32,6 @@
|
||||
"develop": "gatsby develop"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "1.13.7"
|
||||
"prettier": "1.16.4"
|
||||
}
|
||||
}
|
||||
|
@@ -6978,9 +6978,10 @@ preserve@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
||||
|
||||
prettier@1.13.7:
|
||||
version "1.13.7"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.13.7.tgz#850f3b8af784a49a6ea2d2eaa7ed1428a34b7281"
|
||||
prettier@1.16.4:
|
||||
version "1.16.4"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717"
|
||||
integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==
|
||||
|
||||
pretty-bytes@^4.0.2:
|
||||
version "4.0.2"
|
||||
|
@@ -6,4 +6,38 @@
|
||||
*/
|
||||
#include "YGConfig.h"
|
||||
|
||||
YGConfig::YGConfig(YGLogger logger) : logger(logger) {}
|
||||
YGConfig::YGConfig(YGLogger logger) : cloneNodeCallback_{nullptr} {
|
||||
logger_.noContext = logger;
|
||||
loggerUsesContext_ = false;
|
||||
}
|
||||
|
||||
void YGConfig::log(
|
||||
YGConfig* config,
|
||||
YGNode* node,
|
||||
YGLogLevel logLevel,
|
||||
void* logContext,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
if (loggerUsesContext_) {
|
||||
logger_.withContext(config, node, logLevel, logContext, format, args);
|
||||
} else {
|
||||
logger_.noContext(config, node, logLevel, format, args);
|
||||
}
|
||||
}
|
||||
|
||||
YGNodeRef YGConfig::cloneNode(
|
||||
YGNodeRef node,
|
||||
YGNodeRef owner,
|
||||
int childIndex,
|
||||
void* cloneContext) {
|
||||
YGNodeRef clone = nullptr;
|
||||
if (cloneNodeCallback_.noContext != nullptr) {
|
||||
clone = cloneNodeUsesContext_
|
||||
? cloneNodeCallback_.withContext(node, owner, childIndex, cloneContext)
|
||||
: cloneNodeCallback_.noContext(node, owner, childIndex);
|
||||
}
|
||||
if (clone == nullptr) {
|
||||
clone = YGNodeClone(node);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
@@ -10,17 +10,70 @@
|
||||
#include "Yoga.h"
|
||||
|
||||
struct YGConfig {
|
||||
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
|
||||
experimentalFeatures = {};
|
||||
using LogWithContextFn = int (*)(
|
||||
YGConfigRef config,
|
||||
YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
const char* format,
|
||||
va_list args);
|
||||
using CloneWithContextFn = YGNodeRef (*)(
|
||||
YGNodeRef node,
|
||||
YGNodeRef owner,
|
||||
int childIndex,
|
||||
void* cloneContext);
|
||||
|
||||
private:
|
||||
union {
|
||||
CloneWithContextFn withContext;
|
||||
YGCloneNodeFunc noContext;
|
||||
} cloneNodeCallback_;
|
||||
union {
|
||||
LogWithContextFn withContext;
|
||||
YGLogger noContext;
|
||||
} logger_;
|
||||
bool cloneNodeUsesContext_;
|
||||
bool loggerUsesContext_;
|
||||
|
||||
public:
|
||||
bool useWebDefaults = false;
|
||||
bool useLegacyStretchBehaviour = false;
|
||||
bool shouldDiffLayoutWithoutLegacyStretchBehaviour = false;
|
||||
bool printTree = false;
|
||||
float pointScaleFactor = 1.0f;
|
||||
YGLogger logger;
|
||||
YGCloneNodeFunc cloneNodeCallback = nullptr;
|
||||
std::array<bool, facebook::yoga::enums::count<YGExperimentalFeature>()>
|
||||
experimentalFeatures = {};
|
||||
void* context = nullptr;
|
||||
YGMarkerCallbacks markerCallbacks = {nullptr, nullptr};
|
||||
|
||||
YGConfig(YGLogger logger);
|
||||
void log(YGConfig*, YGNode*, YGLogLevel, void*, const char*, va_list);
|
||||
void setLogger(YGLogger logger) {
|
||||
logger_.noContext = logger;
|
||||
loggerUsesContext_ = false;
|
||||
}
|
||||
void setLogger(LogWithContextFn logger) {
|
||||
logger_.withContext = logger;
|
||||
loggerUsesContext_ = true;
|
||||
}
|
||||
void setLogger(std::nullptr_t) {
|
||||
setLogger(YGLogger{nullptr});
|
||||
}
|
||||
|
||||
YGNodeRef cloneNode(
|
||||
YGNodeRef node,
|
||||
YGNodeRef owner,
|
||||
int childIndex,
|
||||
void* cloneContext);
|
||||
void setCloneNodeCallback(YGCloneNodeFunc cloneNode) {
|
||||
cloneNodeCallback_.noContext = cloneNode;
|
||||
cloneNodeUsesContext_ = false;
|
||||
}
|
||||
void setCloneNodeCallback(CloneWithContextFn cloneNode) {
|
||||
cloneNodeCallback_.withContext = cloneNode;
|
||||
cloneNodeUsesContext_ = true;
|
||||
}
|
||||
void setCloneNodeCallback(std::nullptr_t) {
|
||||
setCloneNodeCallback(YGCloneNodeFunc{nullptr});
|
||||
}
|
||||
};
|
||||
|
156
yoga/YGNode.cpp
156
yoga/YGNode.cpp
@@ -5,6 +5,7 @@
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include "YGNode.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "CompactValue.h"
|
||||
#include "Utils.h"
|
||||
@@ -12,6 +13,41 @@
|
||||
using namespace facebook;
|
||||
using facebook::yoga::detail::CompactValue;
|
||||
|
||||
YGNode::YGNode(YGNode&& node) {
|
||||
context_ = node.context_;
|
||||
hasNewLayout_ = node.hasNewLayout_;
|
||||
isReferenceBaseline_ = node.isReferenceBaseline_;
|
||||
isDirty_ = node.isDirty_;
|
||||
nodeType_ = node.nodeType_;
|
||||
measureUsesContext_ = node.measureUsesContext_;
|
||||
baselineUsesContext_ = node.baselineUsesContext_;
|
||||
printUsesContext_ = node.printUsesContext_;
|
||||
measure_ = node.measure_;
|
||||
baseline_ = node.baseline_;
|
||||
print_ = node.print_;
|
||||
dirtied_ = node.dirtied_;
|
||||
style_ = node.style_;
|
||||
layout_ = node.layout_;
|
||||
lineIndex_ = node.lineIndex_;
|
||||
owner_ = node.owner_;
|
||||
children_ = std::move(node.children_);
|
||||
config_ = node.config_;
|
||||
resolvedDimensions_ = node.resolvedDimensions_;
|
||||
for (auto c : children_) {
|
||||
c->setOwner(c);
|
||||
}
|
||||
}
|
||||
|
||||
void YGNode::print(void* printContext) {
|
||||
if (print_.noContext != nullptr) {
|
||||
if (printUsesContext_) {
|
||||
print_.withContext(this, printContext);
|
||||
} else {
|
||||
print_.noContext(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
YGFloatOptional YGNode::getLeadingPosition(
|
||||
const YGFlexDirection axis,
|
||||
const float axisSize) const {
|
||||
@@ -101,11 +137,29 @@ YGFloatOptional YGNode::getMarginForAxis(
|
||||
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
|
||||
}
|
||||
|
||||
YGSize YGNode::measure(
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode,
|
||||
void* layoutContext) {
|
||||
|
||||
return measureUsesContext_
|
||||
? measure_.withContext(
|
||||
this, width, widthMode, height, heightMode, layoutContext)
|
||||
: measure_.noContext(this, width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
float YGNode::baseline(float width, float height, void* layoutContext) {
|
||||
return baselineUsesContext_
|
||||
? baseline_.withContext(this, width, height, layoutContext)
|
||||
: baseline_.noContext(this, width, height);
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||
if (measureFunc == nullptr) {
|
||||
measure_ = nullptr;
|
||||
void YGNode::setMeasureFunc(decltype(YGNode::measure_) measureFunc) {
|
||||
if (measureFunc.noContext == nullptr) {
|
||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
||||
// places in Litho
|
||||
nodeType_ = YGNodeTypeDefault;
|
||||
@@ -115,7 +169,6 @@ void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||
children_.size() == 0,
|
||||
"Cannot set measure function: Nodes with measure functions cannot have "
|
||||
"children.");
|
||||
measure_ = measureFunc;
|
||||
// TODO: t18095186 Move nodeType to opt-in function and mark appropriate
|
||||
// places in Litho
|
||||
setNodeType(YGNodeTypeText);
|
||||
@@ -124,6 +177,20 @@ void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||
measure_ = measureFunc;
|
||||
}
|
||||
|
||||
void YGNode::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||
measureUsesContext_ = false;
|
||||
decltype(YGNode::measure_) m;
|
||||
m.noContext = measureFunc;
|
||||
setMeasureFunc(m);
|
||||
}
|
||||
|
||||
void YGNode::setMeasureFunc(MeasureWithContextFn measureFunc) {
|
||||
measureUsesContext_ = true;
|
||||
decltype(YGNode::measure_) m;
|
||||
m.withContext = measureFunc;
|
||||
setMeasureFunc(m);
|
||||
}
|
||||
|
||||
void YGNode::replaceChild(YGNodeRef child, uint32_t index) {
|
||||
children_[index] = child;
|
||||
}
|
||||
@@ -257,34 +324,6 @@ void YGNode::setPosition(
|
||||
trailing[crossAxis]);
|
||||
}
|
||||
|
||||
YGNode& YGNode::operator=(const YGNode& node) {
|
||||
if (&node == this) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
for (auto child : children_) {
|
||||
delete child;
|
||||
}
|
||||
|
||||
context_ = node.getContext();
|
||||
print_ = node.getPrintFunc();
|
||||
hasNewLayout_ = node.getHasNewLayout();
|
||||
nodeType_ = node.getNodeType();
|
||||
measure_ = node.getMeasure();
|
||||
baseline_ = node.getBaseline();
|
||||
dirtied_ = node.getDirtied();
|
||||
style_ = node.style_;
|
||||
layout_ = node.layout_;
|
||||
lineIndex_ = node.getLineIndex();
|
||||
owner_ = node.getOwner();
|
||||
children_ = node.getChildren();
|
||||
config_ = node.getConfig();
|
||||
isDirty_ = node.isDirty();
|
||||
resolvedDimensions_ = node.getResolvedDimensions();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
YGValue YGNode::marginLeadingValue(const YGFlexDirection axis) const {
|
||||
if (YGFlexDirectionIsRow(axis) && !style_.margin[YGEdgeStart].isUndefined()) {
|
||||
return style_.margin[YGEdgeStart];
|
||||
@@ -341,38 +380,8 @@ void YGNode::clearChildren() {
|
||||
|
||||
// Other Methods
|
||||
|
||||
void YGNode::cloneChildrenIfNeeded() {
|
||||
// YGNodeRemoveChild in yoga.cpp has a forked variant of this algorithm
|
||||
// optimized for deletions.
|
||||
|
||||
const uint32_t childCount = static_cast<uint32_t>(children_.size());
|
||||
if (childCount == 0) {
|
||||
// This is an empty set. Nothing to clone.
|
||||
return;
|
||||
}
|
||||
|
||||
const YGNodeRef firstChild = children_.front();
|
||||
if (firstChild->getOwner() == this) {
|
||||
// If the first child has this node as its owner, we assume that it is
|
||||
// already unique. We can do this because if we have it has a child, that
|
||||
// means that its owner was at some point cloned which made that subtree
|
||||
// immutable. We also assume that all its sibling are cloned as well.
|
||||
return;
|
||||
}
|
||||
|
||||
const YGCloneNodeFunc cloneNodeCallback = config_->cloneNodeCallback;
|
||||
for (uint32_t i = 0; i < childCount; ++i) {
|
||||
const YGNodeRef oldChild = children_[i];
|
||||
YGNodeRef newChild = nullptr;
|
||||
if (cloneNodeCallback) {
|
||||
newChild = cloneNodeCallback(oldChild, this, i);
|
||||
}
|
||||
if (newChild == nullptr) {
|
||||
newChild = YGNodeClone(oldChild);
|
||||
}
|
||||
replaceChild(newChild, i);
|
||||
newChild->setOwner(this);
|
||||
}
|
||||
void YGNode::cloneChildrenIfNeeded(void* cloneContext) {
|
||||
iterChildrenAfterCloningIfNeeded([](YGNodeRef, void*) {}, cloneContext);
|
||||
}
|
||||
|
||||
void YGNode::markDirtyAndPropogate() {
|
||||
@@ -557,3 +566,22 @@ bool YGNode::isLayoutTreeEqualToNode(const YGNode& node) const {
|
||||
}
|
||||
return isLayoutTreeEqual;
|
||||
}
|
||||
|
||||
void YGNode::reset() {
|
||||
YGAssertWithNode(
|
||||
this,
|
||||
children_.size() == 0,
|
||||
"Cannot reset a node which still has children attached");
|
||||
YGAssertWithNode(
|
||||
this, owner_ == nullptr, "Cannot reset a node still attached to a owner");
|
||||
|
||||
clearChildren();
|
||||
|
||||
auto config = getConfig();
|
||||
*this = YGNode{};
|
||||
if (config->useWebDefaults) {
|
||||
setStyleFlexDirection(YGFlexDirectionRow);
|
||||
setStyleAlignContent(YGAlignStretch);
|
||||
}
|
||||
setConfig(config);
|
||||
}
|
||||
|
115
yoga/YGNode.h
115
yoga/YGNode.h
@@ -12,15 +12,32 @@
|
||||
#include "Yoga-internal.h"
|
||||
|
||||
struct YGNode {
|
||||
using MeasureWithContextFn =
|
||||
YGSize (*)(YGNode*, float, YGMeasureMode, float, YGMeasureMode, void*);
|
||||
using BaselineWithContextFn = float (*)(YGNode*, float, float, void*);
|
||||
using PrintWithContextFn = void (*)(YGNode*, void*);
|
||||
|
||||
private:
|
||||
void* context_ = nullptr;
|
||||
YGPrintFunc print_ = nullptr;
|
||||
bool hasNewLayout_ : 1;
|
||||
bool isReferenceBaseline_ : 1;
|
||||
bool isDirty_ : 1;
|
||||
YGNodeType nodeType_ : 1;
|
||||
YGMeasureFunc measure_ = nullptr;
|
||||
YGBaselineFunc baseline_ = nullptr;
|
||||
bool measureUsesContext_ : 1;
|
||||
bool baselineUsesContext_ : 1;
|
||||
bool printUsesContext_ : 1;
|
||||
union {
|
||||
YGMeasureFunc noContext;
|
||||
MeasureWithContextFn withContext;
|
||||
} measure_ = {nullptr};
|
||||
union {
|
||||
YGBaselineFunc noContext;
|
||||
BaselineWithContextFn withContext;
|
||||
} baseline_ = {nullptr};
|
||||
union {
|
||||
YGPrintFunc noContext;
|
||||
PrintWithContextFn withContext;
|
||||
} print_ = {nullptr};
|
||||
YGDirtiedFunc dirtied_ = nullptr;
|
||||
YGStyle style_ = {};
|
||||
YGLayout layout_ = {};
|
||||
@@ -35,25 +52,44 @@ private:
|
||||
const YGFlexDirection axis,
|
||||
const float axisSize) const;
|
||||
|
||||
void setMeasureFunc(decltype(measure_));
|
||||
void setBaselineFunc(decltype(baseline_));
|
||||
|
||||
// DANGER DANGER DANGER!
|
||||
// If the the node assigned to has children, we'd either have to deallocate
|
||||
// them (potentially incorrect) or ignore them (danger of leaks). Only ever
|
||||
// use this after checking that there are no children.
|
||||
// DO NOT CHANGE THE VISIBILITY OF THIS METHOD!
|
||||
YGNode& operator=(YGNode&&) = default;
|
||||
|
||||
public:
|
||||
YGNode()
|
||||
: hasNewLayout_(true),
|
||||
isReferenceBaseline_(false),
|
||||
isDirty_(false),
|
||||
nodeType_(YGNodeTypeDefault) {}
|
||||
: hasNewLayout_{true},
|
||||
isReferenceBaseline_{false},
|
||||
isDirty_{false},
|
||||
nodeType_{YGNodeTypeDefault},
|
||||
measureUsesContext_{false},
|
||||
baselineUsesContext_{false},
|
||||
printUsesContext_{false} {}
|
||||
~YGNode() = default; // cleanup of owner/children relationships in YGNodeFree
|
||||
explicit YGNode(const YGConfigRef newConfig) : config_(newConfig){};
|
||||
|
||||
YGNode(YGNode&&);
|
||||
|
||||
// Does not expose true value semantics, as children are not cloned eagerly.
|
||||
// Should we remove this?
|
||||
YGNode(const YGNode& node) = default;
|
||||
YGNode& operator=(const YGNode& node);
|
||||
|
||||
// assignment means potential leaks of existing children, or alternatively
|
||||
// freeing unowned memory, double free, or freeing stack memory.
|
||||
YGNode& operator=(const YGNode&) = delete;
|
||||
|
||||
// Getters
|
||||
void* getContext() const {
|
||||
return context_;
|
||||
}
|
||||
|
||||
YGPrintFunc getPrintFunc() const {
|
||||
return print_;
|
||||
}
|
||||
void print(void*);
|
||||
|
||||
bool getHasNewLayout() const {
|
||||
return hasNewLayout_;
|
||||
@@ -63,14 +99,18 @@ public:
|
||||
return nodeType_;
|
||||
}
|
||||
|
||||
YGMeasureFunc getMeasure() const {
|
||||
return measure_;
|
||||
bool hasMeasureFunc() const noexcept {
|
||||
return measure_.noContext != nullptr;
|
||||
}
|
||||
|
||||
YGBaselineFunc getBaseline() const {
|
||||
return baseline_;
|
||||
YGSize measure(float, YGMeasureMode, float, YGMeasureMode, void*);
|
||||
|
||||
bool hasBaselineFunc() const noexcept {
|
||||
return baseline_.noContext != nullptr;
|
||||
}
|
||||
|
||||
float baseline(float width, float height, void* layoutContext);
|
||||
|
||||
YGDirtiedFunc getDirtied() const {
|
||||
return dirtied_;
|
||||
}
|
||||
@@ -118,6 +158,22 @@ public:
|
||||
return children_;
|
||||
}
|
||||
|
||||
// Applies a callback to all children, after cloning them if they are not
|
||||
// owned.
|
||||
template <typename T>
|
||||
void iterChildrenAfterCloningIfNeeded(T callback, void* cloneContext) {
|
||||
int i = 0;
|
||||
for (YGNodeRef& child : children_) {
|
||||
if (child->getOwner() != this) {
|
||||
child = config_->cloneNode(child, this, i, cloneContext);
|
||||
child->setOwner(this);
|
||||
}
|
||||
i += 1;
|
||||
|
||||
callback(child, cloneContext);
|
||||
}
|
||||
}
|
||||
|
||||
YGNodeRef getChild(uint32_t index) const {
|
||||
return children_.at(index);
|
||||
}
|
||||
@@ -177,7 +233,15 @@ public:
|
||||
}
|
||||
|
||||
void setPrintFunc(YGPrintFunc printFunc) {
|
||||
print_ = printFunc;
|
||||
print_.noContext = printFunc;
|
||||
printUsesContext_ = false;
|
||||
}
|
||||
void setPrintFunc(PrintWithContextFn printFunc) {
|
||||
print_.withContext = printFunc;
|
||||
printUsesContext_ = true;
|
||||
}
|
||||
void setPrintFunc(std::nullptr_t) {
|
||||
setPrintFunc(YGPrintFunc{nullptr});
|
||||
}
|
||||
|
||||
void setHasNewLayout(bool hasNewLayout) {
|
||||
@@ -197,9 +261,21 @@ public:
|
||||
}
|
||||
|
||||
void setMeasureFunc(YGMeasureFunc measureFunc);
|
||||
void setMeasureFunc(MeasureWithContextFn);
|
||||
void setMeasureFunc(std::nullptr_t) {
|
||||
return setMeasureFunc(YGMeasureFunc{nullptr});
|
||||
}
|
||||
|
||||
void setBaseLineFunc(YGBaselineFunc baseLineFunc) {
|
||||
baseline_ = baseLineFunc;
|
||||
void setBaselineFunc(YGBaselineFunc baseLineFunc) {
|
||||
baselineUsesContext_ = false;
|
||||
baseline_.noContext = baseLineFunc;
|
||||
}
|
||||
void setBaselineFunc(BaselineWithContextFn baseLineFunc) {
|
||||
baselineUsesContext_ = true;
|
||||
baseline_.withContext = baseLineFunc;
|
||||
}
|
||||
void setBaselineFunc(std::nullptr_t) {
|
||||
return setBaselineFunc(YGBaselineFunc{nullptr});
|
||||
}
|
||||
|
||||
void setDirtiedFunc(YGDirtiedFunc dirtiedFunc) {
|
||||
@@ -274,11 +350,12 @@ public:
|
||||
bool removeChild(YGNodeRef child);
|
||||
void removeChild(uint32_t index);
|
||||
|
||||
void cloneChildrenIfNeeded();
|
||||
void cloneChildrenIfNeeded(void*);
|
||||
void markDirtyAndPropogate();
|
||||
float resolveFlexGrow();
|
||||
float resolveFlexShrink();
|
||||
bool isNodeFlexible();
|
||||
bool didUseLegacyFlag();
|
||||
bool isLayoutTreeEqualToNode(const YGNode& node) const;
|
||||
void reset();
|
||||
};
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#include "YGNodePrint.h"
|
||||
#include <stdarg.h>
|
||||
#include "YGEnums.h"
|
||||
@@ -114,9 +115,6 @@ void YGNodeToString(
|
||||
uint32_t level) {
|
||||
indent(str, level);
|
||||
appendFormatedString(str, "<div ");
|
||||
if (node->getPrintFunc() != nullptr) {
|
||||
node->getPrintFunc()(node);
|
||||
}
|
||||
|
||||
if (options & YGPrintOptionsLayout) {
|
||||
appendFormatedString(str, "layout=\"");
|
||||
@@ -169,7 +167,7 @@ void YGNodeToString(
|
||||
|
||||
if (node->getStyle().flexWrap != YGNode().getStyle().flexWrap) {
|
||||
appendFormatedString(
|
||||
str, "flexWrap: %s; ", YGWrapToString(node->getStyle().flexWrap));
|
||||
str, "flex-wrap: %s; ", YGWrapToString(node->getStyle().flexWrap));
|
||||
}
|
||||
|
||||
if (node->getStyle().overflow != YGNode().getStyle().overflow) {
|
||||
@@ -214,7 +212,7 @@ void YGNodeToString(
|
||||
str, "bottom", node->getStyle().position, YGEdgeBottom);
|
||||
appendFormatedString(str, "\" ");
|
||||
|
||||
if (node->getMeasure() != nullptr) {
|
||||
if (node->hasMeasureFunc()) {
|
||||
appendFormatedString(str, "has-custom-measure=\"true\"");
|
||||
}
|
||||
}
|
||||
@@ -233,3 +231,4 @@ void YGNodeToString(
|
||||
}
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
#endif
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
@@ -20,3 +21,4 @@ void YGNodeToString(
|
||||
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
||||
#endif
|
||||
|
@@ -22,6 +22,13 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||
const bool forceCeil,
|
||||
const bool forceFloor);
|
||||
|
||||
void YGNodeCalculateLayoutWithContext(
|
||||
YGNodeRef node,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
YGDirection ownerDirection,
|
||||
void* layoutContext);
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
namespace facebook {
|
||||
|
361
yoga/Yoga.cpp
361
yoga/Yoga.cpp
@@ -5,6 +5,7 @@
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
#include "Yoga.h"
|
||||
#include "log.h"
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
@@ -25,6 +26,16 @@ __forceinline const float fmaxf(const float a, const float b) {
|
||||
#endif
|
||||
|
||||
using namespace facebook::yoga;
|
||||
using detail::Log;
|
||||
|
||||
namespace {
|
||||
size_t usedMeasureCacheEntries = YG_MAX_CACHED_RESULT_COUNT;
|
||||
}
|
||||
|
||||
void YGSetUsedCachedEntries(size_t n) {
|
||||
usedMeasureCacheEntries =
|
||||
n == 0 || n > YG_MAX_CACHED_RESULT_COUNT ? YG_MAX_CACHED_RESULT_COUNT : n;
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
static int YGAndroidLog(
|
||||
@@ -143,20 +154,20 @@ void YGNodeSetContext(YGNodeRef node, void* context) {
|
||||
return node->setContext(context);
|
||||
}
|
||||
|
||||
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node) {
|
||||
return node->getMeasure();
|
||||
bool YGNodeHasMeasureFunc(YGNodeRef node) {
|
||||
return node->hasMeasureFunc();
|
||||
}
|
||||
|
||||
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc) {
|
||||
node->setMeasureFunc(measureFunc);
|
||||
}
|
||||
|
||||
YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node) {
|
||||
return node->getBaseline();
|
||||
bool YGNodeHasBaselineFunc(YGNodeRef node) {
|
||||
return node->hasBaselineFunc();
|
||||
}
|
||||
|
||||
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc) {
|
||||
node->setBaseLineFunc(baselineFunc);
|
||||
node->setBaselineFunc(baselineFunc);
|
||||
}
|
||||
|
||||
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node) {
|
||||
@@ -167,10 +178,6 @@ void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) {
|
||||
node->setDirtiedFunc(dirtiedFunc);
|
||||
}
|
||||
|
||||
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node) {
|
||||
return node->getPrintFunc();
|
||||
}
|
||||
|
||||
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
|
||||
node->setPrintFunc(printFunc);
|
||||
}
|
||||
@@ -304,14 +311,16 @@ static void YGConfigFreeRecursive(const YGNodeRef root) {
|
||||
void YGNodeFreeRecursiveWithCleanupFunc(
|
||||
const YGNodeRef root,
|
||||
YGNodeCleanupFunc cleanup) {
|
||||
while (YGNodeGetChildCount(root) > 0) {
|
||||
const YGNodeRef child = YGNodeGetChild(root, 0);
|
||||
uint32_t skipped = 0;
|
||||
while (YGNodeGetChildCount(root) > skipped) {
|
||||
const YGNodeRef child = YGNodeGetChild(root, skipped);
|
||||
if (child->getOwner() != root) {
|
||||
// Don't free shared nodes that we don't own.
|
||||
break;
|
||||
skipped += 1;
|
||||
} else {
|
||||
YGNodeRemoveChild(root, child);
|
||||
YGNodeFreeRecursive(child);
|
||||
}
|
||||
YGNodeRemoveChild(root, child);
|
||||
YGNodeFreeRecursive(child);
|
||||
}
|
||||
if (cleanup != nullptr) {
|
||||
cleanup(root);
|
||||
@@ -323,25 +332,8 @@ void YGNodeFreeRecursive(const YGNodeRef root) {
|
||||
return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr);
|
||||
}
|
||||
|
||||
void YGNodeReset(const YGNodeRef node) {
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
YGNodeGetChildCount(node) == 0,
|
||||
"Cannot reset a node which still has children attached");
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
node->getOwner() == nullptr,
|
||||
"Cannot reset a node still attached to a owner");
|
||||
|
||||
node->clearChildren();
|
||||
|
||||
const YGConfigRef config = node->getConfig();
|
||||
*node = YGNode();
|
||||
if (config->useWebDefaults) {
|
||||
node->setStyleFlexDirection(YGFlexDirectionRow);
|
||||
node->setStyleAlignContent(YGAlignStretch);
|
||||
}
|
||||
node->setConfig(config);
|
||||
void YGNodeReset(YGNodeRef node) {
|
||||
node->reset();
|
||||
}
|
||||
|
||||
int32_t YGNodeGetInstanceCount(void) {
|
||||
@@ -383,77 +375,40 @@ bool YGNodeIsReferenceBaseline(YGNodeRef node) {
|
||||
}
|
||||
|
||||
void YGNodeInsertChild(
|
||||
const YGNodeRef node,
|
||||
const YGNodeRef owner,
|
||||
const YGNodeRef child,
|
||||
const uint32_t index) {
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
owner,
|
||||
child->getOwner() == nullptr,
|
||||
"Child already has a owner, it must be removed first.");
|
||||
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
node->getMeasure() == nullptr,
|
||||
owner,
|
||||
!owner->hasMeasureFunc(),
|
||||
"Cannot add child: Nodes with measure functions cannot have children.");
|
||||
|
||||
node->cloneChildrenIfNeeded();
|
||||
node->insertChild(child, index);
|
||||
YGNodeRef owner = child->getOwner() ? nullptr : node;
|
||||
owner->insertChild(child, index);
|
||||
child->setOwner(owner);
|
||||
node->markDirtyAndPropogate();
|
||||
owner->markDirtyAndPropogate();
|
||||
}
|
||||
|
||||
void YGNodeRemoveChild(const YGNodeRef owner, const YGNodeRef excludedChild) {
|
||||
// This algorithm is a forked variant from cloneChildrenIfNeeded in YGNode
|
||||
// that excludes a child.
|
||||
const uint32_t childCount = YGNodeGetChildCount(owner);
|
||||
|
||||
if (childCount == 0) {
|
||||
if (YGNodeGetChildCount(owner) == 0) {
|
||||
// This is an empty set. Nothing to remove.
|
||||
return;
|
||||
}
|
||||
const YGNodeRef firstChild = YGNodeGetChild(owner, 0);
|
||||
if (firstChild->getOwner() == owner) {
|
||||
// If the first child has this node as its owner, we assume that it is
|
||||
// already unique. We can now try to delete a child in this list.
|
||||
if (owner->removeChild(excludedChild)) {
|
||||
excludedChild->setLayout(
|
||||
YGNode().getLayout()); // layout is no longer valid
|
||||
excludedChild->setOwner(nullptr);
|
||||
owner->markDirtyAndPropogate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Otherwise we have to clone the node list except for the child we're trying
|
||||
// to delete. We don't want to simply clone all children, because then the
|
||||
// host will need to free the clone of the child that was just deleted.
|
||||
const YGCloneNodeFunc cloneNodeCallback =
|
||||
owner->getConfig()->cloneNodeCallback;
|
||||
uint32_t nextInsertIndex = 0;
|
||||
for (uint32_t i = 0; i < childCount; i++) {
|
||||
const YGNodeRef oldChild = owner->getChild(i);
|
||||
if (excludedChild == oldChild) {
|
||||
// Ignore the deleted child. Don't reset its layout or owner since it is
|
||||
// still valid in the other owner. However, since this owner has now
|
||||
// changed, we need to mark it as dirty.
|
||||
owner->markDirtyAndPropogate();
|
||||
continue;
|
||||
}
|
||||
YGNodeRef newChild = nullptr;
|
||||
if (cloneNodeCallback) {
|
||||
newChild = cloneNodeCallback(oldChild, owner, nextInsertIndex);
|
||||
}
|
||||
if (newChild == nullptr) {
|
||||
newChild = YGNodeClone(oldChild);
|
||||
}
|
||||
owner->replaceChild(newChild, nextInsertIndex);
|
||||
newChild->setOwner(owner);
|
||||
|
||||
nextInsertIndex++;
|
||||
}
|
||||
while (nextInsertIndex < childCount) {
|
||||
owner->removeChild(nextInsertIndex);
|
||||
nextInsertIndex++;
|
||||
// Children may be shared between parents, which is indicated by not having an
|
||||
// owner. We only want to reset the child completely if it is owned
|
||||
// exclusively by one node.
|
||||
auto childOwner = excludedChild->getOwner();
|
||||
if (owner->removeChild(excludedChild)) {
|
||||
if (owner == childOwner) {
|
||||
excludedChild->setLayout({}); // layout is no longer valid
|
||||
excludedChild->setOwner(nullptr);
|
||||
}
|
||||
owner->markDirtyAndPropogate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,7 +508,7 @@ YGNodeRef YGNodeGetParent(const YGNodeRef node) {
|
||||
void YGNodeMarkDirty(const YGNodeRef node) {
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
node->getMeasure() != nullptr,
|
||||
node->hasMeasureFunc(),
|
||||
"Only leaf nodes with custom measure functions"
|
||||
"should manually mark themselves as dirty");
|
||||
|
||||
@@ -1021,19 +976,22 @@ bool YGLayoutNodeInternal(
|
||||
const bool performLayout,
|
||||
const char* reason,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData);
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext);
|
||||
|
||||
#ifdef DEBUG
|
||||
static void YGNodePrintInternal(
|
||||
const YGNodeRef node,
|
||||
const YGPrintOptions options) {
|
||||
std::string str;
|
||||
facebook::yoga::YGNodeToString(str, node, options, 0);
|
||||
YGLog(node, YGLogLevelDebug, str.c_str());
|
||||
Log::log(node, YGLogLevelDebug, nullptr, str.c_str());
|
||||
}
|
||||
|
||||
void YGNodePrint(const YGNodeRef node, const YGPrintOptions options) {
|
||||
YGNodePrintInternal(node, options);
|
||||
}
|
||||
#endif
|
||||
|
||||
const std::array<YGEdge, 4> leading = {
|
||||
{YGEdgeTop, YGEdgeBottom, YGEdgeLeft, YGEdgeRight}};
|
||||
@@ -1072,14 +1030,14 @@ static inline YGAlign YGNodeAlignItem(
|
||||
return align;
|
||||
}
|
||||
|
||||
static float YGBaseline(const YGNodeRef node) {
|
||||
if (node->getBaseline() != nullptr) {
|
||||
static float YGBaseline(const YGNodeRef node, void* layoutContext) {
|
||||
if (node->hasBaselineFunc()) {
|
||||
const float baseline = marker::MarkerSection<YGMarkerBaselineFn>::wrap(
|
||||
node,
|
||||
node->getBaseline(),
|
||||
node,
|
||||
&YGNode::baseline,
|
||||
node->getLayout().measuredDimensions[YGDimensionWidth],
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight]);
|
||||
node->getLayout().measuredDimensions[YGDimensionHeight],
|
||||
layoutContext);
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
!YGFloatIsUndefined(baseline),
|
||||
@@ -1112,7 +1070,7 @@ static float YGBaseline(const YGNodeRef node) {
|
||||
return node->getLayout().measuredDimensions[YGDimensionHeight];
|
||||
}
|
||||
|
||||
const float baseline = YGBaseline(baselineChild);
|
||||
const float baseline = YGBaseline(baselineChild, layoutContext);
|
||||
return baseline + baselineChild->getLayout().position[YGEdgeTop];
|
||||
}
|
||||
|
||||
@@ -1263,7 +1221,8 @@ static void YGNodeComputeFlexBasisForChild(
|
||||
const YGMeasureMode heightMode,
|
||||
const YGDirection direction,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
const YGFlexDirection mainAxis =
|
||||
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
|
||||
const bool isMainAxisRow = YGFlexDirectionIsRow(mainAxis);
|
||||
@@ -1437,7 +1396,8 @@ static void YGNodeComputeFlexBasisForChild(
|
||||
false,
|
||||
"measure",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
|
||||
child->setLayoutComputedFlexBasis(YGFloatOptional(YGFloatMax(
|
||||
child->getLayout().measuredDimensions[dim[mainAxis]],
|
||||
@@ -1454,7 +1414,8 @@ static void YGNodeAbsoluteLayoutChild(
|
||||
const float height,
|
||||
const YGDirection direction,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
const YGFlexDirection mainAxis =
|
||||
YGResolveFlexDirection(node->getStyle().flexDirection, direction);
|
||||
const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, direction);
|
||||
@@ -1559,7 +1520,8 @@ static void YGNodeAbsoluteLayoutChild(
|
||||
false,
|
||||
"abs-measure",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
childWidth = child->getLayout().measuredDimensions[YGDimensionWidth] +
|
||||
child->getMarginForAxis(YGFlexDirectionRow, width).unwrap();
|
||||
childHeight = child->getLayout().measuredDimensions[YGDimensionHeight] +
|
||||
@@ -1578,7 +1540,8 @@ static void YGNodeAbsoluteLayoutChild(
|
||||
true,
|
||||
"abs-layout",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
|
||||
if (child->isTrailingPosDefined(mainAxis) &&
|
||||
!child->isLeadingPositionDefined(mainAxis)) {
|
||||
@@ -1645,10 +1608,11 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||
const YGMeasureMode widthMeasureMode,
|
||||
const YGMeasureMode heightMeasureMode,
|
||||
const float ownerWidth,
|
||||
const float ownerHeight) {
|
||||
const float ownerHeight,
|
||||
void* const layoutContext) {
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
node->getMeasure() != nullptr,
|
||||
node->hasMeasureFunc(),
|
||||
"Expected node to have custom measure function");
|
||||
|
||||
const float paddingAndBorderAxisRow =
|
||||
@@ -1692,12 +1656,12 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||
// Measure the text under the current constraints.
|
||||
const YGSize measuredSize = marker::MarkerSection<YGMarkerMeasure>::wrap(
|
||||
node,
|
||||
node->getMeasure(),
|
||||
node,
|
||||
&YGNode::measure,
|
||||
innerWidth,
|
||||
widthMeasureMode,
|
||||
innerHeight,
|
||||
heightMeasureMode);
|
||||
heightMeasureMode,
|
||||
layoutContext);
|
||||
|
||||
node->setLayoutMeasuredDimension(
|
||||
YGNodeBoundAxis(
|
||||
@@ -1819,17 +1783,16 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(
|
||||
return false;
|
||||
}
|
||||
|
||||
static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
|
||||
static void YGZeroOutLayoutRecursivly(
|
||||
const YGNodeRef node,
|
||||
void* layoutContext) {
|
||||
node->getLayout() = {};
|
||||
node->setLayoutDimension(0, 0);
|
||||
node->setLayoutDimension(0, 1);
|
||||
node->setHasNewLayout(true);
|
||||
node->cloneChildrenIfNeeded();
|
||||
const uint32_t childCount = YGNodeGetChildCount(node);
|
||||
for (uint32_t i = 0; i < childCount; i++) {
|
||||
const YGNodeRef child = node->getChild(i);
|
||||
YGZeroOutLayoutRecursivly(child);
|
||||
}
|
||||
|
||||
node->iterChildrenAfterCloningIfNeeded(
|
||||
YGZeroOutLayoutRecursivly, layoutContext);
|
||||
}
|
||||
|
||||
static float YGNodeCalculateAvailableInnerDim(
|
||||
@@ -1881,7 +1844,8 @@ static float YGNodeComputeFlexBasisForChildren(
|
||||
YGFlexDirection mainAxis,
|
||||
const YGConfigRef config,
|
||||
bool performLayout,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
float totalOuterFlexBasis = 0.0f;
|
||||
YGNodeRef singleFlexChild = nullptr;
|
||||
YGVector children = node->getChildren();
|
||||
@@ -1910,7 +1874,7 @@ static float YGNodeComputeFlexBasisForChildren(
|
||||
for (auto child : children) {
|
||||
child->resolveDimension();
|
||||
if (child->getStyle().display == YGDisplayNone) {
|
||||
YGZeroOutLayoutRecursivly(child);
|
||||
YGZeroOutLayoutRecursivly(child, layoutContext);
|
||||
child->setHasNewLayout(true);
|
||||
child->setDirty(false);
|
||||
continue;
|
||||
@@ -1946,7 +1910,8 @@ static float YGNodeComputeFlexBasisForChildren(
|
||||
heightMeasureMode,
|
||||
direction,
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
}
|
||||
|
||||
totalOuterFlexBasis +=
|
||||
@@ -2059,7 +2024,8 @@ static float YGDistributeFreeSpaceSecondPass(
|
||||
const YGMeasureMode measureModeCrossDim,
|
||||
const bool performLayout,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
float childFlexBasis = 0;
|
||||
float flexShrinkScaledFactor = 0;
|
||||
float flexGrowFactor = 0;
|
||||
@@ -2224,7 +2190,8 @@ static float YGDistributeFreeSpaceSecondPass(
|
||||
performLayout && !requiresStretchLayout,
|
||||
"flex",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
node->setLayoutHadOverflow(
|
||||
node->getLayout().hadOverflow |
|
||||
currentRelativeChild->getLayout().hadOverflow);
|
||||
@@ -2354,7 +2321,8 @@ static void YGResolveFlexibleLength(
|
||||
const YGMeasureMode measureModeCrossDim,
|
||||
const bool performLayout,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
const float originalFreeSpace = collectedFlexItemsValues.remainingFreeSpace;
|
||||
// First pass: detect the flex items whose min/max constraints trigger
|
||||
YGDistributeFreeSpaceFirstPass(
|
||||
@@ -2379,7 +2347,8 @@ static void YGResolveFlexibleLength(
|
||||
measureModeCrossDim,
|
||||
performLayout,
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
|
||||
collectedFlexItemsValues.remainingFreeSpace =
|
||||
originalFreeSpace - distributedFreeSpace;
|
||||
@@ -2398,7 +2367,8 @@ static void YGJustifyMainAxis(
|
||||
const float availableInnerMainDim,
|
||||
const float availableInnerCrossDim,
|
||||
const float availableInnerWidth,
|
||||
const bool performLayout) {
|
||||
const bool performLayout,
|
||||
void* const layoutContext) {
|
||||
const YGStyle& style = node->getStyle();
|
||||
const float leadingPaddingAndBorderMain =
|
||||
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap();
|
||||
@@ -2558,7 +2528,7 @@ static void YGJustifyMainAxis(
|
||||
if (isNodeBaselineLayout) {
|
||||
// If the child is baseline aligned then the cross dimension is
|
||||
// calculated by adding maxAscent and maxDescent from the baseline.
|
||||
const float ascent = YGBaseline(child) +
|
||||
const float ascent = YGBaseline(child, layoutContext) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
YGFlexDirectionColumn, availableInnerWidth)
|
||||
@@ -2676,7 +2646,8 @@ static void YGNodelayoutImpl(
|
||||
const float ownerHeight,
|
||||
const bool performLayout,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
YGAssertWithNode(
|
||||
node,
|
||||
YGFloatIsUndefined(availableWidth)
|
||||
@@ -2735,7 +2706,7 @@ static void YGNodelayoutImpl(
|
||||
node->getTrailingPadding(flexColumnDirection, ownerWidth).unwrap(),
|
||||
YGEdgeBottom);
|
||||
|
||||
if (node->getMeasure() != nullptr) {
|
||||
if (node->hasMeasureFunc()) {
|
||||
YGNodeWithMeasureFuncSetMeasuredDimensions(
|
||||
node,
|
||||
availableWidth,
|
||||
@@ -2743,7 +2714,8 @@ static void YGNodelayoutImpl(
|
||||
widthMeasureMode,
|
||||
heightMeasureMode,
|
||||
ownerWidth,
|
||||
ownerHeight);
|
||||
ownerHeight,
|
||||
layoutContext);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2776,7 +2748,7 @@ static void YGNodelayoutImpl(
|
||||
|
||||
// At this point we know we're going to perform work. Ensure that each child
|
||||
// has a mutable copy.
|
||||
node->cloneChildrenIfNeeded();
|
||||
node->cloneChildrenIfNeeded(layoutContext);
|
||||
// Reset layout flags, as they could have changed.
|
||||
node->setLayoutHadOverflow(false);
|
||||
|
||||
@@ -2860,7 +2832,8 @@ static void YGNodelayoutImpl(
|
||||
mainAxis,
|
||||
config,
|
||||
performLayout,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
|
||||
const bool flexBasisOverflows = measureModeMainDim == YGMeasureModeUndefined
|
||||
? false
|
||||
@@ -2967,7 +2940,8 @@ static void YGNodelayoutImpl(
|
||||
measureModeCrossDim,
|
||||
performLayout,
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
}
|
||||
|
||||
node->setLayoutHadOverflow(
|
||||
@@ -2994,7 +2968,8 @@ static void YGNodelayoutImpl(
|
||||
availableInnerMainDim,
|
||||
availableInnerCrossDim,
|
||||
availableInnerWidth,
|
||||
performLayout);
|
||||
performLayout,
|
||||
layoutContext);
|
||||
|
||||
float containerCrossAxis = availableInnerCrossDim;
|
||||
if (measureModeCrossDim == YGMeasureModeUndefined ||
|
||||
@@ -3133,7 +3108,8 @@ static void YGNodelayoutImpl(
|
||||
true,
|
||||
"stretch",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
}
|
||||
} else {
|
||||
const float remainingCrossDim = containerCrossAxis -
|
||||
@@ -3237,7 +3213,7 @@ static void YGNodelayoutImpl(
|
||||
.unwrap());
|
||||
}
|
||||
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
||||
const float ascent = YGBaseline(child) +
|
||||
const float ascent = YGBaseline(child, layoutContext) +
|
||||
child
|
||||
->getLeadingMargin(
|
||||
YGFlexDirectionColumn, availableInnerWidth)
|
||||
@@ -3340,14 +3316,16 @@ static void YGNodelayoutImpl(
|
||||
true,
|
||||
"multiline-stretch",
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case YGAlignBaseline: {
|
||||
child->setLayoutPosition(
|
||||
currentLead + maxAscentForCurrentLine - YGBaseline(child) +
|
||||
currentLead + maxAscentForCurrentLine -
|
||||
YGBaseline(child, layoutContext) +
|
||||
child
|
||||
->getLeadingPosition(
|
||||
YGFlexDirectionColumn, availableInnerCrossDim)
|
||||
@@ -3478,7 +3456,8 @@ static void YGNodelayoutImpl(
|
||||
availableInnerHeight,
|
||||
direction,
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
}
|
||||
|
||||
// STEP 11: SETTING TRAILING POSITIONS FOR CHILDREN
|
||||
@@ -3711,7 +3690,8 @@ bool YGLayoutNodeInternal(
|
||||
const bool performLayout,
|
||||
const char* reason,
|
||||
const YGConfigRef config,
|
||||
YGMarkerLayoutData& layoutMarkerData) {
|
||||
YGMarkerLayoutData& layoutMarkerData,
|
||||
void* const layoutContext) {
|
||||
YGLayout* layout = &node->getLayout();
|
||||
|
||||
gDepth++;
|
||||
@@ -3739,7 +3719,7 @@ bool YGLayoutNodeInternal(
|
||||
// dimensions. We handle nodes with measure functions specially here because
|
||||
// they are the most expensive to measure, so it's worth avoiding redundant
|
||||
// measurements if at all possible.
|
||||
if (node->getMeasure() != nullptr) {
|
||||
if (node->hasMeasureFunc()) {
|
||||
const float marginAxisRow =
|
||||
node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap();
|
||||
const float marginAxisColumn =
|
||||
@@ -3814,18 +3794,18 @@ bool YGLayoutNodeInternal(
|
||||
: layoutMarkerData.cachedMeasures) += 1;
|
||||
|
||||
if (gPrintChanges && gPrintSkips) {
|
||||
YGLog(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"%s%d.{[skipped] ",
|
||||
YGSpacer(gDepth),
|
||||
gDepth);
|
||||
if (node->getPrintFunc() != nullptr) {
|
||||
node->getPrintFunc()(node);
|
||||
}
|
||||
YGLog(
|
||||
node->print(layoutContext);
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
|
||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||
@@ -3837,19 +3817,19 @@ bool YGLayoutNodeInternal(
|
||||
}
|
||||
} else {
|
||||
if (gPrintChanges) {
|
||||
YGLog(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"%s%d.{%s",
|
||||
YGSpacer(gDepth),
|
||||
gDepth,
|
||||
needToVisitNode ? "*" : "");
|
||||
if (node->getPrintFunc() != nullptr) {
|
||||
node->getPrintFunc()(node);
|
||||
}
|
||||
YGLog(
|
||||
node->print(layoutContext);
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
|
||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||
@@ -3869,22 +3849,23 @@ bool YGLayoutNodeInternal(
|
||||
ownerHeight,
|
||||
performLayout,
|
||||
config,
|
||||
layoutMarkerData);
|
||||
layoutMarkerData,
|
||||
layoutContext);
|
||||
|
||||
if (gPrintChanges) {
|
||||
YGLog(
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"%s%d.}%s",
|
||||
YGSpacer(gDepth),
|
||||
gDepth,
|
||||
needToVisitNode ? "*" : "");
|
||||
if (node->getPrintFunc() != nullptr) {
|
||||
node->getPrintFunc()(node);
|
||||
}
|
||||
YGLog(
|
||||
node->print(layoutContext);
|
||||
Log::log(
|
||||
node,
|
||||
YGLogLevelVerbose,
|
||||
nullptr,
|
||||
"wm: %s, hm: %s, d: (%f, %f) %s\n",
|
||||
YGMeasureModeName(widthMeasureMode, performLayout),
|
||||
YGMeasureModeName(heightMeasureMode, performLayout),
|
||||
@@ -3901,9 +3882,9 @@ bool YGLayoutNodeInternal(
|
||||
layoutMarkerData.maxMeasureCache =
|
||||
layout->nextCachedMeasurementsIndex + 1;
|
||||
}
|
||||
if (layout->nextCachedMeasurementsIndex == YG_MAX_CACHED_RESULT_COUNT) {
|
||||
if (layout->nextCachedMeasurementsIndex == usedMeasureCacheEntries) {
|
||||
if (gPrintChanges) {
|
||||
YGLog(node, YGLogLevelVerbose, "Out of cache entries!\n");
|
||||
Log::log(node, YGLogLevelVerbose, nullptr, "Out of cache entries!\n");
|
||||
}
|
||||
layout->nextCachedMeasurementsIndex = 0;
|
||||
}
|
||||
@@ -4037,11 +4018,12 @@ static void YGRoundToPixelGrid(
|
||||
}
|
||||
}
|
||||
|
||||
void YGNodeCalculateLayout(
|
||||
void YGNodeCalculateLayoutWithContext(
|
||||
const YGNodeRef node,
|
||||
const float ownerWidth,
|
||||
const float ownerHeight,
|
||||
const YGDirection ownerDirection) {
|
||||
const YGDirection ownerDirection,
|
||||
void* layoutContext) {
|
||||
marker::MarkerSection<YGMarkerLayout> marker{node};
|
||||
|
||||
// Increment the generation count. This will force the recursive routine to
|
||||
@@ -4105,11 +4087,13 @@ void YGNodeCalculateLayout(
|
||||
true,
|
||||
"initial",
|
||||
node->getConfig(),
|
||||
marker.data)) {
|
||||
marker.data,
|
||||
layoutContext)) {
|
||||
node->setPosition(
|
||||
node->getLayout().direction, ownerWidth, ownerHeight, ownerWidth);
|
||||
YGRoundToPixelGrid(node, node->getConfig()->pointScaleFactor, 0.0f, 0.0f);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (node->getConfig()->printTree) {
|
||||
YGNodePrint(
|
||||
node,
|
||||
@@ -4117,6 +4101,7 @@ void YGNodeCalculateLayout(
|
||||
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// We want to get rid off `useLegacyStretchBehaviour` from YGConfig. But we
|
||||
@@ -4148,7 +4133,8 @@ void YGNodeCalculateLayout(
|
||||
true,
|
||||
"initial",
|
||||
originalNode->getConfig(),
|
||||
layoutMarkerData)) {
|
||||
layoutMarkerData,
|
||||
layoutContext)) {
|
||||
originalNode->setPosition(
|
||||
originalNode->getLayout().direction,
|
||||
ownerWidth,
|
||||
@@ -4165,6 +4151,7 @@ void YGNodeCalculateLayout(
|
||||
!originalNode->isLayoutTreeEqualToNode(*node);
|
||||
node->setLayoutDoesLegacyFlagAffectsLayout(neededLegacyStretchBehaviour);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (originalNode->getConfig()->printTree) {
|
||||
YGNodePrint(
|
||||
originalNode,
|
||||
@@ -4172,20 +4159,30 @@ void YGNodeCalculateLayout(
|
||||
YGPrintOptionsLayout | YGPrintOptionsChildren |
|
||||
YGPrintOptionsStyle));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
YGConfigFreeRecursive(originalNode);
|
||||
YGNodeFreeRecursive(originalNode);
|
||||
}
|
||||
}
|
||||
|
||||
void YGNodeCalculateLayout(
|
||||
const YGNodeRef node,
|
||||
const float ownerWidth,
|
||||
const float ownerHeight,
|
||||
const YGDirection ownerDirection) {
|
||||
YGNodeCalculateLayoutWithContext(
|
||||
node, ownerWidth, ownerHeight, ownerDirection, nullptr);
|
||||
}
|
||||
|
||||
void YGConfigSetLogger(const YGConfigRef config, YGLogger logger) {
|
||||
if (logger != nullptr) {
|
||||
config->logger = logger;
|
||||
config->setLogger(logger);
|
||||
} else {
|
||||
#ifdef ANDROID
|
||||
config->logger = &YGAndroidLog;
|
||||
config->setLogger(&YGAndroidLog);
|
||||
#else
|
||||
config->logger = &YGDefaultLog;
|
||||
config->setLogger(&YGDefaultLog);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -4196,43 +4193,9 @@ void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
|
||||
config->shouldDiffLayoutWithoutLegacyStretchBehaviour = shouldDiffLayout;
|
||||
}
|
||||
|
||||
static void YGVLog(
|
||||
const YGConfigRef config,
|
||||
const YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
const YGConfigRef logConfig =
|
||||
config != nullptr ? config : YGConfigGetDefault();
|
||||
logConfig->logger(logConfig, node, level, format, args);
|
||||
|
||||
if (level == YGLogLevelFatal) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void YGLogWithConfig(
|
||||
const YGConfigRef config,
|
||||
YGLogLevel level,
|
||||
const char* format,
|
||||
...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
YGVLog(config, nullptr, level, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void YGLog(const YGNodeRef node, YGLogLevel level, const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
YGVLog(
|
||||
node == nullptr ? nullptr : node->getConfig(), node, level, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void YGAssert(const bool condition, const char* message) {
|
||||
if (!condition) {
|
||||
YGLog(nullptr, YGLogLevelFatal, "%s\n", message);
|
||||
Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4241,7 +4204,7 @@ void YGAssertWithNode(
|
||||
const bool condition,
|
||||
const char* message) {
|
||||
if (!condition) {
|
||||
YGLog(node, YGLogLevelFatal, "%s\n", message);
|
||||
Log::log(node, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4250,7 +4213,7 @@ void YGAssertWithConfig(
|
||||
const bool condition,
|
||||
const char* message) {
|
||||
if (!condition) {
|
||||
YGLogWithConfig(config, YGLogLevelFatal, "%s\n", message);
|
||||
Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4292,7 +4255,7 @@ void* YGConfigGetContext(const YGConfigRef config) {
|
||||
void YGConfigSetCloneNodeFunc(
|
||||
const YGConfigRef config,
|
||||
const YGCloneNodeFunc callback) {
|
||||
config->cloneNodeCallback = callback;
|
||||
config->setCloneNodeCallback(callback);
|
||||
}
|
||||
|
||||
static void YGTraverseChildrenPreOrder(
|
||||
|
17
yoga/Yoga.h
17
yoga/Yoga.h
@@ -132,13 +132,12 @@ WIN_EXPORT void YGNodeCopyStyle(
|
||||
WIN_EXPORT void* YGNodeGetContext(YGNodeRef node);
|
||||
WIN_EXPORT void YGNodeSetContext(YGNodeRef node, void* context);
|
||||
void YGConfigSetPrintTreeFlag(YGConfigRef config, bool enabled);
|
||||
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node);
|
||||
bool YGNodeHasMeasureFunc(YGNodeRef node);
|
||||
WIN_EXPORT void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
||||
YGBaselineFunc YGNodeGetBaselineFunc(YGNodeRef node);
|
||||
bool YGNodeHasBaselineFunc(YGNodeRef node);
|
||||
void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc);
|
||||
YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node);
|
||||
void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc);
|
||||
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node);
|
||||
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
||||
WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node);
|
||||
WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);
|
||||
@@ -348,16 +347,6 @@ WIN_EXPORT float YGNodeLayoutGetPadding(
|
||||
const YGEdge edge);
|
||||
|
||||
WIN_EXPORT void YGConfigSetLogger(const YGConfigRef config, YGLogger logger);
|
||||
WIN_EXPORT void YGLog(
|
||||
const YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
const char* message,
|
||||
...);
|
||||
WIN_EXPORT void YGLogWithConfig(
|
||||
const YGConfigRef config,
|
||||
YGLogLevel level,
|
||||
const char* format,
|
||||
...);
|
||||
WIN_EXPORT void YGAssert(const bool condition, const char* message);
|
||||
WIN_EXPORT void YGAssertWithNode(
|
||||
const YGNodeRef node,
|
||||
@@ -422,6 +411,8 @@ WIN_EXPORT float YGRoundValueToPixelGrid(
|
||||
const bool forceCeil,
|
||||
const bool forceFloor);
|
||||
|
||||
void YGSetUsedCachedEntries(size_t);
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -28,9 +28,12 @@ public:
|
||||
typename Data::type data = {};
|
||||
|
||||
template <typename Ret, typename... Args>
|
||||
static Ret wrap(YGNodeRef node, Ret (*fn)(Args...), Args... args) {
|
||||
static Ret wrap(
|
||||
YGNodeRef node,
|
||||
Ret (YGNode::*method)(Args...),
|
||||
Args... args) {
|
||||
MarkerSection<MarkerType> section{node};
|
||||
return fn(std::forward<Args>(args)...);
|
||||
return (node->*method)(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
|
68
yoga/log.cpp
Normal file
68
yoga/log.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "Yoga.h"
|
||||
#include "YGConfig.h"
|
||||
#include "YGNode.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
namespace detail {
|
||||
|
||||
namespace {
|
||||
|
||||
void vlog(
|
||||
YGConfig* config,
|
||||
YGNode* node,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault();
|
||||
logConfig->log(logConfig, node, level, context, format, args);
|
||||
|
||||
if (level == YGLogLevelFatal) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Log::log(
|
||||
YGNode* node,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
const char* format,
|
||||
...) noexcept {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vlog(
|
||||
node == nullptr ? nullptr : node->getConfig(),
|
||||
node,
|
||||
level,
|
||||
context,
|
||||
format,
|
||||
args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Log::log(
|
||||
YGConfig* config,
|
||||
YGLogLevel level,
|
||||
void* context,
|
||||
const char* format,
|
||||
...) noexcept {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vlog(config, nullptr, level, context, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
37
yoga/log.h
Normal file
37
yoga/log.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* 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 "YGEnums.h"
|
||||
|
||||
struct YGNode;
|
||||
struct YGConfig;
|
||||
|
||||
namespace facebook {
|
||||
namespace yoga {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct Log {
|
||||
static void log(
|
||||
YGNode* node,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* message,
|
||||
...) noexcept;
|
||||
|
||||
static void log(
|
||||
YGConfig* config,
|
||||
YGLogLevel level,
|
||||
void*,
|
||||
const char* format,
|
||||
...) noexcept;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace yoga
|
||||
} // namespace facebook
|
Reference in New Issue
Block a user