Add feature to use percentage as value unit
Summary: Adds the feature to use percentage as a value unit. You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience. I did some benchmarks: ``` Without Percentage Feature - Release x86: Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms Nested flex: median: 0.000000 ms, stddev: 0.490101 ms Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms Nested flex: median: 0.000000 ms, stddev: 0.477791 ms Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms With Percentage Feature - Release x86: Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms Nested flex: median: 0.000000 ms, stddev: 0.489570 ms Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms Closes https://github.com/facebook/yoga/pull/258 Reviewed By: dshahidehpour Differential Revision: D4361945 Pulled By: emilsjolander fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
This commit is contained in:
committed by
Facebook Github Bot
parent
6f462a72bf
commit
a85bd4ad2a
@@ -16,4 +16,8 @@ public class YogaConstants {
|
||||
public static boolean isUndefined(float value) {
|
||||
return Float.compare(value, UNDEFINED) == 0;
|
||||
}
|
||||
|
||||
public static boolean isUndefined(YogaValue value) {
|
||||
return value.unit == YogaUnit.UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
@@ -323,10 +323,10 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
private native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
|
||||
@Override
|
||||
public float getFlexBasis() {
|
||||
return jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
public YogaValue getFlexBasis() {
|
||||
return (YogaValue) jni_YGNodeStyleGetFlexBasis(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
|
||||
@@ -335,13 +335,19 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
private native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getMargin(YogaEdge edge) {
|
||||
public void setFlexBasisPercent(float percent) {
|
||||
jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
|
||||
@Override
|
||||
public YogaValue getMargin(YogaEdge edge) {
|
||||
if (!mHasSetMargin) {
|
||||
return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED;
|
||||
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
|
||||
}
|
||||
return jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
|
||||
@@ -351,13 +357,20 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
private native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
|
||||
@Override
|
||||
public float getPadding(YogaEdge edge) {
|
||||
public void setMarginPercent(YogaEdge edge, float percent) {
|
||||
mHasSetMargin = true;
|
||||
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
|
||||
@Override
|
||||
public YogaValue getPadding(YogaEdge edge) {
|
||||
if (!mHasSetPadding) {
|
||||
return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED;
|
||||
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
|
||||
}
|
||||
return jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
|
||||
@@ -367,6 +380,13 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
|
||||
@Override
|
||||
public void setPaddingPercent(YogaEdge edge, float percent) {
|
||||
mHasSetPadding = true;
|
||||
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
|
||||
@Override
|
||||
public float getBorder(YogaEdge edge) {
|
||||
@@ -383,13 +403,13 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
private native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
|
||||
@Override
|
||||
public float getPosition(YogaEdge edge) {
|
||||
public YogaValue getPosition(YogaEdge edge) {
|
||||
if (!mHasSetPosition) {
|
||||
return YogaConstants.UNDEFINED;
|
||||
return YogaValue.UNDEFINED;
|
||||
}
|
||||
return jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
return (YogaValue) jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue());
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
|
||||
@@ -399,10 +419,17 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
|
||||
@Override
|
||||
public float getWidth() {
|
||||
return jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
public void setPositionPercent(YogaEdge edge, float percent) {
|
||||
mHasSetPosition = true;
|
||||
jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetWidth(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
|
||||
@@ -411,10 +438,16 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetWidth(mNativePointer, width);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
public void setWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetHeight(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
|
||||
@@ -423,10 +456,16 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetHeight(mNativePointer, height);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getMinWidth() {
|
||||
return jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
public void setHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getMinWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
|
||||
@@ -435,10 +474,16 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getMinHeight() {
|
||||
return jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
public void setMinWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getMinHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMinHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
|
||||
@@ -447,10 +492,16 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getMaxWidth() {
|
||||
return jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
public void setMinHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getMaxWidth() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxWidth(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
|
||||
@@ -459,10 +510,16 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
private native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public float getMaxHeight() {
|
||||
return jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
public void setMaxWidthPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
|
||||
@Override
|
||||
public YogaValue getMaxHeight() {
|
||||
return (YogaValue) jni_YGNodeStyleGetMaxHeight(mNativePointer);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
|
||||
@@ -471,6 +528,12 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
|
||||
jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
|
||||
@Override
|
||||
public void setMaxHeightPercent(float percent) {
|
||||
jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
|
||||
}
|
||||
|
||||
private native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
|
||||
public float getAspectRatio() {
|
||||
return jni_YGNodeStyleGetAspectRatio(mNativePointer);
|
||||
|
@@ -45,28 +45,38 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
|
||||
void setFlexGrow(float flexGrow);
|
||||
float getFlexShrink();
|
||||
void setFlexShrink(float flexShrink);
|
||||
float getFlexBasis();
|
||||
YogaValue getFlexBasis();
|
||||
void setFlexBasis(float flexBasis);
|
||||
float getMargin(YogaEdge edge);
|
||||
void setFlexBasisPercent(float percent);
|
||||
YogaValue getMargin(YogaEdge edge);
|
||||
void setMargin(YogaEdge edge, float margin);
|
||||
float getPadding(YogaEdge edge);
|
||||
void setMarginPercent(YogaEdge edge, float percent);
|
||||
YogaValue getPadding(YogaEdge edge);
|
||||
void setPadding(YogaEdge edge, float padding);
|
||||
void setPaddingPercent(YogaEdge edge, float percent);
|
||||
float getBorder(YogaEdge edge);
|
||||
void setBorder(YogaEdge edge, float border);
|
||||
float getPosition(YogaEdge edge);
|
||||
YogaValue getPosition(YogaEdge edge);
|
||||
void setPosition(YogaEdge edge, float position);
|
||||
float getWidth();
|
||||
void setPositionPercent(YogaEdge edge, float percent);
|
||||
YogaValue getWidth();
|
||||
void setWidth(float width);
|
||||
float getHeight();
|
||||
void setWidthPercent(float percent);
|
||||
YogaValue getHeight();
|
||||
void setHeight(float height);
|
||||
float getMaxWidth();
|
||||
void setHeightPercent(float percent);
|
||||
YogaValue getMaxWidth();
|
||||
void setMaxWidth(float maxWidth);
|
||||
float getMinWidth();
|
||||
void setMaxWidthPercent(float percent);
|
||||
YogaValue getMinWidth();
|
||||
void setMinWidth(float minWidth);
|
||||
float getMaxHeight();
|
||||
void setMinWidthPercent(float percent);
|
||||
YogaValue getMaxHeight();
|
||||
void setMaxHeight(float maxHeight);
|
||||
float getMinHeight();
|
||||
void setMaxHeightPercent(float percent);
|
||||
YogaValue getMinHeight();
|
||||
void setMinHeight(float minHeight);
|
||||
void setMinHeightPercent(float percent);
|
||||
float getLayoutX();
|
||||
float getLayoutY();
|
||||
float getLayoutWidth();
|
||||
|
38
java/com/facebook/yoga/YogaUnit.java
Normal file
38
java/com/facebook/yoga/YogaUnit.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public enum YogaUnit {
|
||||
UNDEFINED(0),
|
||||
PIXEL(1),
|
||||
PERCENT(2);
|
||||
|
||||
private int mIntValue;
|
||||
|
||||
YogaUnit(int intValue) {
|
||||
mIntValue = intValue;
|
||||
}
|
||||
|
||||
public int intValue() {
|
||||
return mIntValue;
|
||||
}
|
||||
|
||||
public static YogaUnit fromInt(int value) {
|
||||
switch (value) {
|
||||
case 0: return UNDEFINED;
|
||||
case 1: return PIXEL;
|
||||
case 2: return PERCENT;
|
||||
default: throw new IllegalArgumentException("Unkown enum value: " + value);
|
||||
}
|
||||
}
|
||||
}
|
45
java/com/facebook/yoga/YogaValue.java
Normal file
45
java/com/facebook/yoga/YogaValue.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
package com.facebook.yoga;
|
||||
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@DoNotStrip
|
||||
public class YogaValue {
|
||||
static final YogaValue UNDEFINED = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED);
|
||||
static final YogaValue ZERO = new YogaValue(0, YogaUnit.PIXEL);
|
||||
|
||||
public final float value;
|
||||
public final YogaUnit unit;
|
||||
|
||||
YogaValue(float value, YogaUnit unit) {
|
||||
this.value = value;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
YogaValue(float value, int unit) {
|
||||
this(value, YogaUnit.fromInt(unit));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof YogaValue) {
|
||||
final YogaValue otherValue = (YogaValue) other;
|
||||
return value == otherValue.value && unit == otherValue.unit;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Float.floatToIntBits(value) + unit.intValue();
|
||||
}
|
||||
}
|
@@ -7,9 +7,9 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#include <yoga/Yoga.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <iostream>
|
||||
#include <yoga/Yoga.h>
|
||||
|
||||
using namespace facebook::jni;
|
||||
using namespace std;
|
||||
@@ -70,8 +70,8 @@ static YGSize YGJNIMeasureFunc(YGNodeRef node,
|
||||
int32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
|
||||
int32_t hBits = 0xFFFFFFFF & measureResult;
|
||||
|
||||
const float *measuredWidth = reinterpret_cast<float*>(&wBits);
|
||||
const float *measuredHeight = reinterpret_cast<float*>(&hBits);
|
||||
const float *measuredWidth = reinterpret_cast<float *>(&wBits);
|
||||
const float *measuredHeight = reinterpret_cast<float *>(&hBits);
|
||||
|
||||
return YGSize{*measuredWidth, *measuredHeight};
|
||||
} else {
|
||||
@@ -204,6 +204,14 @@ void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNa
|
||||
YGNodeCopyStyle(_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(alias_ref<jobject>, jlong nativePointer) { \
|
||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
|
||||
@@ -213,6 +221,19 @@ void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNa
|
||||
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast<type>(value)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer) { \
|
||||
return JYogaValue::create(YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
|
||||
} \
|
||||
\
|
||||
void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
||||
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
||||
} \
|
||||
\
|
||||
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, jlong nativePointer, jfloat value) { \
|
||||
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \
|
||||
javatype jni_YGNodeStyleGet##name(alias_ref<jobject>, jlong nativePointer, jint edge) { \
|
||||
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), \
|
||||
@@ -228,6 +249,29 @@ void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNa
|
||||
static_cast<type>(value)); \
|
||||
}
|
||||
|
||||
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
|
||||
local_ref<jobject> jni_YGNodeStyleGet##name(alias_ref<jobject>, \
|
||||
jlong nativePointer, \
|
||||
jint edge) { \
|
||||
return JYogaValue::create( \
|
||||
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
|
||||
} \
|
||||
\
|
||||
void jni_YGNodeStyleSet##name(alias_ref<jobject>, jlong nativePointer, jint edge, jfloat value) { \
|
||||
YGNodeStyleSet##name(_jlong2YGNodeRef(nativePointer), \
|
||||
static_cast<YGEdge>(edge), \
|
||||
static_cast<float>(value)); \
|
||||
} \
|
||||
\
|
||||
void jni_YGNodeStyleSet##name##Percent(alias_ref<jobject>, \
|
||||
jlong nativePointer, \
|
||||
jint edge, \
|
||||
jfloat value) { \
|
||||
YGNodeStyleSet##name##Percent(_jlong2YGNodeRef(nativePointer), \
|
||||
static_cast<YGEdge>(edge), \
|
||||
static_cast<float>(value)); \
|
||||
}
|
||||
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection);
|
||||
YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent);
|
||||
@@ -243,19 +287,19 @@ void jni_YGNodeStyleSetFlex(alias_ref<jobject>, jlong nativePointer, jfloat valu
|
||||
}
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexBasis);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(FlexBasis);
|
||||
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Position);
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Margin);
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Padding);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Position);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Margin);
|
||||
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Padding);
|
||||
YG_NODE_JNI_STYLE_EDGE_PROP(jfloat, float, Border);
|
||||
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, Width);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, MinWidth);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, MaxWidth);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, Height);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, MinHeight);
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, MaxHeight);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(Width);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MinWidth);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MaxWidth);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(Height);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MinHeight);
|
||||
YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight);
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
|
||||
@@ -278,7 +322,6 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeMarkLayoutSeen),
|
||||
YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc),
|
||||
YGMakeNativeMethod(jni_YGNodeCopyStyle),
|
||||
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetDirection),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetDirection),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetFlexDirection),
|
||||
@@ -303,29 +346,38 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexShrink),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasis),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetFlexBasisPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMargin),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMargin),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMarginPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetPadding),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPadding),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPaddingPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetBorder),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetBorder),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetPosition),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPosition),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetPositionPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetWidthPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetHeightPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinWidthPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMinHeightPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidth),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMaxWidthPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeight),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetMaxHeightPercent),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleGetAspectRatio),
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||
|
||||
YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
|
||||
YGMakeNativeMethod(jni_YGSetLogger),
|
||||
YGMakeNativeMethod(jni_YGLog),
|
||||
|
941
java/tests/com/facebook/yoga/YGPercentageTest.java
Normal file
941
java/tests/com/facebook/yoga/YGPercentageTest.java
Normal file
@@ -0,0 +1,941 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
// @Generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html
|
||||
|
||||
package com.facebook.yoga;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class YGPercentageTest {
|
||||
@Test
|
||||
public void test_percentage_width_height() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setWidthPercent(30f);
|
||||
root_child0.setHeightPercent(30f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(140f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_position_left_top() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(400f);
|
||||
root.setHeight(400f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setPositionPercent(YogaEdge.LEFT, 10f);
|
||||
root_child0.setPositionPercent(YogaEdge.TOP, 20f);
|
||||
root_child0.setWidthPercent(45f);
|
||||
root_child0.setHeightPercent(55f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(400f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(400f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(40f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(180f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(220f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(400f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(400f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(260f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(80f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(180f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(220f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_position_bottom_right() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(500f);
|
||||
root.setHeight(500f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setPositionPercent(YogaEdge.RIGHT, 20f);
|
||||
root_child0.setPositionPercent(YogaEdge.BOTTOM, 10f);
|
||||
root_child0.setWidthPercent(55f);
|
||||
root_child0.setHeightPercent(15f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(500f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(500f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(-100f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(275f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(500f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(500f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(125f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(-50f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(275f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(75f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setFlexBasisPercent(25f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(125f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(125f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(75f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(125f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_cross() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(1f);
|
||||
root_child1.setFlexBasisPercent(25f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(125f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(125f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(125f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(125f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(75f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_cross_min_height() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setMinHeightPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(2f);
|
||||
root_child1.setMinHeightPercent(10f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(140f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(140f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(140f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(140f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_main_max_height() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(10f);
|
||||
root_child0.setMaxHeightPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(10f);
|
||||
root_child1.setMaxHeightPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(52f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(148f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(148f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(52f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(148f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_cross_max_height() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(10f);
|
||||
root_child0.setMaxHeightPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(10f);
|
||||
root_child1.setMaxHeightPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(120f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(120f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_main_max_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(15f);
|
||||
root_child0.setMaxWidthPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(10f);
|
||||
root_child1.setMaxWidthPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(120f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(40f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_cross_max_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(10f);
|
||||
root_child0.setMaxWidthPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(15f);
|
||||
root_child1.setMaxWidthPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(160f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(40f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_main_min_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(15f);
|
||||
root_child0.setMinWidthPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(10f);
|
||||
root_child1.setMinWidthPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(120f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(80f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(80f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(120f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(80f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_flex_basis_cross_min_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(10f);
|
||||
root_child0.setMinWidthPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(15f);
|
||||
root_child1.setMinWidthPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(150f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_multiple_nested_with_padding_margin_and_percentage_values() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(200f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setFlexBasisPercent(10f);
|
||||
root_child0.setMargin(YogaEdge.LEFT, 5f);
|
||||
root_child0.setMargin(YogaEdge.TOP, 5f);
|
||||
root_child0.setMargin(YogaEdge.RIGHT, 5f);
|
||||
root_child0.setMargin(YogaEdge.BOTTOM, 5f);
|
||||
root_child0.setPadding(YogaEdge.LEFT, 3);
|
||||
root_child0.setPadding(YogaEdge.TOP, 3);
|
||||
root_child0.setPadding(YogaEdge.RIGHT, 3);
|
||||
root_child0.setPadding(YogaEdge.BOTTOM, 3);
|
||||
root_child0.setMinWidthPercent(60f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child0 = new YogaNode();
|
||||
root_child0_child0.setMargin(YogaEdge.LEFT, 5f);
|
||||
root_child0_child0.setMargin(YogaEdge.TOP, 5f);
|
||||
root_child0_child0.setMargin(YogaEdge.RIGHT, 5f);
|
||||
root_child0_child0.setMargin(YogaEdge.BOTTOM, 5f);
|
||||
root_child0_child0.setPaddingPercent(YogaEdge.LEFT, 3);
|
||||
root_child0_child0.setPaddingPercent(YogaEdge.TOP, 3);
|
||||
root_child0_child0.setPaddingPercent(YogaEdge.RIGHT, 3);
|
||||
root_child0_child0.setPaddingPercent(YogaEdge.BOTTOM, 3);
|
||||
root_child0_child0.setWidthPercent(50f);
|
||||
root_child0.addChildAt(root_child0_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child0_child0 = new YogaNode();
|
||||
root_child0_child0_child0.setMarginPercent(YogaEdge.LEFT, 5f);
|
||||
root_child0_child0_child0.setMarginPercent(YogaEdge.TOP, 5f);
|
||||
root_child0_child0_child0.setMarginPercent(YogaEdge.RIGHT, 5f);
|
||||
root_child0_child0_child0.setMarginPercent(YogaEdge.BOTTOM, 5f);
|
||||
root_child0_child0_child0.setPadding(YogaEdge.LEFT, 3);
|
||||
root_child0_child0_child0.setPadding(YogaEdge.TOP, 3);
|
||||
root_child0_child0_child0.setPadding(YogaEdge.RIGHT, 3);
|
||||
root_child0_child0_child0.setPadding(YogaEdge.BOTTOM, 3);
|
||||
root_child0_child0_child0.setWidthPercent(45f);
|
||||
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setFlexGrow(4f);
|
||||
root_child1.setFlexBasisPercent(15f);
|
||||
root_child1.setMinWidthPercent(20f);
|
||||
root.addChildAt(root_child1, 1);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(190f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(48f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(8f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(8f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(92f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(25f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(10f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(36f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(6f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(58f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(142f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(190f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(48f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(90f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(8f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(92f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(25f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(46f, root_child0_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(36f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(6f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||
assertEquals(58f, root_child1.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child1.getLayoutWidth(), 0.0f);
|
||||
assertEquals(142f, root_child1.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_margin_should_calculate_based_only_on_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setMarginPercent(YogaEdge.LEFT, 10f);
|
||||
root_child0.setMarginPercent(YogaEdge.TOP, 10f);
|
||||
root_child0.setMarginPercent(YogaEdge.RIGHT, 10f);
|
||||
root_child0.setMarginPercent(YogaEdge.BOTTOM, 10f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child0 = new YogaNode();
|
||||
root_child0_child0.setWidth(10f);
|
||||
root_child0_child0.setHeight(10f);
|
||||
root_child0.addChildAt(root_child0_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(160f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(160f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(60f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(150f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_padding_should_calculate_based_only_on_width() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setFlexGrow(1f);
|
||||
root_child0.setPaddingPercent(YogaEdge.LEFT, 10);
|
||||
root_child0.setPaddingPercent(YogaEdge.TOP, 10);
|
||||
root_child0.setPaddingPercent(YogaEdge.RIGHT, 10);
|
||||
root_child0.setPaddingPercent(YogaEdge.BOTTOM, 10);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child0_child0 = new YogaNode();
|
||||
root_child0_child0.setWidth(10f);
|
||||
root_child0_child0.setHeight(10f);
|
||||
root_child0.addChildAt(root_child0_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(20f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(20f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(170f, root_child0_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(20f, root_child0_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_percentage_absolute_position() {
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
|
||||
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setWidth(200f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
|
||||
root_child0.setPositionPercent(YogaEdge.LEFT, 30f);
|
||||
root_child0.setPositionPercent(YogaEdge.TOP, 10f);
|
||||
root_child0.setWidth(10f);
|
||||
root_child0.setHeight(10f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
root.setDirection(YogaDirection.LTR);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(60f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
root.setDirection(YogaDirection.RTL);
|
||||
root.calculateLayout();
|
||||
|
||||
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||
assertEquals(200f, root.getLayoutWidth(), 0.0f);
|
||||
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||
|
||||
assertEquals(60f, root_child0.getLayoutX(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutY(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
|
||||
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
||||
|
||||
YogaNode.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, false);
|
||||
}
|
||||
|
||||
}
|
@@ -136,6 +136,6 @@ public class YogaNodeTest {
|
||||
node1.setMaxHeight(100);
|
||||
|
||||
node0.copyStyle(node1);
|
||||
assertEquals(100, (int) node0.getMaxHeight());
|
||||
assertEquals(100, (int) node0.getMaxHeight().value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user