Baseline support
Summary: Added baseline support (see #132) You have the ability for a custom baseline function (```float(*YGBaselineFunc)(YGNodeRef node);```) to return whatever baseline you want. Closes https://github.com/facebook/yoga/pull/317 Reviewed By: splhack Differential Revision: D4385061 Pulled By: emilsjolander fbshipit-source-id: cb8a59a09237c840fa3e21753ab68239997dab0c
This commit is contained in:
committed by
Facebook Github Bot
parent
6d48307c8d
commit
c169a98be6
@@ -17,7 +17,8 @@ public enum YogaAlign {
|
||||
FLEX_START(1),
|
||||
CENTER(2),
|
||||
FLEX_END(3),
|
||||
STRETCH(4);
|
||||
STRETCH(4),
|
||||
BASELINE(5);
|
||||
|
||||
private int mIntValue;
|
||||
|
||||
@@ -36,6 +37,7 @@ public enum YogaAlign {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -169,4 +169,74 @@ public class YGAlignSelfTest {
|
||||
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_align_self_baseline() {
|
||||
final YogaNode root = new YogaNode();
|
||||
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||
root.setWidth(100f);
|
||||
root.setHeight(100f);
|
||||
|
||||
final YogaNode root_child0 = new YogaNode();
|
||||
root_child0.setAlignSelf(YogaAlign.BASELINE);
|
||||
root_child0.setWidth(50f);
|
||||
root_child0.setHeight(50f);
|
||||
root.addChildAt(root_child0, 0);
|
||||
|
||||
final YogaNode root_child1 = new YogaNode();
|
||||
root_child1.setAlignSelf(YogaAlign.BASELINE);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user