Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline support #317

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3d840e5
added baseline support
woehrl01 Jan 4, 2017
3b20c24
remove background color from tests
woehrl01 Jan 4, 2017
71a23ef
fix whitespace indent
woehrl01 Jan 4, 2017
09f3470
more whitespace cleanup
woehrl01 Jan 4, 2017
29bce98
enums for csharp and java
woehrl01 Jan 4, 2017
d4ccb44
use flexdirection
woehrl01 Jan 4, 2017
5803ba4
fix nodes with margin
woehrl01 Jan 5, 2017
eaa2501
fix multiline baseline layout
woehrl01 Jan 5, 2017
45f0011
run format.sh
woehrl01 Jan 5, 2017
3e5e01f
renamed variables correctly and used correct values
woehrl01 Jan 5, 2017
e99e7b9
format
woehrl01 Jan 5, 2017
49ffda5
cleanup
woehrl01 Jan 5, 2017
d4e4595
remove unneeded function
woehrl01 Jan 5, 2017
b721fb3
delete tmp file
woehrl01 Jan 5, 2017
00ab30e
get baseline of the same direction
woehrl01 Jan 5, 2017
23ad2df
fix layout with explicit top specified
woehrl01 Jan 5, 2017
17ef313
renamed to YGBaseline
woehrl01 Jan 5, 2017
87abbc0
added test for align-self: baseline
woehrl01 Jan 5, 2017
e4f70d0
delete tmp
woehrl01 Jan 5, 2017
60861a3
more tests for row and column directions
woehrl01 Jan 5, 2017
d10d050
renamed files and moved tests to accoriding fixtures
woehrl01 Jan 5, 2017
e87edbf
adjusted text and fixed alignment on column/row direction difference
woehrl01 Jan 5, 2017
9d035cd
added additional tests
woehrl01 Jan 5, 2017
1c52ff1
wrong comparions
woehrl01 Jan 5, 2017
cf7a7c5
added tests for margin and removed unused function argument
woehrl01 Jan 5, 2017
3151617
code review changes and tests for child firstline and per baseline ov…
woehrl01 Jan 5, 2017
fc834e8
add testcase where align-self can't override if on second line
woehrl01 Jan 5, 2017
11825ad
break instead of continue if on second line
woehrl01 Jan 5, 2017
b790bf7
crash if custom baseline function returns undefined
woehrl01 Jan 5, 2017
2595e08
use height explicit
woehrl01 Jan 5, 2017
0a708e1
use YGFlexDirectionColumn explicit
woehrl01 Jan 5, 2017
9e44f0f
code review changes
woehrl01 Jan 5, 2017
1d9855b
shortcut if node is column direction
woehrl01 Jan 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csharp/Facebook.Yoga/YogaAlign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public enum YogaAlign
Center,
FlexEnd,
Stretch,
Baseline,
}
}
1,378 changes: 1,378 additions & 0 deletions csharp/tests/Facebook.Yoga/YGAlignItemsTest.cs

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions csharp/tests/Facebook.Yoga/YGAlignSelfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,76 @@ public void Test_align_self_flex_end_override_flex_start()
Assert.AreEqual(10f, root_child0.LayoutHeight);
}

[Test]
public void Test_align_self_baseline()
{
YogaNode root = new YogaNode();
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 100;
root.Height = 100;

YogaNode root_child0 = new YogaNode();
root_child0.AlignSelf = YogaAlign.Baseline;
root_child0.Width = 50;
root_child0.Height = 50;
root.Insert(0, root_child0);

YogaNode root_child1 = new YogaNode();
root_child1.AlignSelf = YogaAlign.Baseline;
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);
}

}
}
1 change: 1 addition & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'Center',
'FlexEnd',
'Stretch',
'Baseline',
],
'PositionType': [
'Relative',
Expand Down
132 changes: 132 additions & 0 deletions gentest/fixtures/YGAlignItemsTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,135 @@
<div id="align_items_flex_end" style="width: 100px; height: 100px; align-items: flex-end;">
<div style="height: 10px; width: 10px;"></div>
</div>

<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; align-items: baseline;">
<div style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>

<div id="align_baseline_child_multiline" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 60px;"></div>
<div style="width: 50px; height: 25px;flex-wrap:wrap;flex-direction:row;">
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;"></div>
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;"></div>
</div>
</div>

<div id="align_baseline_child_multiline_override" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 60px;"></div>
<div style="width: 50px; height: 25px;flex-wrap:wrap;flex-direction:row;">
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;align-self:baseline;"></div>
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;align-self:baseline;"></div>
</div>
</div>

<div id="align_baseline_child_multiline_no_override_on_secondline" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 60px;"></div>
<div style="width: 50px; height: 25px;flex-wrap:wrap;flex-direction:row;">
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;"></div>
<div style="width: 25px; height: 20px;"></div>
<div style="width: 25px; height: 10px;align-self:baseline;"></div>
</div>
</div>


<div id="align_baseline_child_top" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 50px;top:10px;"></div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>

<div id="align_baseline_child_top2" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 20px;top:5px">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>

<div id="align_baseline_double_nested_child" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 50px;">
<div style="width: 50px; height: 20px;"></div>
</div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 15px;"></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>

<div id="align_baseline_child_margin" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;">
<div style="width: 50px; height: 50px;margin: 5px;"></div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 10px;margin: 1px;"></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 style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 10px;"></div>
</div>
<div style="width: 50px; height: 20px;">
<div style="width: 50px; height: 10px;"></div>
</div>
<div style="width: 50px; height: 50px;"></div>
</div>

<div id="align_baseline_multiline_column" style="width: 100px; height: 100px; flex-direction:column; align-items: baseline;flex-wrap:wrap;">
<div style="width: 50px; height: 50px;"></div>
<div style="width: 30px; height: 50px;">
<div style="width: 20px; height: 20px;"></div>
</div>
<div style="width: 40px; height: 70px;">
<div style="width: 10px; height: 10px;"></div>
</div>
<div style="width: 50px; height: 20px;"></div>
</div>

<div id="align_baseline_multiline_column2" style="width: 100px; height: 100px; flex-direction:column; align-items: baseline;flex-wrap:wrap;">
<div style="width: 50px; height: 50px;flex-direction:column;"></div>
<div style="width: 30px; height: 50px;flex-direction:column;">
<div style="width: 20px; height: 20px;flex-direction:column;"></div>
</div>
<div style="width: 40px; height: 70px;flex-direction:column;">
<div style="width: 10px; height: 10px;flex-direction:column;"></div>
</div>
<div style="width: 50px; height: 20px;flex-direction:column;"></div>
</div>



<div id="align_baseline_multiline_row_and_column" 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;flex-direction:column;">
<div style="width: 50px; height: 10px;"></div>
</div>
<div style="width: 50px; height: 20px;flex-direction:column;">
<div style="width: 50px; height: 10px;"></div>
</div>
<div style="width: 50px; height: 20px;"></div>
</div>
8 changes: 8 additions & 0 deletions gentest/fixtures/YGAlignSelfTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
<div id="align_self_flex_end_override_flex_start" style="width:100px; height: 100px; align-items: flex-start;">
<div style="height: 10px; width: 10px; align-self: flex-end;"></div>
</div>


<div id="align_self_baseline" style="width: 100px; height: 100px; flex-direction:row;">
<div style="width: 50px; height: 50px;align-self: baseline;"></div>
<div style="width: 50px; height: 20px;align-self: baseline;">
<div style="width: 50px; height: 10px;"></div>
</div>
</div>
2 changes: 2 additions & 0 deletions gentest/gentest-cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
YGAlignFlexEnd:{value:'YGAlignFlexEnd'},
YGAlignFlexStart:{value:'YGAlignFlexStart'},
YGAlignStretch:{value:'YGAlignStretch'},

YGAlignBaseline:{value:'YGAlignBaseline'},

YGDirectionInherit:{value:'YGDirectionInherit'},
YGDirectionLTR:{value:'YGDirectionLTR'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ CSEmitter.prototype = Object.create(Emitter.prototype, {
YGAlignFlexEnd:{value:'YogaAlign.FlexEnd'},
YGAlignFlexStart:{value:'YogaAlign.FlexStart'},
YGAlignStretch:{value:'YogaAlign.Stretch'},
YGAlignBaseline:{value:'YogaAlign.Baseline'},

YGDirectionInherit:{value:'YogaDirection.Inherit'},
YGDirectionLTR:{value:'YogaDirection.LTR'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
YGAlignFlexEnd:{value:'YogaAlign.FLEX_END'},
YGAlignFlexStart:{value:'YogaAlign.FLEX_START'},
YGAlignStretch:{value:'YogaAlign.STRETCH'},
YGAlignBaseline:{value:'YogaAlign.BASELINE'},

YGDirectionInherit:{value:'YogaDirection.INHERIT'},
YGDirectionLTR:{value:'YogaDirection.LTR'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
YGAlignFlexEnd:{value:'Yoga.ALIGN_FLEX_END'},
YGAlignFlexStart:{value:'Yoga.ALIGN_FLEX_START'},
YGAlignStretch:{value:'Yoga.ALIGN_STRETCH'},
YGAlignBaseline:{value:'Yoga.ALIGN_BASELINE'},

YGDirectionInherit:{value:'Yoga.DIRECTION_INHERIT'},
YGDirectionLTR:{value:'Yoga.DIRECTION_LTR'},
Expand Down
1 change: 1 addition & 0 deletions gentest/gentest.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ function alignValue(e, value) {
case 'stretch': return e.YGAlignStretch;
case 'flex-start': return e.YGAlignFlexStart;
case 'flex-end': return e.YGAlignFlexEnd;
case 'baseline': return e.YGAlignBaseline;
}
}

Expand Down
4 changes: 3 additions & 1 deletion java/com/facebook/yoga/YogaAlign.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum YogaAlign {
FLEX_START(1),
CENTER(2),
FLEX_END(3),
STRETCH(4);
STRETCH(4),
BASELINE(5);

private int mIntValue;

Expand All @@ -36,6 +37,7 @@ public static YogaAlign fromInt(int value) {
case 2: return CENTER;
case 3: return FLEX_END;
case 4: return STRETCH;
case 5: return BASELINE;
default: throw new IllegalArgumentException("Unkown enum value: " + value);
}
}
Expand Down
Loading