Skip to content

Commit db9abd4

Browse files
committed
feat: calc layout calculations
1 parent 0a2398d commit db9abd4

21 files changed

Lines changed: 633 additions & 208 deletions

enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"MaxContent",
1717
"FitContent",
1818
"Stretch",
19+
"Dynamic",
1920
],
2021
"FlexDirection": ["Column", "ColumnReverse", "Row", "RowReverse"],
2122
"Justify": [

java/com/facebook/yoga/YogaUnit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public enum YogaUnit {
1616
AUTO(3),
1717
MAX_CONTENT(4),
1818
FIT_CONTENT(5),
19-
STRETCH(6);
19+
STRETCH(6),
20+
DYNAMIC(7);
2021

2122
private final int mIntValue;
2223

@@ -37,6 +38,7 @@ public static YogaUnit fromInt(int value) {
3738
case 4: return MAX_CONTENT;
3839
case 5: return FIT_CONTENT;
3940
case 6: return STRETCH;
41+
case 7: return DYNAMIC;
4042
default: throw new IllegalArgumentException("Unknown enum value: " + value);
4143
}
4244
}

javascript/src/generated/YGEnums.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export enum Unit {
144144
MaxContent = 4,
145145
FitContent = 5,
146146
Stretch = 6,
147+
Dynamic = 7,
147148
}
148149

149150
export enum Wrap {
@@ -238,6 +239,7 @@ const constants = {
238239
UNIT_MAX_CONTENT: Unit.MaxContent,
239240
UNIT_FIT_CONTENT: Unit.FitContent,
240241
UNIT_STRETCH: Unit.Stretch,
242+
UNIT_DYNAMIC: Unit.Dynamic,
241243
WRAP_NO_WRAP: Wrap.NoWrap,
242244
WRAP_WRAP: Wrap.Wrap,
243245
WRAP_WRAP_REVERSE: Wrap.WrapReverse,

tests/StyleTest.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,31 @@ TEST(Style, computed_padding_is_floored) {
1414
yoga::Style style;
1515
style.setPadding(Edge::All, StyleLength::points(-1.0f));
1616
auto paddingStart = style.computeInlineStartPadding(
17-
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
17+
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/, nullptr);
1818
ASSERT_EQ(paddingStart, 0.0f);
1919
}
2020

2121
TEST(Style, computed_border_is_floored) {
2222
yoga::Style style;
2323
style.setBorder(Edge::All, StyleLength::points(-1.0f));
24-
auto borderStart =
25-
style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR);
24+
auto borderStart = style.computeInlineStartBorder(
25+
FlexDirection::Row, Direction::LTR, nullptr);
2626
ASSERT_EQ(borderStart, 0.0f);
2727
}
2828

2929
TEST(Style, computed_gap_is_floored) {
3030
yoga::Style style;
3131
style.setGap(Gutter::Column, StyleLength::points(-1.0f));
32-
auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0);
32+
auto gapBetweenColumns =
33+
style.computeGapForAxis(FlexDirection::Row, 0.0, nullptr);
3334
ASSERT_EQ(gapBetweenColumns, 0.0f);
3435
}
3536

3637
TEST(Style, computed_margin_is_not_floored) {
3738
yoga::Style style;
3839
style.setMargin(Edge::All, StyleLength::points(-1.0f));
3940
auto marginStart = style.computeInlineStartMargin(
40-
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
41+
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/, nullptr);
4142
ASSERT_EQ(marginStart, -1.0f);
4243
}
4344

yoga/YGEnums.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ const char* YGUnitToString(const YGUnit value) {
283283
return "fit-content";
284284
case YGUnitStretch:
285285
return "stretch";
286+
case YGUnitDynamic:
287+
return "dynamic";
286288
}
287289
return "unknown";
288290
}

yoga/YGEnums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ YG_ENUM_DECL(
150150
YGUnitAuto,
151151
YGUnitMaxContent,
152152
YGUnitFitContent,
153-
YGUnitStretch)
153+
YGUnitStretch,
154+
YGUnitDynamic)
154155

155156
YG_ENUM_DECL(
156157
YGWrap,

yoga/YGNodeStyle.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ void YGNodeStyleSetFlexBasisStretch(const YGNodeRef node) {
226226
node, StyleSizeLength::ofStretch());
227227
}
228228

229+
void YGNodeStyleSetFlexBasisDynamic(
230+
const YGNodeRef node,
231+
YGValueDynamic callback,
232+
YGValueDynamicID id) {
233+
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
234+
node, StyleSizeLength::dynamic(callback, id));
235+
}
236+
229237
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
230238
return (YGValue)resolveRef(node)->style().flexBasis();
231239
}
@@ -249,6 +257,15 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
249257
return (YGValue)resolveRef(node)->style().position(scopedEnum(edge));
250258
}
251259

260+
void YGNodeStyleSetPositionDynamic(
261+
YGNodeRef node,
262+
YGEdge edge,
263+
YGValueDynamic callback,
264+
YGValueDynamicID id) {
265+
updateStyle<&Style::position, &Style::setPosition>(
266+
node, scopedEnum(edge), StyleLength::dynamic(callback, id));
267+
}
268+
252269
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
253270
updateStyle<&Style::margin, &Style::setMargin>(
254271
node, scopedEnum(edge), StyleLength::points(points));
@@ -268,6 +285,15 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
268285
return (YGValue)resolveRef(node)->style().margin(scopedEnum(edge));
269286
}
270287

288+
void YGNodeStyleSetMarginDynamic(
289+
YGNodeRef node,
290+
YGEdge edge,
291+
YGValueDynamic callback,
292+
YGValueDynamicID id) {
293+
updateStyle<&Style::margin, &Style::setMargin>(
294+
node, scopedEnum(edge), StyleLength::dynamic(callback, id));
295+
}
296+
271297
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
272298
updateStyle<&Style::padding, &Style::setPadding>(
273299
node, scopedEnum(edge), StyleLength::points(points));
@@ -282,6 +308,15 @@ YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
282308
return (YGValue)resolveRef(node)->style().padding(scopedEnum(edge));
283309
}
284310

311+
void YGNodeStyleSetPaddingDynamic(
312+
YGNodeRef node,
313+
YGEdge edge,
314+
YGValueDynamic callback,
315+
YGValueDynamicID id) {
316+
updateStyle<&Style::padding, &Style::setPadding>(
317+
node, scopedEnum(edge), StyleLength::dynamic(callback, id));
318+
}
319+
285320
void YGNodeStyleSetBorder(
286321
const YGNodeRef node,
287322
const YGEdge edge,
@@ -299,6 +334,15 @@ float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
299334
return static_cast<YGValue>(border).value;
300335
}
301336

337+
void YGNodeStyleSetBorderDynamic(
338+
YGNodeRef node,
339+
YGEdge edge,
340+
YGValueDynamic callback,
341+
YGValueDynamicID id) {
342+
updateStyle<&Style::border, &Style::setBorder>(
343+
node, scopedEnum(edge), StyleLength::dynamic(callback, id));
344+
}
345+
302346
void YGNodeStyleSetGap(
303347
const YGNodeRef node,
304348
const YGGutter gutter,
@@ -312,6 +356,15 @@ void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
312356
node, scopedEnum(gutter), StyleLength::percent(percent));
313357
}
314358

359+
void YGNodeStyleSetGapDynamic(
360+
YGNodeRef node,
361+
YGGutter gutter,
362+
YGValueDynamic callback,
363+
YGValueDynamicID id) {
364+
updateStyle<&Style::gap, &Style::setGap>(
365+
node, scopedEnum(gutter), StyleLength::dynamic(callback, id));
366+
}
367+
315368
YGValue YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
316369
return (YGValue)resolveRef(node)->style().gap(scopedEnum(gutter));
317370
}
@@ -365,6 +418,14 @@ void YGNodeStyleSetWidthStretch(YGNodeRef node) {
365418
node, Dimension::Width, StyleSizeLength::ofStretch());
366419
}
367420

421+
void YGNodeStyleSetWidthDynamic(
422+
YGNodeRef node,
423+
YGValueDynamic callback,
424+
YGValueDynamicID id) {
425+
updateStyle<&Style::dimension, &Style::setDimension>(
426+
node, Dimension::Width, StyleSizeLength::dynamic(callback, id));
427+
}
428+
368429
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
369430
return (YGValue)resolveRef(node)->style().dimension(Dimension::Width);
370431
}
@@ -399,6 +460,14 @@ void YGNodeStyleSetHeightStretch(YGNodeRef node) {
399460
node, Dimension::Height, StyleSizeLength::ofStretch());
400461
}
401462

463+
void YGNodeStyleSetHeightDynamic(
464+
YGNodeRef node,
465+
YGValueDynamic callback,
466+
YGValueDynamicID id) {
467+
updateStyle<&Style::dimension, &Style::setDimension>(
468+
node, Dimension::Height, StyleSizeLength::dynamic(callback, id));
469+
}
470+
402471
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
403472
return (YGValue)resolveRef(node)->style().dimension(Dimension::Height);
404473
}
@@ -428,6 +497,14 @@ void YGNodeStyleSetMinWidthStretch(const YGNodeRef node) {
428497
node, Dimension::Width, StyleSizeLength::ofStretch());
429498
}
430499

500+
void YGNodeStyleSetMinWidthDynamic(
501+
const YGNodeRef node,
502+
YGValueDynamic callback,
503+
YGValueDynamicID id) {
504+
updateStyle<&Style::minDimension, &Style::setMinDimension>(
505+
node, Dimension::Width, StyleSizeLength::dynamic(callback, id));
506+
}
507+
431508
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
432509
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Width);
433510
}
@@ -459,6 +536,14 @@ void YGNodeStyleSetMinHeightStretch(const YGNodeRef node) {
459536
node, Dimension::Height, StyleSizeLength::ofStretch());
460537
}
461538

539+
void YGNodeStyleSetMinHeightDynamic(
540+
const YGNodeRef node,
541+
YGValueDynamic callback,
542+
YGValueDynamicID id) {
543+
updateStyle<&Style::minDimension, &Style::setMinDimension>(
544+
node, Dimension::Height, StyleSizeLength::dynamic(callback, id));
545+
}
546+
462547
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
463548
return (YGValue)resolveRef(node)->style().minDimension(Dimension::Height);
464549
}
@@ -488,6 +573,14 @@ void YGNodeStyleSetMaxWidthStretch(const YGNodeRef node) {
488573
node, Dimension::Width, StyleSizeLength::ofStretch());
489574
}
490575

576+
void YGNodeStyleSetMaxWidthDynamic(
577+
const YGNodeRef node,
578+
YGValueDynamic callback,
579+
YGValueDynamicID id) {
580+
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
581+
node, Dimension::Width, StyleSizeLength::dynamic(callback, id));
582+
}
583+
491584
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
492585
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Width);
493586
}
@@ -519,6 +612,14 @@ void YGNodeStyleSetMaxHeightStretch(const YGNodeRef node) {
519612
node, Dimension::Height, StyleSizeLength::ofStretch());
520613
}
521614

615+
void YGNodeStyleSetMaxHeightDynamic(
616+
const YGNodeRef node,
617+
YGValueDynamic callback,
618+
YGValueDynamicID id) {
619+
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
620+
node, Dimension::Height, StyleSizeLength::dynamic(callback, id));
621+
}
622+
522623
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
523624
return (YGValue)resolveRef(node)->style().maxDimension(Dimension::Height);
524625
}

0 commit comments

Comments
 (0)