public void exactly_measure_stretched_child_row() { _MeasureConstraintList constraintList = new _MeasureConstraintList(); YGNode root = YGNodeNew(); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); // root_child0.setContext(&constraintList); root_child0.setContext(constraintList); root_child0.setMeasureFunc(_measure); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, constraintList.Count); Assert.AreEqual(100, constraintList[0].height); Assert.AreEqual(YGMeasureMode.Exactly, constraintList[0].heightMode); // free(constraintList.constraints); }
public void flex_child_with_flex_basis() { var constraintList = new _MeasureConstraintList(); YGNode root = YGNodeNew(); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); YGNodeStyleSetFlexGrow(root_child0, 1); YGNodeStyleSetFlexBasis(root_child0, 0); root_child0.setContext(constraintList); root_child0.setMeasureFunc(_measure); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, constraintList.Count); Assert.AreEqual(100, constraintList[0].height); Assert.AreEqual(YGMeasureMode.Exactly, constraintList[0].heightMode); // free(constraintList.constraints); }
public void overflow_scroll_row() { var constraintList = new _MeasureConstraintList(); YGNode root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetOverflow(root, YGOverflow.Scroll); YGNodeStyleSetHeight(root, 100); YGNodeStyleSetWidth(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setContext(constraintList); root_child0.setMeasureFunc(_measure); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, constraintList.Count); Assert.IsTrue(YogaIsUndefined(constraintList[0].width)); Assert.AreEqual(YGMeasureMode.Undefined, constraintList[0].widthMode); Assert.AreEqual(100, constraintList[0].height); Assert.AreEqual(YGMeasureMode.AtMost, constraintList[0].heightMode); // free(constraintList.constraints); }
TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node() { YGNode root = YGNodeNew(); YGNode root_child0 = YGNodeNew(); YGNodeInsertChild(root, root_child0, 0); ASSERT_DEATH(root.setMeasureFunc(_measure), "Cannot set measure function.*"); }
public void at_most_main_axis_row() { var constraintList = new _MeasureConstraintList(); YGNode root = YGNodeNew(); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setContext(constraintList); root_child0.setMeasureFunc(_measure); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, constraintList.Count); Assert.AreEqual(100, constraintList[0].width); Assert.AreEqual(YGMeasureMode.AtMost, constraintList[0].widthMode); // free(constraintList.constraints); }
[Test] public void remeasure_with_already_measured_value_smaller_but_still_float_equal() { YGNode root = YGNodeNew(); YGNodeStyleSetWidth(root, 288f); YGNodeStyleSetHeight(root, 288f); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNode root_child0 = YGNodeNew(); YGNodeStyleSetPadding(root_child0, YGEdge.All, 2.88f); YGNodeStyleSetFlexDirection(root_child0, YGFlexDirection.Row); YGNodeInsertChild(root, root_child0, 0); YGNode root_child0_child0 = YGNodeNew(); root_child0_child0.setContext(0); root_child0_child0.setMeasureFunc(_measure_84_49); YGNodeInsertChild(root_child0, root_child0_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0_child0.getContext()); }
public void dont_measure_when_min_equals_max() { YGNode root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measure); YGNodeStyleSetMinWidth(root_child0, 10); YGNodeStyleSetMaxWidth(root_child0, 10); YGNodeStyleSetMinHeight(root_child0, 10); YGNodeStyleSetMaxHeight(root_child0, 10); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, (int)root_child0.getContext()); Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetHeight(root_child0)); }
public void can_nullify_measure_func_on_any_node() { YGNode root = YGNodeNew(); YGNodeInsertChild(root, YGNodeNew(), 0); root.setMeasureFunc(null); Assert.IsTrue(root.getMeasure() == null); }
TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func() { YGNode root = YGNodeNew(); root.setMeasureFunc(_measure); YGNode root_child0 = YGNodeNew(); ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); YGNodeFree(root_child0); }
[Test] public void remeasure_with_same_exact_width_larger_than_needed_height() { YGNode root = YGNodeNew(); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measureMin); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, 100, 100, YGDirection.LTR); YGNodeCalculateLayout(root, 100, 50, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0.getContext()); }
[Test] public void rounding_feature_with_custom_measure_func_ceil() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNode root_child0 = YGNodeNewWithConfig(config); root_child0.setMeasureFunc(_measureCeil); YGNodeInsertChild(root, root_child0, 0); YGConfigSetPointScaleFactor(config, 1.0f); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(11, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(11, YGNodeLayoutGetHeight(root_child0)); }
[Test] public void remeasure_with_atmost_computed_width_undefined_height() { YGNode root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measureMin); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, 100, YGValue.YGUndefined, YGDirection.LTR); YGNodeCalculateLayout(root, 10, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0.getContext()); }
public void measure_not_enough_size_should_wrap() { YGNode root = YGNodeNew(); YGNodeStyleSetWidth(root, 55); YGNode root_child0 = YGNodeNew(); YGNodeStyleSetAlignSelf(root_child0, YGAlign.FlexStart); // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); root_child0.setMeasureFunc(_simulate_wrapping_text); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(32, YGNodeLayoutGetHeight(root_child0)); }
public void cant_call_negative_measure_horizontal() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetWidth(root, 10); YGNodeStyleSetHeight(root, 20); YGNode root_child0 = YGNodeNewWithConfig(config); root_child0.setMeasureFunc(_measure_assert_negative); YGNodeStyleSetMargin(root_child0, YGEdge.Start, 20); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); }
[Test] public void remeasure_with_computed_width_larger_than_needed_height() { YGNode root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measureMin); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, 100, 100, YGDirection.LTR); YGNodeStyleSetAlignItems(root, YGAlign.Stretch); YGNodeCalculateLayout(root, 10, 50, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0.getContext()); }
public void measure_absolute_child_with_no_constraints() { YGNode root = YGNodeNew(); YGNode root_child0 = YGNodeNew(); YGNodeInsertChild(root, root_child0, 0); YGNode root_child0_child0 = YGNodeNew(); YGNodeStyleSetPositionType(root_child0_child0, YGPositionType.Absolute); root_child0_child0.setContext(0); root_child0_child0.setMeasureFunc(_measure); YGNodeInsertChild(root_child0, root_child0_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0_child0.getContext()); }
[Test] public void rounding_feature_with_custom_measure_and_fractial_matching_scale() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNode root_child0 = YGNodeNewWithConfig(config); YGNodeStyleSetPosition(root_child0, YGEdge.Left, 73.625f); root_child0.setMeasureFunc(_measureFractial); YGNodeInsertChild(root, root_child0, 0); YGConfigSetPointScaleFactor(config, 2.0f); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0.5, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(0.5, YGNodeLayoutGetHeight(root_child0)); Assert.AreEqual(73.5, YGNodeLayoutGetLeft(root_child0)); }
public void dont_measure_single_grow_shrink_child() { YGNode root = YGNodeNew(); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measure); YGNodeStyleSetFlexGrow(root_child0, 1); YGNodeStyleSetFlexShrink(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, (int)root_child0.getContext()); }
public void measure_flex_direction_row_and_padding() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetPadding(root, YGEdge.Left, 25); YGNodeStyleSetPadding(root, YGEdge.Top, 25); YGNodeStyleSetPadding(root, YGEdge.Right, 25); YGNodeStyleSetPadding(root, YGEdge.Bottom, 25); YGNodeStyleSetWidth(root, 50); YGNodeStyleSetHeight(root, 50); YGNode root_child0 = YGNodeNewWithConfig(config); root_child0.setMeasureFunc(_simulate_wrapping_text); // YGNodeSetMeasureFunc(root_child0, _simulate_wrapping_text); YGNodeInsertChild(root, root_child0, 0); YGNode root_child1 = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(root_child1, 5); YGNodeStyleSetHeight(root_child1, 5); YGNodeInsertChild(root, root_child1, 1); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, YGNodeLayoutGetLeft(root)); Assert.AreEqual(0, YGNodeLayoutGetTop(root)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root)); Assert.AreEqual(50, YGNodeLayoutGetHeight(root)); Assert.AreEqual(25, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(25, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetHeight(root_child0)); Assert.AreEqual(75, YGNodeLayoutGetLeft(root_child1)); Assert.AreEqual(25, YGNodeLayoutGetTop(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetWidth(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetHeight(root_child1)); }
[Test] public void measure_once_single_flexible_child() { YGNode root = YGNodeNew(); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setContext(0); root_child0.setMeasureFunc(_measureMax); YGNodeStyleSetFlexGrow(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(1, (int)root_child0.getContext()); }
public void measure_nodes_with_margin_auto_and_stretch() { YGNode root = YGNodeNew(); YGNodeStyleSetWidth(root, 500); YGNodeStyleSetHeight(root, 500); YGNode root_child0 = YGNodeNew(); root_child0.setMeasureFunc(_measure); YGNodeStyleSetMarginAuto(root_child0, YGEdge.Left); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(490, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetHeight(root_child0)); }
[Test] public void aspect_ratio_with_measure_func() { YGNode root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 100); YGNode root_child0 = YGNodeNew(); root_child0.setMeasureFunc(_measure); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetHeight(root_child0)); }
public void percent_with_text_node() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetJustifyContent(root, YGJustify.SpaceBetween); YGNodeStyleSetAlignItems(root, YGAlign.Center); YGNodeStyleSetWidth(root, 100); YGNodeStyleSetHeight(root, 80); YGNode root_child0 = YGNodeNewWithConfig(config); YGNodeInsertChild(root, root_child0, 0); YGNode root_child1 = YGNodeNewWithConfig(config); root_child1.setMeasureFunc(_measure_90_10); YGNodeStyleSetMaxWidthPercent(root_child1, 50); YGNodeStyleSetPaddingPercent(root_child1, YGEdge.Top, 50); YGNodeInsertChild(root, root_child1, 1); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, YGNodeLayoutGetLeft(root)); Assert.AreEqual(0, YGNodeLayoutGetTop(root)); Assert.AreEqual(100, YGNodeLayoutGetWidth(root)); Assert.AreEqual(80, YGNodeLayoutGetHeight(root)); Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(40, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetHeight(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetLeft(root_child1)); Assert.AreEqual(15, YGNodeLayoutGetTop(root_child1)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child1)); Assert.AreEqual(50, YGNodeLayoutGetHeight(root_child1)); }
public void measure_with_fixed_size() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNodeStyleSetMargin(root, YGEdge.Top, 20); YGNodeStyleSetPadding(root, YGEdge.All, 25); YGNodeStyleSetWidth(root, 50); YGNodeStyleSetHeight(root, 50); YGNode root_child0 = YGNodeNewWithConfig(config); root_child0.setMeasureFunc(_simulate_wrapping_text); YGNodeStyleSetWidth(root_child0, 10); YGNodeStyleSetHeight(root_child0, 10); YGNodeInsertChild(root, root_child0, 0); YGNode root_child1 = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(root_child1, 5); YGNodeStyleSetHeight(root_child1, 5); YGNodeInsertChild(root, root_child1, 1); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, YGNodeLayoutGetLeft(root)); Assert.AreEqual(20, YGNodeLayoutGetTop(root)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root)); Assert.AreEqual(50, YGNodeLayoutGetHeight(root)); Assert.AreEqual(25, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(25, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(10, YGNodeLayoutGetHeight(root_child0)); Assert.AreEqual(25, YGNodeLayoutGetLeft(root_child1)); Assert.AreEqual(35, YGNodeLayoutGetTop(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetWidth(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetHeight(root_child1)); }
public void measure_flex_direction_row_no_padding_align_items_flexstart() { YGConfig config = YGConfigNew(); YGNode root = YGNodeNewWithConfig(config); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row); YGNodeStyleSetMargin(root, YGEdge.Top, 20); YGNodeStyleSetWidth(root, 50); YGNodeStyleSetHeight(root, 50); YGNodeStyleSetAlignItems(root, YGAlign.FlexStart); YGNode root_child0 = YGNodeNewWithConfig(config); root_child0.setMeasureFunc(_simulate_wrapping_text); YGNodeInsertChild(root, root_child0, 0); YGNode root_child1 = YGNodeNewWithConfig(config); YGNodeStyleSetWidth(root_child1, 5); YGNodeStyleSetHeight(root_child1, 5); YGNodeInsertChild(root, root_child1, 1); YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(0, YGNodeLayoutGetLeft(root)); Assert.AreEqual(20, YGNodeLayoutGetTop(root)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root)); Assert.AreEqual(50, YGNodeLayoutGetHeight(root)); Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(32, YGNodeLayoutGetHeight(root_child0)); Assert.AreEqual(50, YGNodeLayoutGetLeft(root_child1)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetWidth(root_child1)); Assert.AreEqual(5, YGNodeLayoutGetHeight(root_child1)); }
public void measure_zero_space_should_grow() { YGNode root = YGNodeNew(); YGNodeStyleSetHeight(root, 200); YGNodeStyleSetFlexDirection(root, YGFlexDirection.Column); YGNodeStyleSetFlexGrow(root, 0); YGNode root_child0 = YGNodeNew(); YGNodeStyleSetFlexDirection(root_child0, YGFlexDirection.Column); YGNodeStyleSetPadding(root_child0, YGEdge.All, 100); root_child0.setContext(0); root_child0.setMeasureFunc(_measure); YGNodeInsertChild(root, root_child0, 0); YGNodeCalculateLayout(root, 282, YGValue.YGUndefined, YGDirection.LTR); Assert.AreEqual(282, YGNodeLayoutGetWidth(root_child0)); Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0)); }