From 7ea9081ec5c293febb4a11983065f9d923cc739c Mon Sep 17 00:00:00 2001 From: heoblitz Date: Wed, 27 Nov 2024 09:00:24 +0900 Subject: [PATCH 1/2] Update YGNodeStyleGetGap to return YGValue --- capture/NodeToString.cpp | 6 +++--- java/com/facebook/yoga/YogaNative.java | 2 +- java/com/facebook/yoga/YogaNode.java | 2 +- java/com/facebook/yoga/YogaNodeJNIBase.java | 4 ++-- java/jni/YGJNIVanilla.cpp | 6 +++--- javascript/src/Node.cpp | 5 +++-- javascript/src/Node.h | 2 +- yoga/YGNodeStyle.cpp | 9 ++------- yoga/YGNodeStyle.h | 2 +- 9 files changed, 17 insertions(+), 21 deletions(-) diff --git a/capture/NodeToString.cpp b/capture/NodeToString.cpp index 87065277f5..2f4cd32762 100644 --- a/capture/NodeToString.cpp +++ b/capture/NodeToString.cpp @@ -225,17 +225,17 @@ static void serializeTreeImpl( appendEdges<&YGNodeStyleGetPosition>( j, "position", node, defaultNode.get()); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "gap", YGNodeStyleGetGap(node, YGGutterAll), YGNodeStyleGetGap(defaultNode.get(), YGGutterAll)); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "column-gap", YGNodeStyleGetGap(node, YGGutterColumn), YGNodeStyleGetGap(defaultNode.get(), YGGutterColumn)); - appendFloatIfNotDefault( + appendYGValueIfNotDefault( j["style"], "row-gap", YGNodeStyleGetGap(node, YGGutterRow), diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index 89ef5ef16f..97b53faa25 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -109,7 +109,7 @@ public class YogaNative { static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent); static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer); static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio); - static native float jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter); + static native long jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter); static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength); static native void jni_YGNodeStyleSetGapPercentJNI(long nativePointer, int gutter, float gapLength); static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc); diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index ba07684675..09f619e62b 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -194,7 +194,7 @@ public interface Inputs { public abstract void setAspectRatio(float aspectRatio); - public abstract float getGap(YogaGutter gutter); + public abstract YogaValue getGap(YogaGutter gutter); public abstract void setGap(YogaGutter gutter, float gapLength); diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index a53fe74af0..faffae14ca 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -727,8 +727,8 @@ public void markLayoutSeen() { } @Override - public float getGap(YogaGutter gutter) { - return YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue()); + public YogaValue getGap(YogaGutter gutter) { + return valueFromLong(YogaNative.jni_YGNodeStyleGetGapJNI(mNativePointer, gutter.intValue())); } @Override diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 6b8ed14bd6..dc961aa36c 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -703,13 +703,13 @@ jni_YGNodeCloneJNI(JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer) { return reinterpret_cast(clonedYogaNode); } -static jfloat jni_YGNodeStyleGetGapJNI( +static jlong jni_YGNodeStyleGetGapJNI( JNIEnv* /*env*/, jobject /*obj*/, jlong nativePointer, jint gutter) { - return (jfloat)YGNodeStyleGetGap( - _jlong2YGNodeRef(nativePointer), static_cast(gutter)); + return YogaValue::asJavaLong(YGNodeStyleGetGap( + _jlong2YGNodeRef(nativePointer), static_cast(gutter))); } static void jni_YGNodeStyleSetGapJNI( diff --git a/javascript/src/Node.cpp b/javascript/src/Node.cpp index f5c6a86651..05296c5c9c 100644 --- a/javascript/src/Node.cpp +++ b/javascript/src/Node.cpp @@ -355,8 +355,9 @@ Value Node::getPadding(int edge) const { YGNodeStyleGetPadding(m_node, static_cast(edge))); } -float Node::getGap(int gutter) { - return YGNodeStyleGetGap(m_node, static_cast(gutter)); +Value Node::getGap(int gutter) const { + return Value::fromYGValue( + YGNodeStyleGetGap(m_node, static_cast(gutter))); } bool Node::isReferenceBaseline() { diff --git a/javascript/src/Node.h b/javascript/src/Node.h index c30f1d2ded..a08e453c73 100644 --- a/javascript/src/Node.h +++ b/javascript/src/Node.h @@ -165,7 +165,7 @@ class Node { Value getPadding(int edge) const; - float getGap(int gutter); + Value getGap(int gutter) const; int getBoxSizing(void) const; diff --git a/yoga/YGNodeStyle.cpp b/yoga/YGNodeStyle.cpp index 8664b53ec8..546e571d89 100644 --- a/yoga/YGNodeStyle.cpp +++ b/yoga/YGNodeStyle.cpp @@ -278,13 +278,8 @@ void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) { node, scopedEnum(gutter), StyleLength::percent(percent)); } -float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { - auto gapLength = resolveRef(node)->style().gap(scopedEnum(gutter)); - if (gapLength.isUndefined() || gapLength.isAuto()) { - return YGUndefined; - } - - return static_cast(gapLength).value; +YGValue YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { + return (YGValue)resolveRef(node)->style().gap(scopedEnum(gutter)); } void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { diff --git a/yoga/YGNodeStyle.h b/yoga/YGNodeStyle.h index 2746a4a00a..242c5fb088 100644 --- a/yoga/YGNodeStyle.h +++ b/yoga/YGNodeStyle.h @@ -93,7 +93,7 @@ YG_EXPORT void YGNodeStyleSetGap(YGNodeRef node, YGGutter gutter, float gapLength); YG_EXPORT void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float gapLength); -YG_EXPORT float YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); +YG_EXPORT YGValue YGNodeStyleGetGap(YGNodeConstRef node, YGGutter gutter); YG_EXPORT void YGNodeStyleSetBoxSizing(YGNodeRef node, YGBoxSizing boxSizing); YG_EXPORT YGBoxSizing YGNodeStyleGetBoxSizing(YGNodeConstRef node); From 9ae43e00f0107cba743cb8bf487243f5175f713b Mon Sep 17 00:00:00 2001 From: heoblitz Date: Thu, 28 Nov 2024 20:38:31 +0900 Subject: [PATCH 2/2] Fix jni_YGNodeStyleGetGapJNI binding code --- java/jni/YGJNIVanilla.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index dc961aa36c..eb5b2daf19 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -972,7 +972,7 @@ static JNINativeMethod methods[] = { {"jni_YGNodeSetHasMeasureFuncJNI", "(JZ)V", (void*)jni_YGNodeSetHasMeasureFuncJNI}, - {"jni_YGNodeStyleGetGapJNI", "(JI)F", (void*)jni_YGNodeStyleGetGapJNI}, + {"jni_YGNodeStyleGetGapJNI", "(JI)J", (void*)jni_YGNodeStyleGetGapJNI}, {"jni_YGNodeStyleSetGapJNI", "(JIF)V", (void*)jni_YGNodeStyleSetGapJNI}, {"jni_YGNodeStyleSetGapPercentJNI", "(JIF)V",