Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        static void _dirtied(YGNode node)
        {
            int dirtiedCount = (int)node.getContext();

            dirtiedCount++;
            node.setContext(dirtiedCount);
        }
Example #4
0
        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] 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());
        }
Example #6
0
        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);
        }
Example #7
0
        [Test] public void dirtied_propagation()
        {
            YGNode root = YGNodeNew();

            YGNodeStyleSetAlignItems(root, YGAlign.FlexStart);
            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YGNode root_child0 = YGNodeNew();

            YGNodeStyleSetWidth(root_child0, 50);
            YGNodeStyleSetHeight(root_child0, 20);
            YGNodeInsertChild(root, root_child0, 0);

            YGNode root_child1 = YGNodeNew();

            YGNodeStyleSetWidth(root_child1, 50);
            YGNodeStyleSetHeight(root_child1, 20);
            YGNodeInsertChild(root, root_child1, 1);

            YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR);

            root.setContext(0);
            root.setDirtiedFunc(_dirtied);

            Assert.AreEqual(0, (int)root.getContext());

            // `_dirtied` MUST be called for the first time.
            root_child0.markDirtyAndPropogate();
            Assert.AreEqual(1, (int)root.getContext());

            // `_dirtied` must NOT be called for the second time.
            root_child0.markDirtyAndPropogate();
            Assert.AreEqual(1, (int)root.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));
        }
Example #9
0
        [Test] public void align_baseline_customer_func()
        {
            YGNode root = YGNodeNew();

            YGNodeStyleSetFlexDirection(root, YGFlexDirection.Row);
            YGNodeStyleSetAlignItems(root, YGAlign.Baseline);
            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YGNode root_child0 = YGNodeNew();

            YGNodeStyleSetWidth(root_child0, 50);
            YGNodeStyleSetHeight(root_child0, 50);
            YGNodeInsertChild(root, root_child0, 0);

            YGNode root_child1 = YGNodeNew();

            YGNodeStyleSetWidth(root_child1, 50);
            YGNodeStyleSetHeight(root_child1, 20);
            YGNodeInsertChild(root, root_child1, 1);

            float  baselineValue      = 10;
            YGNode root_child1_child0 = YGNodeNew();

            root_child1_child0.setContext(baselineValue);
            YGNodeStyleSetWidth(root_child1_child0, 50);
            root_child1_child0.setBaselineFunc(_baseline);
            YGNodeStyleSetHeight(root_child1_child0, 20);
            YGNodeInsertChild(root_child1, root_child1_child0, 0);
            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(100, YGNodeLayoutGetHeight(root));

            Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child0));
            Assert.AreEqual(0, YGNodeLayoutGetTop(root_child0));
            Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child0));
            Assert.AreEqual(50, YGNodeLayoutGetHeight(root_child0));

            Assert.AreEqual(50, YGNodeLayoutGetLeft(root_child1));
            Assert.AreEqual(40, YGNodeLayoutGetTop(root_child1));
            Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child1));
            Assert.AreEqual(20, YGNodeLayoutGetHeight(root_child1));

            Assert.AreEqual(0, YGNodeLayoutGetLeft(root_child1_child0));
            Assert.AreEqual(0, YGNodeLayoutGetTop(root_child1_child0));
            Assert.AreEqual(50, YGNodeLayoutGetWidth(root_child1_child0));
            Assert.AreEqual(20, YGNodeLayoutGetHeight(root_child1_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 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());
        }
        [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());
        }
        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());
        }
        [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());
        }
Example #16
0
        [Test] public void dirtied_hierarchy()
        {
            YGNode root = YGNodeNew();

            YGNodeStyleSetAlignItems(root, YGAlign.FlexStart);
            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YGNode root_child0 = YGNodeNew();

            YGNodeStyleSetWidth(root_child0, 50);
            YGNodeStyleSetHeight(root_child0, 20);
            YGNodeInsertChild(root, root_child0, 0);

            YGNode root_child1 = YGNodeNew();

            YGNodeStyleSetWidth(root_child1, 50);
            YGNodeStyleSetHeight(root_child1, 20);
            YGNodeInsertChild(root, root_child1, 1);

            YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR);

            root_child0.setContext(0);
            root_child0.setDirtiedFunc(_dirtied);

            Assert.AreEqual(0, (int)root_child0.getContext());

            // `_dirtied` must NOT be called for descendants.
            root.markDirtyAndPropogate();
            Assert.AreEqual(0, (int)root_child0.getContext());

            // `_dirtied` must NOT be called for the sibling node.
            root_child1.markDirtyAndPropogate();
            Assert.AreEqual(0, (int)root_child0.getContext());

            // `_dirtied` MUST be called in case of explicit dirtying.
            root_child0.markDirtyAndPropogate();
            Assert.AreEqual(1, (int)root_child0.getContext());
        }
        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));
        }
Example #18
0
        [Test] public void dirtied()
        {
            YGNode root = YGNodeNew();

            YGNodeStyleSetAlignItems(root, YGAlign.FlexStart);
            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YGNodeCalculateLayout(root, YGValue.YGUndefined, YGValue.YGUndefined, YGDirection.LTR);

            //int dirtiedCount = 0;
            root.setContext(0);
            root.setDirtiedFunc(_dirtied);

            Assert.AreEqual(0, (int)root.getContext());

            // `_dirtied` MUST be called in case of explicit dirtying.
            root.setDirty(true);
            Assert.AreEqual(1, (int)root.getContext());

            // `_dirtied` MUST be called ONCE.
            root.setDirty(true);
            Assert.AreEqual(1, (int)root.getContext());
        }