88#include < yoga/Yoga.h>
99#include < yoga/debug/AssertFatal.h>
1010#include < yoga/node/Node.h>
11+ #include < yoga/style/StyleCalcLength.h>
1112
1213using namespace facebook ;
1314using namespace facebook ::yoga;
1415
1516namespace {
1617
18+ inline StyleCalcLength YGCalcToStyleCalcLength (YGCalc calc) {
19+ return {
20+ FloatOptional{calc.px },
21+ FloatOptional{calc.percent },
22+ FloatOptional{calc.vw },
23+ FloatOptional{calc.vh }};
24+ }
25+
1726template <auto GetterT, auto SetterT, typename ValueT>
1827void updateStyle (YGNodeRef node, ValueT value) {
1928 auto & style = resolveRef (node)->style ();
@@ -207,6 +216,11 @@ void YGNodeStyleSetFlexBasisStretch(const YGNodeRef node) {
207216 node, StyleSizeLength::ofStretch ());
208217}
209218
219+ void YGNodeStyleSetFlexBasisCalc (const YGNodeRef node, const YGCalc calc) {
220+ updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
221+ node, StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
222+ }
223+
210224YGValue YGNodeStyleGetFlexBasis (const YGNodeConstRef node) {
211225 return (YGValue)resolveRef (node)->style ().flexBasis ();
212226}
@@ -226,6 +240,11 @@ void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) {
226240 node, scopedEnum (edge), StyleLength::ofAuto ());
227241}
228242
243+ void YGNodeStyleSetPositionCalc (YGNodeRef node, YGEdge edge, YGCalc calc) {
244+ updateStyle<&Style::position, &Style::setPosition>(
245+ node, scopedEnum (edge), StyleLength::calc (YGCalcToStyleCalcLength (calc)));
246+ }
247+
229248YGValue YGNodeStyleGetPosition (YGNodeConstRef node, YGEdge edge) {
230249 return (YGValue)resolveRef (node)->style ().position (scopedEnum (edge));
231250}
@@ -245,6 +264,11 @@ void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
245264 node, scopedEnum (edge), StyleLength::ofAuto ());
246265}
247266
267+ void YGNodeStyleSetMarginCalc (YGNodeRef node, YGEdge edge, YGCalc calc) {
268+ updateStyle<&Style::margin, &Style::setMargin>(
269+ node, scopedEnum (edge), StyleLength::calc (YGCalcToStyleCalcLength (calc)));
270+ }
271+
248272YGValue YGNodeStyleGetMargin (YGNodeConstRef node, YGEdge edge) {
249273 return (YGValue)resolveRef (node)->style ().margin (scopedEnum (edge));
250274}
@@ -259,6 +283,11 @@ void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
259283 node, scopedEnum (edge), StyleLength::percent (percent));
260284}
261285
286+ void YGNodeStyleSetPaddingCalc (YGNodeRef node, YGEdge edge, YGCalc calc) {
287+ updateStyle<&Style::padding, &Style::setPadding>(
288+ node, scopedEnum (edge), StyleLength::calc (YGCalcToStyleCalcLength (calc)));
289+ }
290+
262291YGValue YGNodeStyleGetPadding (YGNodeConstRef node, YGEdge edge) {
263292 return (YGValue)resolveRef (node)->style ().padding (scopedEnum (edge));
264293}
@@ -271,6 +300,14 @@ void YGNodeStyleSetBorder(
271300 node, scopedEnum (edge), StyleLength::points (border));
272301}
273302
303+ void YGNodeStyleSetBorderCalc (
304+ const YGNodeRef node,
305+ const YGEdge edge,
306+ const YGCalc calc) {
307+ updateStyle<&Style::border, &Style::setBorder>(
308+ node, scopedEnum (edge), StyleLength::calc (YGCalcToStyleCalcLength (calc)));
309+ }
310+
274311float YGNodeStyleGetBorder (const YGNodeConstRef node, const YGEdge edge) {
275312 auto border = resolveRef (node)->style ().border (scopedEnum (edge));
276313 if (border.isUndefined () || border.isAuto ()) {
@@ -293,6 +330,13 @@ void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
293330 node, scopedEnum (gutter), StyleLength::percent (percent));
294331}
295332
333+ void YGNodeStyleSetGapCalc (YGNodeRef node, YGGutter gutter, YGCalc calc) {
334+ updateStyle<&Style::gap, &Style::setGap>(
335+ node,
336+ scopedEnum (gutter),
337+ StyleLength::calc (YGCalcToStyleCalcLength (calc)));
338+ }
339+
296340YGValue YGNodeStyleGetGap (const YGNodeConstRef node, const YGGutter gutter) {
297341 return (YGValue)resolveRef (node)->style ().gap (scopedEnum (gutter));
298342}
@@ -346,6 +390,13 @@ void YGNodeStyleSetWidthStretch(YGNodeRef node) {
346390 node, Dimension::Width, StyleSizeLength::ofStretch ());
347391}
348392
393+ void YGNodeStyleSetWidthCalc (YGNodeRef node, YGCalc calc) {
394+ updateStyle<&Style::dimension, &Style::setDimension>(
395+ node,
396+ Dimension::Width,
397+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
398+ }
399+
349400YGValue YGNodeStyleGetWidth (YGNodeConstRef node) {
350401 return (YGValue)resolveRef (node)->style ().dimension (Dimension::Width);
351402}
@@ -380,6 +431,13 @@ void YGNodeStyleSetHeightStretch(YGNodeRef node) {
380431 node, Dimension::Height, StyleSizeLength::ofStretch ());
381432}
382433
434+ void YGNodeStyleSetHeightCalc (YGNodeRef node, YGCalc calc) {
435+ updateStyle<&Style::dimension, &Style::setDimension>(
436+ node,
437+ Dimension::Height,
438+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
439+ }
440+
383441YGValue YGNodeStyleGetHeight (YGNodeConstRef node) {
384442 return (YGValue)resolveRef (node)->style ().dimension (Dimension::Height);
385443}
@@ -409,6 +467,13 @@ void YGNodeStyleSetMinWidthStretch(const YGNodeRef node) {
409467 node, Dimension::Width, StyleSizeLength::ofStretch ());
410468}
411469
470+ void YGNodeStyleSetMinWidthCalc (const YGNodeRef node, const YGCalc calc) {
471+ updateStyle<&Style::minDimension, &Style::setMinDimension>(
472+ node,
473+ Dimension::Width,
474+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
475+ }
476+
412477YGValue YGNodeStyleGetMinWidth (const YGNodeConstRef node) {
413478 return (YGValue)resolveRef (node)->style ().minDimension (Dimension::Width);
414479}
@@ -440,6 +505,13 @@ void YGNodeStyleSetMinHeightStretch(const YGNodeRef node) {
440505 node, Dimension::Height, StyleSizeLength::ofStretch ());
441506}
442507
508+ void YGNodeStyleSetMinHeightCalc (const YGNodeRef node, const YGCalc calc) {
509+ updateStyle<&Style::minDimension, &Style::setMinDimension>(
510+ node,
511+ Dimension::Height,
512+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
513+ }
514+
443515YGValue YGNodeStyleGetMinHeight (const YGNodeConstRef node) {
444516 return (YGValue)resolveRef (node)->style ().minDimension (Dimension::Height);
445517}
@@ -469,6 +541,13 @@ void YGNodeStyleSetMaxWidthStretch(const YGNodeRef node) {
469541 node, Dimension::Width, StyleSizeLength::ofStretch ());
470542}
471543
544+ void YGNodeStyleSetMaxWidthCalc (const YGNodeRef node, const YGCalc calc) {
545+ updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
546+ node,
547+ Dimension::Width,
548+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
549+ }
550+
472551YGValue YGNodeStyleGetMaxWidth (const YGNodeConstRef node) {
473552 return (YGValue)resolveRef (node)->style ().maxDimension (Dimension::Width);
474553}
@@ -500,6 +579,13 @@ void YGNodeStyleSetMaxHeightStretch(const YGNodeRef node) {
500579 node, Dimension::Height, StyleSizeLength::ofStretch ());
501580}
502581
582+ void YGNodeStyleSetMaxHeightCalc (const YGNodeRef node, const YGCalc calc) {
583+ updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
584+ node,
585+ Dimension::Height,
586+ StyleSizeLength::calc (YGCalcToStyleCalcLength (calc)));
587+ }
588+
503589YGValue YGNodeStyleGetMaxHeight (const YGNodeConstRef node) {
504590 return (YGValue)resolveRef (node)->style ().maxDimension (Dimension::Height);
505591}
0 commit comments