Ejemplo n.º 1
0
        public void Test_margin_end()
        {
            YogaNode root = new YogaNode();

            root.FlexDirection  = YogaFlexDirection.Row;
            root.JustifyContent = YogaJustify.FlexEnd;
            root.Width          = 100f;
            root.Height         = 100f;

            YogaNode root_child0 = new YogaNode();

            root_child0.SetMargin(YogaEdge.End, 10f);
            root_child0.Width = 10f;
            root.Insert(0, root_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(80f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(10f, root_child0.LayoutWidth);
            Assert.AreEqual(100f, root_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(10f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(10f, root_child0.LayoutWidth);
            Assert.AreEqual(100f, root_child0.LayoutHeight);
        }
Ejemplo n.º 2
0
        public void Test_margin_and_stretch_row()
        {
            YogaNode root = new YogaNode();

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 100f;
            root.Height        = 100f;

            YogaNode root_child0 = new YogaNode();

            root_child0.FlexGrow = 1f;
            root_child0.SetMargin(YogaEdge.Top, 10f);
            root.Insert(0, root_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(10f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(90f, root_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(0f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(90f, root_child0.LayoutHeight);
        }
Ejemplo n.º 3
0
        public static YogaNode Create(
            YogaDirection?styleDirection    = null,
            YogaFlexDirection?flexDirection = null,
            YogaJustify?justifyContent      = null,
            YogaAlign?alignContent          = null,
            YogaAlign?alignItems            = null,
            YogaAlign?alignSelf             = null,
            YogaPositionType?positionType   = null,
            YogaWrap?wrap         = null,
            YogaOverflow?overflow = null,
            float?flex            = null,
            float?flexGrow        = null,
            float?flexShrink      = null,
            float?flexBasis       = null,
            Spacing position      = null,
            Spacing margin        = null,
            Spacing padding       = null,
            Spacing border        = null,
            float?width           = null,
            float?height          = null,
            float?maxWidth        = null,
            float?maxHeight       = null,
            float?minWidth        = null,
            float?minHeight       = null)
        {
            YogaNode node = new YogaNode();

            if (styleDirection.HasValue)
            {
                node.StyleDirection = styleDirection.Value;
            }

            if (flexDirection.HasValue)
            {
                node.FlexDirection = flexDirection.Value;
            }

            if (justifyContent.HasValue)
            {
                node.JustifyContent = justifyContent.Value;
            }

            if (alignContent.HasValue)
            {
                node.AlignContent = alignContent.Value;
            }

            if (alignItems.HasValue)
            {
                node.AlignItems = alignItems.Value;
            }

            if (alignSelf.HasValue)
            {
                node.AlignSelf = alignSelf.Value;
            }

            if (positionType.HasValue)
            {
                node.PositionType = positionType.Value;
            }

            if (wrap.HasValue)
            {
                node.Wrap = wrap.Value;
            }

            if (overflow.HasValue)
            {
                node.Overflow = overflow.Value;
            }

            if (flex.HasValue)
            {
                node.Flex = flex.Value;
            }

            if (flexGrow.HasValue)
            {
                node.FlexGrow = flexGrow.Value;
            }

            if (flexShrink.HasValue)
            {
                node.FlexShrink = flexShrink.Value;
            }

            if (flexBasis.HasValue)
            {
                node.FlexBasis = flexBasis.Value;
            }

            if (position != null)
            {
                if (position.Top.HasValue)
                {
                    node.SetPosition(YogaEdge.Top, position.Top.Value);
                }

                if (position.Bottom.HasValue)
                {
                    node.SetPosition(YogaEdge.Bottom, position.Bottom.Value);
                }

                if (position.Left.HasValue)
                {
                    node.SetPosition(YogaEdge.Left, position.Left.Value);
                }

                if (position.Right.HasValue)
                {
                    node.SetPosition(YogaEdge.Right, position.Right.Value);
                }
            }

            if (margin != null)
            {
                if (margin.Top.HasValue)
                {
                    node.SetMargin(YogaEdge.Top, margin.Top.Value);
                }

                if (margin.Bottom.HasValue)
                {
                    node.SetMargin(YogaEdge.Bottom, margin.Bottom.Value);
                }

                if (margin.Left.HasValue)
                {
                    node.SetMargin(YogaEdge.Left, margin.Left.Value);
                }

                if (margin.Right.HasValue)
                {
                    node.SetMargin(YogaEdge.Right, margin.Right.Value);
                }
            }

            if (padding != null)
            {
                if (padding.Top.HasValue)
                {
                    node.SetPadding(YogaEdge.Top, padding.Top.Value);
                }

                if (padding.Bottom.HasValue)
                {
                    node.SetPadding(YogaEdge.Bottom, padding.Bottom.Value);
                }

                if (padding.Left.HasValue)
                {
                    node.SetPadding(YogaEdge.Left, padding.Left.Value);
                }

                if (padding.Right.HasValue)
                {
                    node.SetPadding(YogaEdge.Right, padding.Right.Value);
                }
            }

            if (border != null)
            {
                if (border.Top.HasValue)
                {
                    node.SetBorder(YogaEdge.Top, border.Top.Value);
                }

                if (border.Bottom.HasValue)
                {
                    node.SetBorder(YogaEdge.Bottom, border.Bottom.Value);
                }

                if (border.Left.HasValue)
                {
                    node.SetBorder(YogaEdge.Left, border.Left.Value);
                }

                if (border.Right.HasValue)
                {
                    node.SetBorder(YogaEdge.Right, border.Right.Value);
                }
            }

            if (width.HasValue)
            {
                node.Width = width.Value;
            }

            if (height.HasValue)
            {
                node.Height = height.Value;
            }

            if (minWidth.HasValue)
            {
                node.MinWidth = minWidth.Value;
            }

            if (minHeight.HasValue)
            {
                node.MinHeight = minHeight.Value;
            }

            if (maxWidth.HasValue)
            {
                node.MaxWidth = maxWidth.Value;
            }

            if (maxHeight.HasValue)
            {
                node.MaxHeight = maxHeight.Value;
            }

            return(node);
        }
Ejemplo n.º 4
0
        public void Test_absolute_layout_within_border()
        {
            YogaNode root = new YogaNode();

            root.SetMargin(YogaEdge.Left, 10f);
            root.SetMargin(YogaEdge.Top, 10f);
            root.SetMargin(YogaEdge.Right, 10f);
            root.SetMargin(YogaEdge.Bottom, 10f);
            root.SetPadding(YogaEdge.Left, 10f);
            root.SetPadding(YogaEdge.Top, 10f);
            root.SetPadding(YogaEdge.Right, 10f);
            root.SetPadding(YogaEdge.Bottom, 10f);
            root.SetBorder(YogaEdge.Left, 10f);
            root.SetBorder(YogaEdge.Top, 10f);
            root.SetBorder(YogaEdge.Right, 10f);
            root.SetBorder(YogaEdge.Bottom, 10f);
            root.Width  = 100f;
            root.Height = 100f;

            YogaNode root_child0 = new YogaNode();

            root_child0.PositionType = YogaPositionType.Absolute;
            root_child0.SetPosition(YogaEdge.Left, 0f);
            root_child0.SetPosition(YogaEdge.Top, 0f);
            root_child0.Width  = 50f;
            root_child0.Height = 50f;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode();

            root_child1.PositionType = YogaPositionType.Absolute;
            root_child1.SetPosition(YogaEdge.Right, 0f);
            root_child1.SetPosition(YogaEdge.Bottom, 0f);
            root_child1.Width  = 50f;
            root_child1.Height = 50f;
            root.Insert(1, root_child1);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(10f, root.LayoutX);
            Assert.AreEqual(10f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(10f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(50f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

            Assert.AreEqual(40f, root_child1.LayoutX);
            Assert.AreEqual(40f, root_child1.LayoutY);
            Assert.AreEqual(50f, root_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child1.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(10f, root.LayoutX);
            Assert.AreEqual(10f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(10f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(50f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

            Assert.AreEqual(40f, root_child1.LayoutX);
            Assert.AreEqual(40f, root_child1.LayoutY);
            Assert.AreEqual(50f, root_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child1.LayoutHeight);
        }