Sunset the value namespace #1720

Closed
joevilches wants to merge 3 commits from export-D63922280 into main
16 changed files with 1164 additions and 179 deletions

View File

@@ -0,0 +1,25 @@
<div id="auto_width" style="width: auto; height: 50px; flex-direction: row;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_height" style="width: 50px; height: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_flex_basis" style="width: 50px; flex-basis: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_position" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; right: auto"></div>
</div>
<div id="auto_margin" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; margin-left: auto"></div>
</div>

View File

@@ -12,7 +12,7 @@ function toValueCpp(value) {
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : ''); return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
} }
function toFunctionName(value) { function toFunctionNameCpp(value) {
if (value.indexOf('%') >= 0) { if (value.indexOf('%') >= 0) {
return 'Percent'; return 'Percent';
} else if (value.indexOf('Auto') >= 0) { } else if (value.indexOf('Auto') >= 0) {
@@ -21,6 +21,23 @@ function toFunctionName(value) {
return ''; return '';
} }
function keywordFunctionCpp(functionPrefix, nodeName, value) {
const functionSuffix = toFunctionNameCpp(value);
if (functionSuffix == 'Auto') {
return functionPrefix + functionSuffix + '(' + nodeName + ');';
} else {
return (
functionPrefix +
functionSuffix +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');'
);
}
}
const CPPEmitter = function () { const CPPEmitter = function () {
Emitter.call(this, 'cpp', ' '); Emitter.call(this, 'cpp', ' ');
}; };
@@ -231,7 +248,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
'YGNodeStyleSetAspectRatio' + 'YGNodeStyleSetAspectRatio' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -273,15 +290,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
YGNodeStyleSetFlexBasis: { YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(keywordFunctionCpp('YGNodeStyleSetFlexBasis', nodeName, value));
'YGNodeStyleSetFlexBasis' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
}, },
}, },
@@ -325,20 +334,6 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetJustifyContent: { YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
@@ -361,7 +356,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
} }
this.push( this.push(
'YGNodeStyleSetMargin' + 'YGNodeStyleSetMargin' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -372,11 +367,23 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetHeight', nodeName, value));
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetWidth', nodeName, value));
},
},
YGNodeStyleSetMaxHeight: { YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
'YGNodeStyleSetMaxHeight' + 'YGNodeStyleSetMaxHeight' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -390,7 +397,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
'YGNodeStyleSetMaxWidth' + 'YGNodeStyleSetMaxWidth' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -404,7 +411,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
'YGNodeStyleSetMinHeight' + 'YGNodeStyleSetMinHeight' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -418,7 +425,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
'YGNodeStyleSetMinWidth' + 'YGNodeStyleSetMinWidth' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -440,7 +447,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, edge, value) { value: function (nodeName, edge, value) {
this.push( this.push(
'YGNodeStyleSetPadding' + 'YGNodeStyleSetPadding' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -462,7 +469,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
} }
this.push( this.push(
'YGNodeStyleSetPosition' + 'YGNodeStyleSetPosition' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +
@@ -485,25 +492,11 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetGap: { YGNodeStyleSetGap: {
value: function (nodeName, gap, value) { value: function (nodeName, gap, value) {
this.push( this.push(
'YGNodeStyleSetGap' + 'YGNodeStyleSetGap' +
toFunctionName(value) + toFunctionNameCpp(value) +
'(' + '(' +
nodeName + nodeName +
', ' + ', ' +

View File

@@ -100,15 +100,21 @@ for (const fileName of fixtures) {
await driver.get('file://' + process.cwd() + '/test.html'); await driver.get('file://' + process.cwd() + '/test.html');
const logs = await driver.manage().logs().get(logging.Type.BROWSER); const logs = await driver.manage().logs().get(logging.Type.BROWSER);
const testLogs = logs.filter(
log => !log.message.replace(/^[^"]*/, '').startsWith('"gentest-log:'),
);
await fs.writeFile( await fs.writeFile(
`${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`, `${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`,
addSignatureToSourceCode(JSON.parse(logs[0].message.replace(/^[^"]*/, ''))), addSignatureToSourceCode(
JSON.parse(testLogs[0].message.replace(/^[^"]*/, '')),
),
); );
await fs.writeFile( await fs.writeFile(
`${yogaDir}/java/tests/generated/com/facebook/yoga/${fileNameNoExtension}.java`, `${yogaDir}/java/tests/generated/com/facebook/yoga/${fileNameNoExtension}.java`,
addSignatureToSourceCode( addSignatureToSourceCode(
JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace( JSON.parse(testLogs[1].message.replace(/^[^"]*/, '')).replace(
'YogaTest', 'YogaTest',
fileNameNoExtension, fileNameNoExtension,
), ),
@@ -118,7 +124,7 @@ for (const fileName of fixtures) {
await fs.writeFile( await fs.writeFile(
`${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`, `${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`,
addSignatureToSourceCode( addSignatureToSourceCode(
JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace( JSON.parse(testLogs[2].message.replace(/^[^"]*/, '')).replace(
'YogaTest', 'YogaTest',
fileNameNoExtension, fileNameNoExtension,
), ),

View File

@@ -21,6 +21,23 @@ function toMethodName(value) {
return ''; return '';
} }
function keywordMethod(methodPrefix, nodeName, value) {
const methodSuffix = toMethodName(value);
if (methodSuffix == 'Auto') {
return nodeName + '.' + methodPrefix + methodSuffix + '();';
} else {
return (
nodeName +
'.' +
methodPrefix +
methodSuffix +
'(' +
toValueJava(value) +
'f);'
);
}
}
const JavaEmitter = function () { const JavaEmitter = function () {
Emitter.call(this, 'java', ' '); Emitter.call(this, 'java', ' ');
}; };
@@ -273,14 +290,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
YGNodeStyleSetFlexBasis: { YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(keywordMethod('setFlexBasis', nodeName, value));
nodeName +
'.setFlexBasis' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
}, },
}, },
@@ -308,19 +318,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setHeight' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},
YGNodeStyleSetJustifyContent: { YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push(nodeName + '.setJustifyContent(' + toValueJava(value) + ');'); this.push(nodeName + '.setJustifyContent(' + toValueJava(value) + ');');
@@ -348,6 +345,18 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordMethod('setHeight', nodeName, value));
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordMethod('setWidth', nodeName, value));
},
},
YGNodeStyleSetMaxHeight: { YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) { value: function (nodeName, value) {
this.push( this.push(
@@ -448,19 +457,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
}, },
}, },
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setWidth' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},
YGNodeStyleSetGap: { YGNodeStyleSetGap: {
value: function (nodeName, gap, value) { value: function (nodeName, gap, value) {
this.push( this.push(

11
gentest/gentest-log.js Normal file
View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// eslint-disable-next-line no-unused-vars
function gentestLog(message) {
console.log('gentest-log: ', message);
}

View File

@@ -8,6 +8,7 @@
<script src="gentest-cpp.js"></script> <script src="gentest-cpp.js"></script>
<script src="gentest-java.js"></script> <script src="gentest-java.js"></script>
<script src="gentest-javascript.js"></script> <script src="gentest-javascript.js"></script>
<script src="gentest-log.js"></script>
<style> <style>
@font-face { @font-face {

View File

@@ -0,0 +1,325 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<30103b31d09984d8443cf1ba544adeb7>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
*/
package com.facebook.yoga;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.facebook.yoga.utils.TestUtils;
@RunWith(Parameterized.class)
public class YGAutoTest {
@Parameterized.Parameters(name = "{0}")
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
return TestParametrization.nodeFactories();
}
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
@Test
public void test_auto_width() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidthAuto();
root.setHeight(50f);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(50f);
root_child0.setHeight(50f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(50f);
root_child1.setHeight(50f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(50f);
root_child2.setHeight(50f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(150f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(100f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(150f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_auto_height() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(50f);
root.setHeightAuto();
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(50f);
root_child0.setHeight(50f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(50f);
root_child1.setHeight(50f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(50f);
root_child2.setHeight(50f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(150f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(150f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_auto_flex_basis() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(50f);
final YogaNode root_child0 = createNode(config);
root_child0.setWidth(50f);
root_child0.setHeight(50f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = createNode(config);
root_child1.setWidth(50f);
root_child1.setHeight(50f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = createNode(config);
root_child2.setWidth(50f);
root_child2.setHeight(50f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(150f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(150f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_auto_position() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(50f);
root.setHeight(50f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionAuto(YogaEdge.RIGHT);
root_child0.setWidth(25f);
root_child0.setHeight(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_auto_margin() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(50f);
root.setHeight(50f);
final YogaNode root_child0 = createNode(config);
root_child0.setMarginAuto(YogaEdge.LEFT);
root_child0.setWidth(25f);
root_child0.setHeight(25f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(50f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}
}

View File

@@ -0,0 +1,347 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<234cdb7f76ac586e034a5b6ca2033fa4>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,
BoxSizing,
Direction,
Display,
Edge,
Errata,
ExperimentalFeature,
FlexDirection,
Gutter,
Justify,
MeasureMode,
Overflow,
PositionType,
Unit,
Wrap,
} from 'yoga-layout';
test('auto_width', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setFlexDirection(FlexDirection.Row);
root.setPositionType(PositionType.Absolute);
root.setWidth('auto');
root.setHeight(50);
const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(50);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create(config);
root_child1.setWidth(50);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
const root_child2 = Yoga.Node.create(config);
root_child2.setWidth(50);
root_child2.setHeight(50);
root.insertChild(root_child2, 2);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(150);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(50);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(100);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(150);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(100);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(50);
expect(root_child1.getComputedTop()).toBe(0);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(0);
expect(root_child2.getComputedTop()).toBe(0);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('auto_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(50);
root.setHeight('auto');
const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(50);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create(config);
root_child1.setWidth(50);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
const root_child2 = Yoga.Node.create(config);
root_child2.setWidth(50);
root_child2.setHeight(50);
root.insertChild(root_child2, 2);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(0);
expect(root_child1.getComputedTop()).toBe(50);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(0);
expect(root_child2.getComputedTop()).toBe(100);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(0);
expect(root_child1.getComputedTop()).toBe(50);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(0);
expect(root_child2.getComputedTop()).toBe(100);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('auto_flex_basis', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(50);
const root_child0 = Yoga.Node.create(config);
root_child0.setWidth(50);
root_child0.setHeight(50);
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create(config);
root_child1.setWidth(50);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
const root_child2 = Yoga.Node.create(config);
root_child2.setWidth(50);
root_child2.setHeight(50);
root.insertChild(root_child2, 2);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(0);
expect(root_child1.getComputedTop()).toBe(50);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(0);
expect(root_child2.getComputedTop()).toBe(100);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(150);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(50);
expect(root_child1.getComputedLeft()).toBe(0);
expect(root_child1.getComputedTop()).toBe(50);
expect(root_child1.getComputedWidth()).toBe(50);
expect(root_child1.getComputedHeight()).toBe(50);
expect(root_child2.getComputedLeft()).toBe(0);
expect(root_child2.getComputedTop()).toBe(100);
expect(root_child2.getComputedWidth()).toBe(50);
expect(root_child2.getComputedHeight()).toBe(50);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('auto_position', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(50);
root.setHeight(50);
const root_child0 = Yoga.Node.create(config);
root_child0.setPositionAuto(Edge.Right);
root_child0.setWidth(25);
root_child0.setHeight(25);
root.insertChild(root_child0, 0);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(25);
expect(root_child0.getComputedHeight()).toBe(25);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(25);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(25);
expect(root_child0.getComputedHeight()).toBe(25);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('auto_margin', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(50);
root.setHeight(50);
const root_child0 = Yoga.Node.create(config);
root_child0.setMargin(Edge.Left, 'auto');
root_child0.setWidth(25);
root_child0.setHeight(25);
root.insertChild(root_child0, 0);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(25);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(25);
expect(root_child0.getComputedHeight()).toBe(25);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(50);
expect(root.getComputedHeight()).toBe(50);
expect(root_child0.getComputedLeft()).toBe(25);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(25);
expect(root_child0.getComputedHeight()).toBe(25);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -12,7 +12,7 @@ namespace facebook::yoga {
TEST(Style, computed_padding_is_floored) { TEST(Style, computed_padding_is_floored) {
yoga::Style style; yoga::Style style;
style.setPadding(Edge::All, value::points(-1.0f)); style.setPadding(Edge::All, StyleLength::points(-1.0f));
auto paddingStart = style.computeInlineStartPadding( auto paddingStart = style.computeInlineStartPadding(
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
ASSERT_EQ(paddingStart, 0.0f); ASSERT_EQ(paddingStart, 0.0f);
@@ -20,7 +20,7 @@ TEST(Style, computed_padding_is_floored) {
TEST(Style, computed_border_is_floored) { TEST(Style, computed_border_is_floored) {
yoga::Style style; yoga::Style style;
style.setBorder(Edge::All, value::points(-1.0f)); style.setBorder(Edge::All, StyleLength::points(-1.0f));
auto borderStart = auto borderStart =
style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR); style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR);
ASSERT_EQ(borderStart, 0.0f); ASSERT_EQ(borderStart, 0.0f);
@@ -28,14 +28,14 @@ TEST(Style, computed_border_is_floored) {
TEST(Style, computed_gap_is_floored) { TEST(Style, computed_gap_is_floored) {
yoga::Style style; yoga::Style style;
style.setGap(Gutter::Column, value::points(-1.0f)); style.setGap(Gutter::Column, StyleLength::points(-1.0f));
auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0); auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0);
ASSERT_EQ(gapBetweenColumns, 0.0f); ASSERT_EQ(gapBetweenColumns, 0.0f);
} }
TEST(Style, computed_margin_is_not_floored) { TEST(Style, computed_margin_is_not_floored) {
yoga::Style style; yoga::Style style;
style.setMargin(Edge::All, value::points(-1.0f)); style.setMargin(Edge::All, StyleLength::points(-1.0f));
auto marginStart = style.computeInlineStartMargin( auto marginStart = style.computeInlineStartMargin(
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/); FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
ASSERT_EQ(marginStart, -1.0f); ASSERT_EQ(marginStart, -1.0f);

View File

@@ -16,7 +16,7 @@ TEST(StyleValuePool, undefined_at_init) {
EXPECT_TRUE(handle.isUndefined()); EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined()); EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined()); EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
EXPECT_EQ(pool.getNumber(handle), FloatOptional{}); EXPECT_EQ(pool.getNumber(handle), FloatOptional{});
} }
@@ -25,63 +25,63 @@ TEST(StyleValuePool, auto_at_init) {
auto handle = StyleValueHandle::ofAuto(); auto handle = StyleValueHandle::ofAuto();
EXPECT_TRUE(handle.isAuto()); EXPECT_TRUE(handle.isAuto());
EXPECT_EQ(pool.getLength(handle), value::ofAuto()); EXPECT_EQ(pool.getLength(handle), StyleLength::ofAuto());
} }
TEST(StyleValuePool, store_small_int_points) { TEST(StyleValuePool, store_small_int_points) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::points(10)); pool.store(handle, StyleLength::points(10));
EXPECT_EQ(pool.getLength(handle), value::points(10)); EXPECT_EQ(pool.getLength(handle), StyleLength::points(10));
} }
TEST(StyleValuePool, store_small_negative_int_points) { TEST(StyleValuePool, store_small_negative_int_points) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::points(-10)); pool.store(handle, StyleLength::points(-10));
EXPECT_EQ(pool.getLength(handle), value::points(-10)); EXPECT_EQ(pool.getLength(handle), StyleLength::points(-10));
} }
TEST(StyleValuePool, store_small_int_percent) { TEST(StyleValuePool, store_small_int_percent) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::percent(10)); pool.store(handle, StyleLength::percent(10));
EXPECT_EQ(pool.getLength(handle), value::percent(10)); EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
} }
TEST(StyleValuePool, store_large_int_percent) { TEST(StyleValuePool, store_large_int_percent) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::percent(262144)); pool.store(handle, StyleLength::percent(262144));
EXPECT_EQ(pool.getLength(handle), value::percent(262144)); EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
} }
TEST(StyleValuePool, store_large_int_after_small_int) { TEST(StyleValuePool, store_large_int_after_small_int) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::percent(10)); pool.store(handle, StyleLength::percent(10));
pool.store(handle, value::percent(262144)); pool.store(handle, StyleLength::percent(262144));
EXPECT_EQ(pool.getLength(handle), value::percent(262144)); EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
} }
TEST(StyleValuePool, store_small_int_after_large_int) { TEST(StyleValuePool, store_small_int_after_large_int) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::percent(262144)); pool.store(handle, StyleLength::percent(262144));
pool.store(handle, value::percent(10)); pool.store(handle, StyleLength::percent(10));
EXPECT_EQ(pool.getLength(handle), value::percent(10)); EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
} }
TEST(StyleValuePool, store_small_int_number) { TEST(StyleValuePool, store_small_int_number) {
@@ -97,35 +97,35 @@ TEST(StyleValuePool, store_undefined) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::undefined()); pool.store(handle, StyleLength::undefined());
EXPECT_TRUE(handle.isUndefined()); EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined()); EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined()); EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
} }
TEST(StyleValuePool, store_undefined_after_small_int) { TEST(StyleValuePool, store_undefined_after_small_int) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::points(10)); pool.store(handle, StyleLength::points(10));
pool.store(handle, value::undefined()); pool.store(handle, StyleLength::undefined());
EXPECT_TRUE(handle.isUndefined()); EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined()); EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined()); EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
} }
TEST(StyleValuePool, store_undefined_after_large_int) { TEST(StyleValuePool, store_undefined_after_large_int) {
StyleValuePool pool; StyleValuePool pool;
StyleValueHandle handle; StyleValueHandle handle;
pool.store(handle, value::points(262144)); pool.store(handle, StyleLength::points(262144));
pool.store(handle, value::undefined()); pool.store(handle, StyleLength::undefined());
EXPECT_TRUE(handle.isUndefined()); EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined()); EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined()); EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
} }
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -0,0 +1,311 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* clang-format off
* @generated SignedSource<<00e4ee58a2a66a3fcd064d3c517d8330>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include "../util/TestUtil.h"
TEST(YogaTest, auto_width) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidthAuto(root);
YGNodeStyleSetHeight(root, 50);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0, 50);
YGNodeStyleSetHeight(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child1, 50);
YGNodeStyleSetHeight(root_child1, 50);
YGNodeInsertChild(root, root_child1, 1);
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child2, 50);
YGNodeStyleSetHeight(root_child2, 50);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, auto_height) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 50);
YGNodeStyleSetHeightAuto(root);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0, 50);
YGNodeStyleSetHeight(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child1, 50);
YGNodeStyleSetHeight(root_child1, 50);
YGNodeInsertChild(root, root_child1, 1);
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child2, 50);
YGNodeStyleSetHeight(root_child2, 50);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, auto_flex_basis) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 50);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child0, 50);
YGNodeStyleSetHeight(root_child0, 50);
YGNodeInsertChild(root, root_child0, 0);
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child1, 50);
YGNodeStyleSetHeight(root_child1, 50);
YGNodeInsertChild(root, root_child1, 1);
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root_child2, 50);
YGNodeStyleSetHeight(root_child2, 50);
YGNodeInsertChild(root, root_child2, 2);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, auto_position) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 50);
YGNodeStyleSetHeight(root, 50);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionAuto(root_child0, YGEdgeRight);
YGNodeStyleSetWidth(root_child0, 25);
YGNodeStyleSetHeight(root_child0, 25);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}
TEST(YogaTest, auto_margin) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 50);
YGNodeStyleSetHeight(root, 50);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
YGNodeStyleSetWidth(root_child0, 25);
YGNodeStyleSetHeight(root_child0, 25);
YGNodeInsertChild(root, root_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -177,18 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>( updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::points(flexBasis)); node, StyleLength::points(flexBasis));
} }
void YGNodeStyleSetFlexBasisPercent( void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node, const YGNodeRef node,
const float flexBasisPercent) { const float flexBasisPercent) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>( updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::percent(flexBasisPercent)); node, StyleLength::percent(flexBasisPercent));
} }
void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto()); updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleLength::ofAuto());
} }
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
@@ -197,17 +198,17 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) { void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::position, &Style::setPosition>( updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::points(points)); node, scopedEnum(edge), StyleLength::points(points));
} }
void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) { void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::position, &Style::setPosition>( updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::percent(percent)); node, scopedEnum(edge), StyleLength::percent(percent));
} }
void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) { void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::position, &Style::setPosition>( updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::ofAuto()); node, scopedEnum(edge), StyleLength::ofAuto());
} }
YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) { YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
@@ -216,17 +217,17 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) { void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::margin, &Style::setMargin>( updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::points(points)); node, scopedEnum(edge), StyleLength::points(points));
} }
void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) { void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::margin, &Style::setMargin>( updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::percent(percent)); node, scopedEnum(edge), StyleLength::percent(percent));
} }
void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) { void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::margin, &Style::setMargin>( updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::ofAuto()); node, scopedEnum(edge), StyleLength::ofAuto());
} }
YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) { YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
@@ -235,12 +236,12 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) { void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::padding, &Style::setPadding>( updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::points(points)); node, scopedEnum(edge), StyleLength::points(points));
} }
void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) { void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::padding, &Style::setPadding>( updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::percent(percent)); node, scopedEnum(edge), StyleLength::percent(percent));
} }
YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) { YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
@@ -252,7 +253,7 @@ void YGNodeStyleSetBorder(
const YGEdge edge, const YGEdge edge,
const float border) { const float border) {
updateStyle<&Style::border, &Style::setBorder>( updateStyle<&Style::border, &Style::setBorder>(
node, scopedEnum(edge), value::points(border)); node, scopedEnum(edge), StyleLength::points(border));
} }
float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) { float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
@@ -269,12 +270,12 @@ void YGNodeStyleSetGap(
const YGGutter gutter, const YGGutter gutter,
const float gapLength) { const float gapLength) {
updateStyle<&Style::gap, &Style::setGap>( updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::points(gapLength)); node, scopedEnum(gutter), StyleLength::points(gapLength));
} }
void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) { void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
updateStyle<&Style::gap, &Style::setGap>( updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::percent(percent)); node, scopedEnum(gutter), StyleLength::percent(percent));
} }
float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) { float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
@@ -307,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {
void YGNodeStyleSetWidth(YGNodeRef node, float points) { void YGNodeStyleSetWidth(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::points(points)); node, Dimension::Width, StyleLength::points(points));
} }
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) { void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::percent(percent)); node, Dimension::Width, StyleLength::percent(percent));
} }
void YGNodeStyleSetWidthAuto(YGNodeRef node) { void YGNodeStyleSetWidthAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::ofAuto()); node, Dimension::Width, StyleLength::ofAuto());
} }
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) { YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
@@ -326,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
void YGNodeStyleSetHeight(YGNodeRef node, float points) { void YGNodeStyleSetHeight(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::points(points)); node, Dimension::Height, StyleLength::points(points));
} }
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) { void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::percent(percent)); node, Dimension::Height, StyleLength::percent(percent));
} }
void YGNodeStyleSetHeightAuto(YGNodeRef node) { void YGNodeStyleSetHeightAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>( updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::ofAuto()); node, Dimension::Height, StyleLength::ofAuto());
} }
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) { YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
@@ -345,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) { void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>( updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::points(minWidth)); node, Dimension::Width, StyleLength::points(minWidth));
} }
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) { void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>( updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::percent(minWidth)); node, Dimension::Width, StyleLength::percent(minWidth));
} }
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) { YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
@@ -359,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) { void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>( updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::points(minHeight)); node, Dimension::Height, StyleLength::points(minHeight));
} }
void YGNodeStyleSetMinHeightPercent( void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node, const YGNodeRef node,
const float minHeight) { const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>( updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::percent(minHeight)); node, Dimension::Height, StyleLength::percent(minHeight));
} }
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) { YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
@@ -375,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) { void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>( updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::points(maxWidth)); node, Dimension::Width, StyleLength::points(maxWidth));
} }
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) { void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>( updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::percent(maxWidth)); node, Dimension::Width, StyleLength::percent(maxWidth));
} }
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) { YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
@@ -389,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) { void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>( updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::points(maxHeight)); node, Dimension::Height, StyleLength::points(maxHeight));
} }
void YGNodeStyleSetMaxHeightPercent( void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node, const YGNodeRef node,
const float maxHeight) { const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>( updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::percent(maxHeight)); node, Dimension::Height, StyleLength::percent(maxHeight));
} }
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) { YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {

View File

@@ -288,9 +288,10 @@ Style::Length Node::processFlexBasis() const {
return flexBasis; return flexBasis;
} }
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) { if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults() ? value::ofAuto() : value::points(0); return config_->useWebDefaults() ? StyleLength::ofAuto()
: StyleLength::points(0);
} }
return value::ofAuto(); return StyleLength::ofAuto();
} }
FloatOptional Node::resolveFlexBasis( FloatOptional Node::resolveFlexBasis(

View File

@@ -302,7 +302,7 @@ class YG_EXPORT Node : public ::YGNode {
std::vector<Node*> children_; std::vector<Node*> children_;
const Config* config_; const Config* config_;
std::array<Style::Length, 2> processedDimensions_{ std::array<Style::Length, 2> processedDimensions_{
{value::undefined(), value::undefined()}}; {StyleLength::undefined(), StyleLength::undefined()}};
}; };
inline Node* resolveRef(const YGNodeRef ref) { inline Node* resolveRef(const YGNodeRef ref) {

View File

@@ -104,36 +104,4 @@ inline bool inexactEquals(const StyleLength& a, const StyleLength& b) {
return a.unit() == b.unit() && inexactEquals(a.value(), b.value()); return a.unit() == b.unit() && inexactEquals(a.value(), b.value());
} }
namespace value {
/**
* Canonical unit (one YGUnitPoint)
*/
constexpr StyleLength points(float value) {
return StyleLength::points(value);
}
/**
* Percent of reference
*/
constexpr StyleLength percent(float value) {
return StyleLength::percent(value);
}
/**
* "auto" keyword
*/
constexpr StyleLength ofAuto() {
return StyleLength::ofAuto();
}
/**
* Undefined
*/
constexpr StyleLength undefined() {
return StyleLength::undefined();
}
} // namespace value
} // namespace facebook::yoga } // namespace facebook::yoga

View File

@@ -49,9 +49,9 @@ class StyleValuePool {
StyleLength getLength(StyleValueHandle handle) const { StyleLength getLength(StyleValueHandle handle) const {
if (handle.isUndefined()) { if (handle.isUndefined()) {
return value::undefined(); return StyleLength::undefined();
} else if (handle.isAuto()) { } else if (handle.isAuto()) {
return value::ofAuto(); return StyleLength::ofAuto();
} else { } else {
assert( assert(
handle.type() == StyleValueHandle::Type::Point || handle.type() == StyleValueHandle::Type::Point ||
@@ -61,8 +61,8 @@ class StyleValuePool {
: unpackInlineInteger(handle.value()); : unpackInlineInteger(handle.value());
return handle.type() == StyleValueHandle::Type::Point return handle.type() == StyleValueHandle::Type::Point
? value::points(value) ? StyleLength::points(value)
: value::percent(value); : StyleLength::percent(value);
} }
} }