Baseline support #317
285
csharp/tests/Facebook.Yoga/YGAlignBaseline.cs
Normal file
@@ -0,0 +1,285 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignBaseline.html
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace Facebook.Yoga
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class YGAlignBaseline
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Test_align_baseline()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root.AlignItems = YogaAlign.Baseline;
|
||||||
|
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.Width = 50;
|
||||||
|
root_child1.Height = 20;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
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(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(30f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.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(50f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(30f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_align_baseline_child()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root.AlignItems = YogaAlign.Baseline;
|
||||||
|
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.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(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(40f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, 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(50f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(40f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_align_baseline_double_nested_child()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.FlexDirection = YogaFlexDirection.Row;
|
||||||
|
root.AlignItems = YogaAlign.Baseline;
|
||||||
|
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_child0_child0 = new YogaNode();
|
||||||
|
root_child0_child0.Width = 50;
|
||||||
|
root_child0_child0.Height = 20;
|
||||||
|
root_child0.Insert(0, root_child0_child0);
|
||||||
|
|
||||||
|
YogaNode root_child1 = new YogaNode();
|
||||||
|
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 = 15;
|
||||||
|
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(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(15f, 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(50f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(5f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child1_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(15f, root_child1_child0.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_align_baseline_column()
|
||||||
|
{
|
||||||
|
YogaNode root = new YogaNode();
|
||||||
|
root.AlignItems = YogaAlign.Baseline;
|
||||||
|
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.Width = 50;
|
||||||
|
root_child1.Height = 20;
|
||||||
|
root.Insert(1, root_child1);
|
||||||
|
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(0f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.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(50f, root_child0.LayoutX);
|
||||||
|
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutWidth);
|
||||||
|
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||||
|
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutX);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutY);
|
||||||
|
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||||
|
Assert.AreEqual(20f, root_child1.LayoutHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
1
enums.py
@@ -46,6 +46,7 @@ ENUMS = {
|
|||||||
'Center',
|
'Center',
|
||||||
'FlexEnd',
|
'FlexEnd',
|
||||||
'Stretch',
|
'Stretch',
|
||||||
|
'Baseline',
|
||||||
],
|
],
|
||||||
'PositionType': [
|
'PositionType': [
|
||||||
'Relative',
|
'Relative',
|
||||||
|
26
gentest/fixtures/YGAlignBaseline.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<div id="align_baseline" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
|
||||||
|
|||||||
|
<div style="width: 50px; height: 50px;"></div>
|
||||||
|
<div style="width: 50px; height: 20px;"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="align_baseline_child" style="width: 100px; height: 100px; flex-direction:row; background-color:red; align-items: baseline;">
|
||||||
|
<div style="width: 50px; height: 50px;background-color:green"></div>
|
||||||
|
<div style="width: 50px; height: 20px;background-color:green">
|
||||||
|
<div style="width: 50px; height: 10px;background-color:yellow"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="align_baseline_double_nested_child" style="width: 100px; height: 100px; flex-direction:row; background-color:red; align-items: baseline;">
|
||||||
|
<div style="width: 50px; height: 50px;background-color:green">
|
||||||
|
<div style="width: 50px; height: 20px;background-color:yellow"></div>
|
||||||
|
</div>
|
||||||
|
<div style="width: 50px; height: 20px;background-color:green">
|
||||||
|
<div style="width: 50px; height: 15px;background-color:yellow"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="align_baseline_column" style="width: 100px; height: 100px; flex-direction:column; align-items: baseline;">
|
||||||
|
<div style="width: 50px; height: 50px;"></div>
|
||||||
|
<div style="width: 50px; height: 20px;"></div>
|
||||||
|
</div>
|
@@ -83,6 +83,8 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
YGAlignFlexStart:{value:'YGAlignFlexStart'},
|
YGAlignFlexStart:{value:'YGAlignFlexStart'},
|
||||||
YGAlignStretch:{value:'YGAlignStretch'},
|
YGAlignStretch:{value:'YGAlignStretch'},
|
||||||
|
|
||||||
|
YGAlignBaseline:{value:'YGAlignBaseline'},
|
||||||
|
|
||||||
YGDirectionInherit:{value:'YGDirectionInherit'},
|
YGDirectionInherit:{value:'YGDirectionInherit'},
|
||||||
YGDirectionLTR:{value:'YGDirectionLTR'},
|
YGDirectionLTR:{value:'YGDirectionLTR'},
|
||||||
YGDirectionRTL:{value:'YGDirectionRTL'},
|
YGDirectionRTL:{value:'YGDirectionRTL'},
|
||||||
|
@@ -96,6 +96,7 @@ CSEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
YGAlignFlexEnd:{value:'YogaAlign.FlexEnd'},
|
YGAlignFlexEnd:{value:'YogaAlign.FlexEnd'},
|
||||||
YGAlignFlexStart:{value:'YogaAlign.FlexStart'},
|
YGAlignFlexStart:{value:'YogaAlign.FlexStart'},
|
||||||
YGAlignStretch:{value:'YogaAlign.Stretch'},
|
YGAlignStretch:{value:'YogaAlign.Stretch'},
|
||||||
|
YGAlignBaseline:{value:'YogaAlign.Baseline'},
|
||||||
|
|
||||||
YGDirectionInherit:{value:'YogaDirection.Inherit'},
|
YGDirectionInherit:{value:'YogaDirection.Inherit'},
|
||||||
YGDirectionLTR:{value:'YogaDirection.LTR'},
|
YGDirectionLTR:{value:'YogaDirection.LTR'},
|
||||||
|
@@ -100,6 +100,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
YGAlignFlexEnd:{value:'YogaAlign.FLEX_END'},
|
YGAlignFlexEnd:{value:'YogaAlign.FLEX_END'},
|
||||||
YGAlignFlexStart:{value:'YogaAlign.FLEX_START'},
|
YGAlignFlexStart:{value:'YogaAlign.FLEX_START'},
|
||||||
YGAlignStretch:{value:'YogaAlign.STRETCH'},
|
YGAlignStretch:{value:'YogaAlign.STRETCH'},
|
||||||
|
YGAlignBaseline:{value:'YogaAlign.Baseline'},
|
||||||
|
|
||||||
YGDirectionInherit:{value:'YogaDirection.INHERIT'},
|
YGDirectionInherit:{value:'YogaDirection.INHERIT'},
|
||||||
YGDirectionLTR:{value:'YogaDirection.LTR'},
|
YGDirectionLTR:{value:'YogaDirection.LTR'},
|
||||||
|
@@ -84,6 +84,7 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
YGAlignFlexEnd:{value:'Yoga.ALIGN_FLEX_END'},
|
YGAlignFlexEnd:{value:'Yoga.ALIGN_FLEX_END'},
|
||||||
YGAlignFlexStart:{value:'Yoga.ALIGN_FLEX_START'},
|
YGAlignFlexStart:{value:'Yoga.ALIGN_FLEX_START'},
|
||||||
YGAlignStretch:{value:'Yoga.ALIGN_STRETCH'},
|
YGAlignStretch:{value:'Yoga.ALIGN_STRETCH'},
|
||||||
|
YGAlignBaseline:{value:'Yoga.ALIGN_BASELINE'},
|
||||||
|
|
||||||
YGDirectionInherit:{value:'Yoga.DIRECTION_INHERIT'},
|
YGDirectionInherit:{value:'Yoga.DIRECTION_INHERIT'},
|
||||||
YGDirectionLTR:{value:'Yoga.DIRECTION_LTR'},
|
YGDirectionLTR:{value:'Yoga.DIRECTION_LTR'},
|
||||||
|
@@ -377,6 +377,7 @@ function alignValue(e, value) {
|
|||||||
case 'stretch': return e.YGAlignStretch;
|
case 'stretch': return e.YGAlignStretch;
|
||||||
case 'flex-start': return e.YGAlignFlexStart;
|
case 'flex-start': return e.YGAlignFlexStart;
|
||||||
case 'flex-end': return e.YGAlignFlexEnd;
|
case 'flex-end': return e.YGAlignFlexEnd;
|
||||||
|
case 'baseline': return e.YGAlignBaseline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
279
java/tests/com/facebook/yoga/YGAlignBaseline.java
Normal file
@@ -0,0 +1,279 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignBaseline.html
|
||||||
|
|
||||||
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class YGAlignBaseline {
|
||||||
|
@Test
|
||||||
|
public void test_align_baseline() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setAlignItems(YogaAlign.Baseline);
|
||||||
|
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.setWidth(50f);
|
||||||
|
root_child1.setHeight(20f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
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(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(30f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.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(50f, 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(30f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_align_baseline_child() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setAlignItems(YogaAlign.Baseline);
|
||||||
|
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.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(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(40f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, 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(50f, 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(40f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_align_baseline_double_nested_child() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setAlignItems(YogaAlign.Baseline);
|
||||||
|
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_child0_child0 = new YogaNode();
|
||||||
|
root_child0_child0.setWidth(50f);
|
||||||
|
root_child0_child0.setHeight(20f);
|
||||||
|
root_child0.addChildAt(root_child0_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = new YogaNode();
|
||||||
|
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(15f);
|
||||||
|
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(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_child0_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(15f, 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(50f, 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_child0_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child0_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(5f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(15f, root_child1_child0.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_align_baseline_column() {
|
||||||
|
final YogaNode root = new YogaNode();
|
||||||
|
root.setAlignItems(YogaAlign.Baseline);
|
||||||
|
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.setWidth(50f);
|
||||||
|
root_child1.setHeight(20f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
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(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(20f, root_child1.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(50f, 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(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(20f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
269
tests/YGAlignBaseline.cpp
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// @Generated by gentest/gentest.rb from gentest/fixtures/YGAlignBaseline.html
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
TEST(YogaTest, align_baseline) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
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();
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 20);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
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(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(30, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
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(50, 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(30, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, align_baseline_child) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
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();
|
||||||
|
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(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(40, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, 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(50, 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(40, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, 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_double_nested_child) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
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_child0_child0 = YGNodeNew();
|
||||||
|
YGNodeStyleSetWidth(root_child0_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child0_child0, 20);
|
||||||
|
YGNodeInsertChild(root_child0, root_child0_child0, 0);
|
||||||
|
|
||||||
|
const YGNodeRef root_child1 = YGNodeNew();
|
||||||
|
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, 15);
|
||||||
|
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(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_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(15, 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(50, 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_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0_child0));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child0_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(5, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(15, YGNodeLayoutGetHeight(root_child1_child0));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, align_baseline_column) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
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();
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 20);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
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(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(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
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(50, 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(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
}
|
63
tests/YGAlignBaselineCustomTest.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
static float _baseline(YGNodeRef node) {
|
||||||
|
float *baseline = (float*) YGNodeGetContext(node);
|
||||||
|
return *baseline;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, align_baseline_customer_func) {
|
||||||
|
const YGNodeRef root = YGNodeNew();
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetAlignItems(root, YGAlignBaseline);
|
||||||
|
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();
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 20);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
|
float baselineValue = 10;
|
||||||
|
const YGNodeRef root_child1_child0 = YGNodeNew();
|
||||||
|
YGNodeSetContext(root_child1_child0, &baselineValue);
|
||||||
|
YGNodeStyleSetWidth(root_child1_child0, 50);
|
||||||
|
YGNodeSetBaselineFunc(root_child1_child0, _baseline);
|
||||||
|
YGNodeStyleSetHeight(root_child1_child0, 20);
|
||||||
|
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(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(40, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1_child0));
|
||||||
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root_child1_child0));
|
||||||
|
}
|
@@ -104,13 +104,14 @@ typedef enum YGExperimentalFeature {
|
|||||||
YGExperimentalFeatureWebFlexBasis,
|
YGExperimentalFeatureWebFlexBasis,
|
||||||
} YGExperimentalFeature;
|
} YGExperimentalFeature;
|
||||||
|
|
||||||
#define YGAlignCount 5
|
#define YGAlignCount 6
|
||||||
typedef enum YGAlign {
|
typedef enum YGAlign {
|
||||||
YGAlignAuto,
|
YGAlignAuto,
|
||||||
YGAlignFlexStart,
|
YGAlignFlexStart,
|
||||||
YGAlignCenter,
|
YGAlignCenter,
|
||||||
YGAlignFlexEnd,
|
YGAlignFlexEnd,
|
||||||
YGAlignStretch,
|
YGAlignStretch,
|
||||||
|
YGAlignBaseline,
|
||||||
} YGAlign;
|
} YGAlign;
|
||||||
|
|
||||||
#define YGUnitCount 3
|
#define YGUnitCount 3
|
||||||
|
86
yoga/Yoga.c
@@ -102,6 +102,7 @@ typedef struct YGNode {
|
|||||||
struct YGNode *nextChild;
|
struct YGNode *nextChild;
|
||||||
|
|
||||||
YGMeasureFunc measure;
|
YGMeasureFunc measure;
|
||||||
|
YGBaselineFunc baseline;
|
||||||
YGPrintFunc print;
|
YGPrintFunc print;
|
||||||
void *context;
|
void *context;
|
||||||
} YGNode;
|
} YGNode;
|
||||||
@@ -334,6 +335,20 @@ YGMeasureFunc YGNodeGetMeasureFunc(const YGNodeRef node) {
|
|||||||
return node->measure;
|
return node->measure;
|
||||||
![]()
`node->baseline = baselineFunc;` is enough
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void YGNodeSetBaselineFunc(const YGNodeRef node, YGBaselineFunc baselineFunc) {
|
||||||
|
if (baselineFunc == NULL) {
|
||||||
|
node->baseline = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
node->baseline = baselineFunc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
YGBaselineFunc YGNodeGetBaselineFunc(const YGNodeRef node) {
|
||||||
|
return node->baseline;
|
||||||
|
}
|
||||||
|
|
||||||
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
|
||||||
YG_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
YG_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
||||||
YG_ASSERT(node->measure == NULL,
|
YG_ASSERT(node->measure == NULL,
|
||||||
@@ -941,6 +956,61 @@ static inline YGDirection YGNodeResolveDirection(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
![]() uint32_t uint32_t
![]() i++ i++
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static float YGBaselineOfFirstLine(const YGNodeRef node, const YGFlexDirection mainAxis, const float parentWidth)
|
||||||
|
{
|
||||||
|
if(node->baseline != NULL)
|
||||||
|
{
|
||||||
|
return node->baseline(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
YGNodeRef baselineChild = NULL;
|
||||||
|
for(unsigned int i = 0; i < YGNodeGetChildCount(node); ++i)
|
||||||
|
{
|
||||||
|
const YGNodeRef child = YGNodeGetChild(node, i);
|
||||||
|
if(child->style.positionType == YGPositionTypeAbsolute || child->lineIndex > 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(YGNodeAlignItem(node, child) == YGAlignBaseline)
|
||||||
|
{
|
||||||
|
baselineChild = child;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(baselineChild == NULL)
|
||||||
|
{
|
||||||
|
baselineChild = child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(baselineChild == NULL)
|
||||||
|
{
|
||||||
|
return YGUndefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
float baseline = YGBaselineOfFirstLine(baselineChild, node->style.direction, node->layout.measuredDimensions[YGDimensionWidth]);
|
||||||
|
if(YGFloatIsUndefined(baseline))
|
||||||
|
{
|
||||||
|
baseline = YGNodeLeadingPaddingAndBorder(baselineChild, mainAxis, parentWidth)
|
||||||
|
+ baselineChild->layout.measuredDimensions[dim[mainAxis]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseline + baselineChild->layout.position[YGEdgeTop];
|
||||||
|
}
|
||||||
|
|
||||||
|
static float YGBaselineWithMargin(const YGNodeRef node, const YGFlexDirection mainAxis, const float parentWidth)
|
||||||
|
{
|
||||||
|
float baseline = YGBaselineOfFirstLine(node, mainAxis, parentWidth);
|
||||||
![]() not quite sure why we break if a child has more than one line. That would mean if the first child of this node has two lines then the baseline would default to the height of the node. I'm not sure why that would be correct. not quite sure why we break if a child has more than one line. That would mean if the first child of this node has two lines then the baseline would default to the height of the node. I'm not sure why that would be correct.
![]() we break as only childs on the first line which have align baseline are taken into account. I already added a testcase for this. we break as only childs on the first line which have align baseline are taken into account. I already added a testcase for this.
![]() oh, I see the confusion, oh, I see the confusion, ```child->lineIndex``` does not mean that it has more than one line. It means it is itself on the seconds (or later) line.
![]() @woehrl01 yeah that was my confusion, i'm not super familiar with the multi line code and read it too quickly 🐱 @woehrl01 yeah that was my confusion, i'm not super familiar with the multi line code and read it too quickly 🐱
|
|||||||
|
if(YGFloatIsUndefined(baseline))
|
||||||
|
{
|
||||||
|
baseline = node->layout.measuredDimensions[dim[mainAxis]];
|
||||||
|
}
|
||||||
|
return baseline + YGNodeLeadingMargin(node, mainAxis, parentWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection,
|
static inline YGFlexDirection YGFlexDirectionResolve(const YGFlexDirection flexDirection,
|
||||||
const YGDirection direction) {
|
const YGDirection direction) {
|
||||||
![]() nit: empty line above nit: empty line above
![]() Please add this 👍 Please add this 👍
![]() not sure what you mean, should I add a empty line above not sure what you mean, should I add a empty line above ```return false```?
|
|||||||
if (direction == YGDirectionRTL) {
|
if (direction == YGDirectionRTL) {
|
||||||
@@ -2422,7 +2492,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
|
// STEP 8: MULTI-LINE CONTENT ALIGNMENT
|
||||||
![]()
`performLayout` check is not needed here as it is already checked in the containing if statement
![]() isn't performlayout checked at line 2526 a little bit down below? isn't performlayout checked at line 2526 a little bit down below?
|
|||||||
if (lineCount > 1 && performLayout && !YGFloatIsUndefined(availableInnerCrossDim)) {
|
if ((node->style.alignItems == YGAlignBaseline || lineCount > 1) && performLayout && !YGFloatIsUndefined(availableInnerCrossDim)) {
|
||||||
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
|
const float remainingAlignContentDim = availableInnerCrossDim - totalLineCrossDim;
|
||||||
|
|
||||||
float crossDimLead = 0;
|
float crossDimLead = 0;
|
||||||
@@ -2442,6 +2512,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
break;
|
break;
|
||||||
case YGAlignAuto:
|
case YGAlignAuto:
|
||||||
case YGAlignFlexStart:
|
case YGAlignFlexStart:
|
||||||
|
case YGAlignBaseline:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2452,6 +2523,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
|
|
||||||
// compute the line's height and find the endIndex
|
// compute the line's height and find the endIndex
|
||||||
float lineHeight = 0;
|
float lineHeight = 0;
|
||||||
|
float maxAscentForCurrentLine = 0;
|
||||||
for (ii = startIndex; ii < childCount; ii++) {
|
for (ii = startIndex; ii < childCount; ii++) {
|
||||||
const YGNodeRef child = YGNodeListGet(node->children, ii);
|
const YGNodeRef child = YGNodeListGet(node->children, ii);
|
||||||
|
|
||||||
@@ -2460,6 +2532,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (performLayout && YGNodeAlignItem(node, child) == YGAlignBaseline)
|
||||||
|
{
|
||||||
|
maxAscentForCurrentLine = fmaxf(maxAscentForCurrentLine,
|
||||||
|
YGBaselineWithMargin(child, crossAxis, availableInnerWidth));
|
||||||
|
}
|
||||||
|
|
||||||
if (YGNodeIsLayoutDimDefined(child, crossAxis)) {
|
if (YGNodeIsLayoutDimDefined(child, crossAxis)) {
|
||||||
lineHeight = fmaxf(lineHeight,
|
lineHeight = fmaxf(lineHeight,
|
||||||
child->layout.measuredDimensions[dim[crossAxis]] +
|
child->layout.measuredDimensions[dim[crossAxis]] +
|
||||||
@@ -2501,6 +2579,12 @@ static void YGNodelayoutImpl(const YGNodeRef node,
|
|||||||
// (auto) crossAxis dimension.
|
// (auto) crossAxis dimension.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case YGAlignBaseline: {
|
||||||
|
child->layout.position[pos[crossAxis]] = currentLead
|
||||||
|
+ maxAscentForCurrentLine -
|
||||||
|
YGBaselineWithMargin(child, crossAxis, availableInnerWidth);;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case YGAlignAuto:
|
case YGAlignAuto:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,9 @@ typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
|||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
![]() nit: remove added empty lines nit: remove added empty lines
![]() nit: remove added empty line nit: remove added empty line
|
|||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode);
|
YGMeasureMode heightMode);
|
||||||
|
|
||||||
|
typedef float(*YGBaselineFunc)(YGNodeRef node);
|
||||||
|
|
||||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||||
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
typedef int (*YGLogger)(YGLogLevel level, const char *format, va_list args);
|
||||||
|
|
||||||
@@ -138,6 +141,7 @@ WIN_EXPORT void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode
|
|||||||
|
|
||||||
YG_NODE_PROPERTY(void *, Context, context);
|
YG_NODE_PROPERTY(void *, Context, context);
|
||||||
YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
|
YG_NODE_PROPERTY(YGMeasureFunc, MeasureFunc, measureFunc);
|
||||||
|
YG_NODE_PROPERTY(YGBaselineFunc, BaselineFunc, baselineFunc)
|
||||||
YG_NODE_PROPERTY(YGPrintFunc, PrintFunc, printFunc);
|
YG_NODE_PROPERTY(YGPrintFunc, PrintFunc, printFunc);
|
||||||
YG_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
YG_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
|
||||||
|
|
||||||
|
please test with different widths on the two items as width is the axis being aligned here
indentation
indendation
please vary the widths as this is a column layout
This whole file would probably make sense to have as part of the YGAlignItems.html + YGAlignSelf.html files which already exist