Skip to content

Commit

Permalink
Add layout margin functions to the java interface
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Jan 12, 2017
1 parent 3d82659 commit e398e9e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public static boolean isExperimentalFeatureEnabled(YogaExperimentalFeature featu
@DoNotStrip
private float mLeft = YogaConstants.UNDEFINED;
@DoNotStrip
private float mMarginLeft = 0;
@DoNotStrip
private float mMarginTop = 0;
@DoNotStrip
private float mMarginRight = 0;
@DoNotStrip
private float mMarginBottom = 0;
@DoNotStrip
private float mPaddingLeft = 0;
@DoNotStrip
private float mPaddingTop = 0;
Expand Down Expand Up @@ -573,6 +581,26 @@ public float getLayoutHeight() {
return mHeight;
}

@Override
public float getLayoutMargin(YogaEdge edge) {
switch (edge) {
case LEFT:
return mMarginLeft;
case TOP:
return mMarginTop;
case RIGHT:
return mMarginRight;
case BOTTOM:
return mMarginBottom;
case START:
return getLayoutDirection() == YogaDirection.RTL ? mMarginRight : mMarginLeft;
case END:
return getLayoutDirection() == YogaDirection.RTL ? mMarginLeft : mMarginRight;
default:
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
}
}

@Override
public float getLayoutPadding(YogaEdge edge) {
switch (edge) {
Expand Down
1 change: 1 addition & 0 deletions java/com/facebook/yoga/YogaNodeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
float getLayoutY();
float getLayoutWidth();
float getLayoutHeight();
float getLayoutMargin(YogaEdge edge);
float getLayoutPadding(YogaEdge edge);
YogaDirection getLayoutDirection();
YogaOverflow getOverflow();
Expand Down
10 changes: 10 additions & 0 deletions java/jni/YGJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
static auto topField = obj->getClass()->getField<jfloat>("mTop");

static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");

static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
Expand All @@ -40,6 +45,11 @@ static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));

obj->setFieldValue(marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue(marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue(marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));

obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
Expand Down

0 comments on commit e398e9e

Please sign in to comment.