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:
Lukas Woehrl
2017-01-02 05:20:37 -08:00
committed by Facebook Github Bot
parent 6f462a72bf
commit a85bd4ad2a
48 changed files with 4948 additions and 1209 deletions

View File

@@ -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);