diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index a257eb8c..5f0391cb 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -144,6 +144,18 @@ public class YogaNative { static native void jni_YGNodeStyleSetFlexBasisJNI(long nativePointer, float flexBasis); static native void jni_YGNodeStyleSetFlexBasisPercentJNI(long nativePointer, float percent); static native void jni_YGNodeStyleSetFlexBasisAutoJNI(long nativePointer); + static native long jni_YGNodeStyleGetMarginJNI(long nativePointer, int edge); + static native void jni_YGNodeStyleSetMarginJNI(long nativePointer, int edge, float margin); + static native void jni_YGNodeStyleSetMarginPercentJNI(long nativePointer, int edge, float percent); + static native void jni_YGNodeStyleSetMarginAutoJNI(long nativePointer, int edge); + static native long jni_YGNodeStyleGetPaddingJNI(long nativePointer, int edge); + static native void jni_YGNodeStyleSetPaddingJNI(long nativePointer, int edge, float padding); + static native void jni_YGNodeStyleSetPaddingPercentJNI(long nativePointer, int edge, float percent); + static native float jni_YGNodeStyleGetBorderJNI(long nativePointer, int edge); + static native void jni_YGNodeStyleSetBorderJNI(long nativePointer, int edge, float border); + static native long jni_YGNodeStyleGetPositionJNI(long nativePointer, int edge); + static native void jni_YGNodeStyleSetPositionJNI(long nativePointer, int edge, float position); + static native void jni_YGNodeStyleSetPositionPercentJNI(long nativePointer, int edge, float percent); static native long jni_YGNodeStyleGetWidthJNI(long nativePointer); static native void jni_YGNodeStyleSetWidthJNI(long nativePointer, float width); static native void jni_YGNodeStyleSetWidthPercentJNI(long nativePointer, float percent); diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 3b7f5b63..744c5979 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -372,51 +372,75 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public YogaValue getMargin(YogaEdge edge) { - return valueFromLong(YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue())); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMarginJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue())); } public void setMargin(YogaEdge edge, float margin) { - YogaNative.jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMarginJNI(mNativePointer, edge.intValue(), margin); + else + YogaNative.jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin); } public void setMarginPercent(YogaEdge edge, float percent) { - YogaNative.jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMarginPercentJNI(mNativePointer, edge.intValue(), percent); + else + YogaNative.jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent); } public void setMarginAuto(YogaEdge edge) { - YogaNative.jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue()); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetMarginAutoJNI(mNativePointer, edge.intValue()); + else + YogaNative.jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue()); } public YogaValue getPadding(YogaEdge edge) { - return valueFromLong(YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue())); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPaddingJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue())); } public void setPadding(YogaEdge edge, float padding) { - YogaNative.jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetPaddingJNI(mNativePointer, edge.intValue(), padding); + else + YogaNative.jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding); } public void setPaddingPercent(YogaEdge edge, float percent) { - YogaNative.jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetPaddingPercentJNI(mNativePointer, edge.intValue(), percent); + else + YogaNative.jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent); } public float getBorder(YogaEdge edge) { - return YogaNative.jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue()); + return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetBorderJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue()); } public void setBorder(YogaEdge edge, float border) { - YogaNative.jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetBorderJNI(mNativePointer, edge.intValue(), border); + else + YogaNative.jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border); } public YogaValue getPosition(YogaEdge edge) { - return valueFromLong(YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue())); + return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPositionJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue())); } public void setPosition(YogaEdge edge, float position) { - YogaNative.jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetPositionJNI(mNativePointer, edge.intValue(), position); + else + YogaNative.jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position); } public void setPositionPercent(YogaEdge edge, float percent) { - YogaNative.jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent); + if (useVanillaJNI) + YogaNative.jni_YGNodeStyleSetPositionPercentJNI(mNativePointer, edge.intValue(), percent); + else + YogaNative.jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent); } public YogaValue getWidth() { diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index c0423208..595fe204 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/java/jni/YGJNI.h b/java/jni/YGJNI.h index d69fba47..f0c489c1 100644 --- a/java/jni/YGJNI.h +++ b/java/jni/YGJNI.h @@ -4,8 +4,6 @@ * This source code is licensed under the MIT license found in the LICENSE * file in the root directory of this source tree. */ -#include - namespace { union YGNodeContext { diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 86899508..395d4526 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -7,6 +7,7 @@ #include "jni.h" #include "YGJNIVanilla.h" #include +#include #include "YGJNI.h" static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { @@ -51,6 +52,37 @@ static inline YGNodeRef _jlong2YGNodeRef(jlong addr) { YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \ } +#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \ + static jlong jni_YGNodeStyleGet##name##JNI( \ + JNIEnv* env, jobject obj, jlong nativePointer, jint edge) { \ + return YogaValue::asJavaLong(YGNodeStyleGet##name( \ + _jlong2YGNodeRef(nativePointer), static_cast(edge))); \ + } \ + \ + static void jni_YGNodeStyleSet##name##JNI( \ + JNIEnv* env, \ + jobject obj, \ + jlong nativePointer, \ + jint edge, \ + jfloat value) { \ + YGNodeStyleSet##name( \ + _jlong2YGNodeRef(nativePointer), \ + static_cast(edge), \ + static_cast(value)); \ + } \ + \ + static void jni_YGNodeStyleSet##name##PercentJNI( \ + JNIEnv* env, \ + jobject obj, \ + jlong nativePointer, \ + jint edge, \ + jfloat value) { \ + YGNodeStyleSet##name##Percent( \ + _jlong2YGNodeRef(nativePointer), \ + static_cast(edge), \ + static_cast(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); @@ -73,6 +105,116 @@ YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Height); YG_NODE_JNI_STYLE_UNIT_PROP(MinHeight); YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight); +YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Position); + +static jlong jni_YGNodeStyleGetMarginJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) { + return YogaValue::undefinedAsJavaLong(); + } + return YogaValue::asJavaLong( + YGNodeStyleGetMargin(yogaNodeRef, static_cast(edge))); +} + +static void jni_YGNodeStyleSetMarginJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge, + jfloat margin) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef); + YGNodeStyleSetMargin( + yogaNodeRef, static_cast(edge), static_cast(margin)); +} + +static void jni_YGNodeStyleSetMarginPercentJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge, + jfloat percent) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef); + YGNodeStyleSetMarginPercent( + yogaNodeRef, static_cast(edge), static_cast(percent)); +} + +static void jni_YGNodeStyleSetMarginAutoJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef); + YGNodeStyleSetMarginAuto(yogaNodeRef, static_cast(edge)); +} + +static jlong jni_YGNodeStyleGetPaddingJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::PADDING)) { + return YogaValue::undefinedAsJavaLong(); + } + return YogaValue::asJavaLong( + YGNodeStyleGetPadding(yogaNodeRef, static_cast(edge))); +} + +static void jni_YGNodeStyleSetPaddingJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge, + jfloat padding) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef); + YGNodeStyleSetPadding( + yogaNodeRef, static_cast(edge), static_cast(padding)); +} + +static void jni_YGNodeStyleSetPaddingPercentJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge, + jfloat percent) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef); + YGNodeStyleSetPaddingPercent( + yogaNodeRef, static_cast(edge), static_cast(percent)); +} + +static jfloat jni_YGNodeStyleGetBorderJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::BORDER)) { + return (jfloat) YGUndefined; + } + return (jfloat) YGNodeStyleGetBorder(yogaNodeRef, static_cast(edge)); +} + +static void jni_YGNodeStyleSetBorderJNI( + JNIEnv* env, + jobject obj, + jlong nativePointer, + jint edge, + jfloat border) { + YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer); + YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::BORDER).setOn(yogaNodeRef); + YGNodeStyleSetBorder( + yogaNodeRef, static_cast(edge), static_cast(border)); +} + // Yoga specific properties, not compatible with flexbox specification YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio); @@ -185,6 +327,42 @@ static JNINativeMethod methods[] = { {"jni_YGNodeStyleSetFlexBasisAutoJNI", "(J)V", (void*) jni_YGNodeStyleSetFlexBasisAutoJNI}, + {"jni_YGNodeStyleGetMarginJNI", + "(JI)J", + (void*) jni_YGNodeStyleGetMarginJNI}, + {"jni_YGNodeStyleSetMarginJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetMarginJNI}, + {"jni_YGNodeStyleSetMarginPercentJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetMarginPercentJNI}, + {"jni_YGNodeStyleSetMarginAutoJNI", + "(JI)V", + (void*) jni_YGNodeStyleSetMarginAutoJNI}, + {"jni_YGNodeStyleGetPaddingJNI", + "(JI)J", + (void*) jni_YGNodeStyleGetPaddingJNI}, + {"jni_YGNodeStyleSetPaddingJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetPaddingJNI}, + {"jni_YGNodeStyleSetPaddingPercentJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetPaddingPercentJNI}, + {"jni_YGNodeStyleGetBorderJNI", + "(JI)F", + (void*) jni_YGNodeStyleGetBorderJNI}, + {"jni_YGNodeStyleSetBorderJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetBorderJNI}, + {"jni_YGNodeStyleGetPositionJNI", + "(JI)J", + (void*) jni_YGNodeStyleGetPositionJNI}, + {"jni_YGNodeStyleSetPositionJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetPositionJNI}, + {"jni_YGNodeStyleSetPositionPercentJNI", + "(JIF)V", + (void*) jni_YGNodeStyleSetPositionPercentJNI}, {"jni_YGNodeStyleGetWidthJNI", "(J)J", (void*) jni_YGNodeStyleGetWidthJNI}, {"jni_YGNodeStyleSetWidthJNI", "(JF)V", (void*) jni_YGNodeStyleSetWidthJNI}, {"jni_YGNodeStyleSetWidthPercentJNI",