Baseline support #317
@@ -655,6 +655,84 @@ namespace Facebook.Yoga
|
|||||||
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
|
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_align_baseline_child_padding()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root.AlignItems = YogaAlign.Baseline;
|
||||||
|
root.SetPadding(YogaEdge.Left, 5);
|
||||||
|
root.SetPadding(YogaEdge.Top, 5);
|
||||||
|
root.SetPadding(YogaEdge.Right, 5);
|
||||||
|
root.SetPadding(YogaEdge.Bottom, 5);
|
||||||
|
root.Width = 100;
|
||||||
|
root.Height = 100;
|
||||||
|
|
||||||
|
YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.Width = 50;
|
||||||
|
root_child0.Height = 50;
|
||||||
|
root.Insert(0, root_child0);
|
||||||
|
|
||||||
|
YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.SetPadding(YogaEdge.Left, 5);
|
||||||
|
root_child1.SetPadding(YogaEdge.Top, 5);
|
||||||
|
root_child1.SetPadding(YogaEdge.Right, 5);
|
||||||
|
root_child1.SetPadding(YogaEdge.Bottom, 5);
|
||||||
|
root_child1.Width = 50;
|
||||||
|
root_child1.Height = 20;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
|
||||||
|
YogaNode root_child1_child0 = new YogaNode();
|
||||||
|
root_child1_child0.Width = 50;
|
||||||
|
root_child1_child0.Height = 10;
|
||||||
|
root_child1.Insert(0, root_child1_child0);
|
||||||
|
root.StyleDirection = YogaDirection.LTR;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(5f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(55f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(40f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(5f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child1_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
|
||||||
|
|
||||||
|
root.StyleDirection = YogaDirection.RTL;
|
||||||
|
root.CalculateLayout();
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root.LayoutY);
|
||||||
|
Assert.AreEqual(100f, root.LayoutWidth);
|
||||||
|
Assert.AreEqual(100f, root.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(45f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(-5f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(40f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(-5f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child1_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_align_baseline_multiline()
|
public void Test_align_baseline_multiline()
|
||||||
{
|
{
|
||||||
|
@@ -62,6 +62,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="align_baseline_child_padding" style="width: 100px; height: 100px; padding:5px; flex-direction:row; align-items: baseline;">
|
||||||
|
<div style="width: 50px; height: 50px;"></div>
|
||||||
|
<div style="width: 50px; height: 20px;padding:5px;">
|
||||||
|
<div style="width: 50px; height: 10px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="align_baseline_multiline" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;flex-wrap:wrap;">
|
<div id="align_baseline_multiline" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;flex-wrap:wrap;">
|
||||||
<div style="width: 50px; height: 50px;"></div>
|
<div style="width: 50px; height: 50px;"></div>
|
||||||
<div style="width: 50px; height: 20px;">
|
<div style="width: 50px; height: 20px;">
|
||||||
|
@@ -643,6 +643,83 @@ public class YGAlignItemsTest {
|
|||||||
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
|
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_align_baseline_child_padding() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setAlignItems(YogaAlign.BASELINE);
|
||||||
|
root.setPadding(YogaEdge.LEFT, 5);
|
||||||
|
root.setPadding(YogaEdge.TOP, 5);
|
||||||
|
root.setPadding(YogaEdge.RIGHT, 5);
|
||||||
|
root.setPadding(YogaEdge.BOTTOM, 5);
|
||||||
|
root.setWidth(100f);
|
||||||
|
root.setHeight(100f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = new YogaNode();
|
||||||
|
root_child0.setWidth(50f);
|
||||||
|
root_child0.setHeight(50f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = new YogaNode();
|
||||||
|
root_child1.setPadding(YogaEdge.LEFT, 5);
|
||||||
|
root_child1.setPadding(YogaEdge.TOP, 5);
|
||||||
|
root_child1.setPadding(YogaEdge.RIGHT, 5);
|
||||||
|
root_child1.setPadding(YogaEdge.BOTTOM, 5);
|
||||||
|
root_child1.setWidth(50f);
|
||||||
|
root_child1.setHeight(20f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
|
||||||
|
final YogaNode root_child1_child0 = new YogaNode();
|
||||||
|
root_child1_child0.setWidth(50f);
|
||||||
|
root_child1_child0.setHeight(10f);
|
||||||
|
root_child1.addChildAt(root_child1_child0, 0);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(5f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(55f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(40f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(5f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child1_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout();
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(100f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(45f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(-5f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(40f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(-5f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child1_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_align_baseline_multiline() {
|
public void test_align_baseline_multiline() {
|
||||||
final YogaNode root = new YogaNode();
|
final YogaNode root = new YogaNode();
|
||||||
|
@@ -628,6 +628,82 @@ TEST(YogaTest, align_baseline_child_margin) {
|
|||||||
YGNodeFreeRecursive(root);
|
YGNodeFreeRecursive(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, align_baseline_child_padding) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 5);
|
||||||
|
YGNodeStyleSetPadding(root, YGEdgeTop, 5);
|
||||||
|
YGNodeStyleSetPadding(root, YGEdgeRight, 5);
|
||||||
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 5);
|
||||||
|
YGNodeStyleSetWidth(root, 100);
|
||||||
|
YGNodeStyleSetHeight(root, 100);
|
||||||
|
|
||||||
|
const YGNodeRef root_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 50);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
|
YGNodeStyleSetPadding(root_child1, YGEdgeLeft, 5);
|
||||||
|
YGNodeStyleSetPadding(root_child1, YGEdgeTop, 5);
|
||||||
|
YGNodeStyleSetPadding(root_child1, YGEdgeRight, 5);
|
||||||
|
YGNodeStyleSetPadding(root_child1, YGEdgeBottom, 5);
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 20);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1_child0, 10);
|
||||||
|
YGNodeInsertChild(root_child1, root_child1_child0, 0);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(55, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(45, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(-5, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(-5, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child1_child0));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(YogaTest, align_baseline_multiline) {
|
TEST(YogaTest, align_baseline_multiline) {
|
||||||
const YGNodeRef root = YGNodeNew();
|
const YGNodeRef root = YGNodeNew();
|
||||||
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
@@ -956,8 +956,7 @@ static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|||||||
|
|
||||||
static float YGBaseline(const YGNodeRef node,
|
static float YGBaseline(const YGNodeRef node,
|
||||||
const YGFlexDirection crossAxis,
|
const YGFlexDirection crossAxis) {
|
||||||
const YGFlexDirection mainAxis) {
|
|
||||||
if (node->baseline != NULL) {
|
if (node->baseline != NULL) {
|
||||||
const float baseline = node->baseline(node);
|
const float baseline = node->baseline(node);
|
||||||
if (YGFloatIsUndefined(baseline)) {
|
if (YGFloatIsUndefined(baseline)) {
|
||||||
@@ -987,7 +986,7 @@ static float YGBaseline(const YGNodeRef node,
|
|||||||
return node->layout.measuredDimensions[dim[crossAxis]];
|
return node->layout.measuredDimensions[dim[crossAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
const float baseline = YGBaseline(baselineChild, crossAxis, mainAxis);
|
const float baseline = YGBaseline(baselineChild, crossAxis);
|
||||||
return baseline + baselineChild->layout.position[pos[crossAxis]];
|
return baseline + baselineChild->layout.position[pos[crossAxis]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2532,7 +2531,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth));
|
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth));
|
||||||
}
|
}
|
||||||
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
if (YGNodeAlignItem(node, child) == YGAlignBaseline) {
|
||||||
const float ascent = YGBaseline(child, crossAxis, mainAxis) +
|
const float ascent = YGBaseline(child, crossAxis) +
|
||||||
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth);
|
YGNodeLeadingMargin(child, crossAxis, availableInnerWidth);
|
||||||
const float descent = child->layout.measuredDimensions[dim[crossAxis]] +
|
const float descent = child->layout.measuredDimensions[dim[crossAxis]] +
|
||||||
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) -
|
YGNodeMarginForAxis(child, crossAxis, availableInnerWidth) -
|
||||||
@@ -2579,7 +2578,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
case YGAlignBaseline: {
|
case YGAlignBaseline: {
|
||||||
child->layout.position[pos[crossAxis]] =
|
child->layout.position[pos[crossAxis]] =
|
||||||
currentLead + maxAscentForCurrentLine - YGBaseline(child, crossAxis, mainAxis) +
|
currentLead + maxAscentForCurrentLine - YGBaseline(child, crossAxis) +
|
||||||
YGNodeLeadingPosition(child, crossAxis, availableInnerCrossDim);
|
YGNodeLeadingPosition(child, crossAxis, availableInnerCrossDim);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user
uint32_t
i++