Skip to content

Commit

Permalink
Update public API for intrinsic sizing setters
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#46939

X-link: facebook/yoga#1722

tsia! opted for one function for each keyword just like auto. This is kinda annoying and not the most sustainable, so maybe it makes more sense to make a new enum here and just add one function

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D64002837

fbshipit-source-id: f15fae9fc0103175e1d85850fc9aa68579989fd3
  • Loading branch information
joevilches authored and facebook-github-bot committed Nov 5, 2024
1 parent 935f134 commit e679f09
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 9 deletions.
105 changes: 105 additions & 0 deletions lib/yoga/src/main/cpp/yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
node, StyleSizeLength::ofAuto());
}

void YGNodeStyleSetFlexBasisMaxContent(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetFlexBasisFitContent(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetFlexBasisStretch(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().flexBasis();
}
Expand Down Expand Up @@ -321,6 +336,21 @@ void YGNodeStyleSetWidthAuto(YGNodeRef node) {
node, Dimension::Width, StyleSizeLength::ofAuto());
}

void YGNodeStyleSetWidthMaxContent(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetWidthFitContent(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetWidthStretch(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().dimension(Dimension::Width);
}
Expand All @@ -340,6 +370,21 @@ void YGNodeStyleSetHeightAuto(YGNodeRef node) {
node, Dimension::Height, StyleSizeLength::ofAuto());
}

void YGNodeStyleSetHeightMaxContent(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetHeightFitContent(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetHeightStretch(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().dimension(Dimension::Height);
}
Expand All @@ -354,6 +399,21 @@ void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
node, Dimension::Width, StyleSizeLength::percent(minWidth));
}

void YGNodeStyleSetMinWidthMaxContent(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetMinWidthFitContent(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetMinWidthStretch(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Width);
}
Expand All @@ -370,6 +430,21 @@ void YGNodeStyleSetMinHeightPercent(
node, Dimension::Height, StyleSizeLength::percent(minHeight));
}

void YGNodeStyleSetMinHeightMaxContent(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetMinHeightFitContent(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetMinHeightStretch(const YGNodeRef node) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Height);
}
Expand All @@ -384,6 +459,21 @@ void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
node, Dimension::Width, StyleSizeLength::percent(maxWidth));
}

void YGNodeStyleSetMaxWidthMaxContent(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetMaxWidthFitContent(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetMaxWidthStretch(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Width);
}
Expand All @@ -400,6 +490,21 @@ void YGNodeStyleSetMaxHeightPercent(
node, Dimension::Height, StyleSizeLength::percent(maxHeight));
}

void YGNodeStyleSetMaxHeightMaxContent(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, StyleSizeLength::ofMaxContent());
}

void YGNodeStyleSetMaxHeightFitContent(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, StyleSizeLength::ofFitContent());
}

void YGNodeStyleSetMaxHeightStretch(const YGNodeRef node) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, StyleSizeLength::ofStretch());
}

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Height);
}
21 changes: 21 additions & 0 deletions lib/yoga/src/main/cpp/yoga/YGNodeStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ YG_EXPORT float YGNodeStyleGetFlexShrink(YGNodeConstRef node);
YG_EXPORT void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis);
YG_EXPORT void YGNodeStyleSetFlexBasisPercent(YGNodeRef node, float flexBasis);
YG_EXPORT void YGNodeStyleSetFlexBasisAuto(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetFlexBasisMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetFlexBasisFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetFlexBasisStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetFlexBasis(YGNodeConstRef node);

YG_EXPORT void
Expand Down Expand Up @@ -101,27 +104,45 @@ YG_EXPORT YGBoxSizing YGNodeStyleGetBoxSizing(YGNodeConstRef node);
YG_EXPORT void YGNodeStyleSetWidth(YGNodeRef node, float width);
YG_EXPORT void YGNodeStyleSetWidthPercent(YGNodeRef node, float width);
YG_EXPORT void YGNodeStyleSetWidthAuto(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetWidthMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetWidthFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetWidthStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetWidth(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetHeight(YGNodeRef node, float height);
YG_EXPORT void YGNodeStyleSetHeightPercent(YGNodeRef node, float height);
YG_EXPORT void YGNodeStyleSetHeightAuto(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetHeightMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetHeightFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetHeightStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetHeight(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth);
YG_EXPORT void YGNodeStyleSetMinWidthPercent(YGNodeRef node, float minWidth);
YG_EXPORT void YGNodeStyleSetMinWidthMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMinWidthFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMinWidthStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetMinWidth(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight);
YG_EXPORT void YGNodeStyleSetMinHeightPercent(YGNodeRef node, float minHeight);
YG_EXPORT void YGNodeStyleSetMinHeightMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMinHeightFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMinHeightStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetMinHeight(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth);
YG_EXPORT void YGNodeStyleSetMaxWidthPercent(YGNodeRef node, float maxWidth);
YG_EXPORT void YGNodeStyleSetMaxWidthMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMaxWidthFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMaxWidthStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetMaxWidth(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight);
YG_EXPORT void YGNodeStyleSetMaxHeightPercent(YGNodeRef node, float maxHeight);
YG_EXPORT void YGNodeStyleSetMaxHeightMaxContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMaxHeightFitContent(YGNodeRef node);
YG_EXPORT void YGNodeStyleSetMaxHeightStretch(YGNodeRef node);
YG_EXPORT YGValue YGNodeStyleGetMaxHeight(YGNodeConstRef node);

YG_EXPORT void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
Expand Down
21 changes: 21 additions & 0 deletions lib/yoga/src/main/java/com/facebook/yoga/YogaNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ 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 void jni_YGNodeStyleSetFlexBasisMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetFlexBasisFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetFlexBasisStretchJNI(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);
Expand All @@ -91,22 +94,40 @@ public class YogaNative {
static native void jni_YGNodeStyleSetWidthJNI(long nativePointer, float width);
static native void jni_YGNodeStyleSetWidthPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetWidthAutoJNI(long nativePointer);
static native void jni_YGNodeStyleSetWidthMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetWidthFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetWidthStretchJNI(long nativePointer);
static native long jni_YGNodeStyleGetHeightJNI(long nativePointer);
static native void jni_YGNodeStyleSetHeightJNI(long nativePointer, float height);
static native void jni_YGNodeStyleSetHeightPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetHeightAutoJNI(long nativePointer);
static native void jni_YGNodeStyleSetHeightMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetHeightFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetHeightStretchJNI(long nativePointer);
static native long jni_YGNodeStyleGetMinWidthJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinWidthJNI(long nativePointer, float minWidth);
static native void jni_YGNodeStyleSetMinWidthPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetMinWidthMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinWidthFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinWidthStretchJNI(long nativePointer);
static native long jni_YGNodeStyleGetMinHeightJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinHeightJNI(long nativePointer, float minHeight);
static native void jni_YGNodeStyleSetMinHeightPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetMinHeightMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinHeightFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMinHeightStretchJNI(long nativePointer);
static native long jni_YGNodeStyleGetMaxWidthJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxWidthJNI(long nativePointer, float maxWidth);
static native void jni_YGNodeStyleSetMaxWidthPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetMaxWidthMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxWidthFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxWidthStretchJNI(long nativePointer);
static native long jni_YGNodeStyleGetMaxHeightJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxHeightJNI(long nativePointer, float maxheight);
static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent);
static native void jni_YGNodeStyleSetMaxHeightMaxContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxHeightFitContentJNI(long nativePointer);
static native void jni_YGNodeStyleSetMaxHeightStretchJNI(long nativePointer);
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);
Expand Down
42 changes: 42 additions & 0 deletions lib/yoga/src/main/java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ public interface Inputs {

public abstract void setFlexBasisAuto();

public abstract void setFlexBasisMaxContent();

public abstract void setFlexBasisFitContent();

public abstract void setFlexBasisStretch();

public abstract YogaValue getMargin(YogaEdge edge);

public abstract void setMargin(YogaEdge edge, float margin);
Expand Down Expand Up @@ -158,6 +164,12 @@ public interface Inputs {

public abstract void setWidthAuto();

public abstract void setWidthMaxContent();

public abstract void setWidthFitContent();

public abstract void setWidthStretch();

public abstract YogaValue getHeight();

public abstract void setHeight(float height);
Expand All @@ -166,30 +178,60 @@ public interface Inputs {

public abstract void setHeightAuto();

public abstract void setHeightMaxContent();

public abstract void setHeightFitContent();

public abstract void setHeightStretch();

public abstract YogaValue getMinWidth();

public abstract void setMinWidth(float minWidth);

public abstract void setMinWidthPercent(float percent);

public abstract void setMinWidthMaxContent();

public abstract void setMinWidthFitContent();

public abstract void setMinWidthStretch();

public abstract YogaValue getMinHeight();

public abstract void setMinHeight(float minHeight);

public abstract void setMinHeightPercent(float percent);

public abstract void setMinHeightMaxContent();

public abstract void setMinHeightFitContent();

public abstract void setMinHeightStretch();

public abstract YogaValue getMaxWidth();

public abstract void setMaxWidth(float maxWidth);

public abstract void setMaxWidthPercent(float percent);

public abstract void setMaxWidthMaxContent();

public abstract void setMaxWidthFitContent();

public abstract void setMaxWidthStretch();

public abstract YogaValue getMaxHeight();

public abstract void setMaxHeight(float maxheight);

public abstract void setMaxHeightPercent(float percent);

public abstract void setMaxHeightMaxContent();

public abstract void setMaxHeightFitContent();

public abstract void setMaxHeightStretch();

public abstract float getAspectRatio();

public abstract void setAspectRatio(float aspectRatio);
Expand Down
Loading

0 comments on commit e679f09

Please sign in to comment.