Beispiel #1
0
 public static void Append(this YogaNode node, YogaNode child, YogaDecor <YogaNode> childDecor)
 {
     childDecor(child);
     node.Insert(node.Count, child);
 }
Beispiel #2
0
 public static YogaNode Append(this YogaNode node, YogaNode child)
 {
     return(node.Insert(node.Count, child));
 }
Beispiel #3
0
        void Init1()
        {
            YogaConfig config = new YogaConfig();

            _rootNode = new YogaNode(config)
            {
                FlexDirection = YogaFlexDirection.Row,
                Width         = _rootPanel.Width,
                Height        = _rootPanel.Height,
                Padding       = 20,
                AlignItems    = YogaAlign.Center
            };

            YogaNode root_child0 = new YogaNode(config)
            {
                Width      = 100,
                Height     = 100,
                FlexShrink = 1
            };

            _rootNode.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config)
            {
                Width            = 100,
                Height           = 100,
                MarginHorizontal = 20,
                FlexGrow         = 1,
                FlexShrink       = 1
            };

            _rootNode.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config)
            {
                Width      = 100,
                Height     = 100,
                FlexShrink = 1
            };

            _rootNode.Insert(2, root_child2);

            _rootNode.StyleDirection = YogaDirection.LeftToRight;
            _rootNode.CalculateLayout();

            CustomWidgets.Box fb0 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = root_child0.ToLayoutInstance()
            };
            _rootPanel.Add(fb0);

            CustomWidgets.Box fb1 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Red, LayoutInstance = root_child1.ToLayoutInstance()
            };
            _rootPanel.Add(fb1);

            CustomWidgets.Box fb2 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = root_child2.ToLayoutInstance()
            };
            _rootPanel.Add(fb2);

            _rootPanel.UpdateLayout();
        }
Beispiel #4
0
        void Init2()
        {
            YogaConfig config = new YogaConfig();

            _rootNode = new YogaNode(config)
            {
                FlexDirection = YogaFlexDirection.Column,
                Width         = _rootPanel.Width,
                Height        = _rootPanel.Height,
                Padding       = 20,
                AlignItems    = YogaAlign.Stretch
            };

            var _root_child0 = new YogaNode(config)
            {
                FlexDirection  = YogaFlexDirection.Row,
                Width          = _rootNode.Width,
                Height         = 100,
                AlignItems     = YogaAlign.Center,
                AlignSelf      = YogaAlign.Center,
                Flex           = 1,
                FlexShrink     = 1,
                StyleDirection = YogaDirection.RightToLeft
            };

            _rootNode.Insert(0, _root_child0);

            YogaNode c1r0_child0 = new YogaNode(config)
            {
                Width      = 100,
                Height     = 100,
                FlexShrink = 1
            };

            _root_child0.Insert(0, c1r0_child0);

            YogaNode c1r0_child1 = new YogaNode(config)
            {
                Width            = 100,
                Height           = 100,
                MarginHorizontal = 20,
                FlexGrow         = 1,
                FlexShrink       = 1
            };

            _root_child0.Insert(1, c1r0_child1);

            YogaNode c1r0_child2 = new YogaNode(config)
            {
                Width      = 100,
                Height     = 100,
                FlexShrink = 1
            };

            _root_child0.Insert(2, c1r0_child2);

            YogaNode root_child1 = new YogaNode(config)
            {
                Width            = 100,
                Height           = 100,
                MarginHorizontal = 20,
                FlexGrow         = 1,
                FlexShrink       = 1
            };

            _rootNode.Insert(1, root_child1);

            //YogaNode root_child2 = new YogaNode(config);
            //root_child2.Width = 100;
            //root_child2.Height = 100;
            //root_child2.FlexShrink = 1;
            //root.Insert(2, root_child2);

            _rootNode.StyleDirection = YogaDirection.LeftToRight;
            _rootNode.CalculateLayout();

            CustomWidgets.Box fb0 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Yellow, LayoutInstance = _root_child0.ToLayoutInstance()
            };
            _rootPanel.Add(fb0);

            CustomWidgets.Box fb0_child0 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child0.ToLayoutInstance()
            };
            fb0.Add(fb0_child0);

            CustomWidgets.Box fb0_child1 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child1.ToLayoutInstance()
            };
            fb0.Add(fb0_child1);

            CustomWidgets.Box fb0_child2 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Blue, LayoutInstance = c1r0_child2.ToLayoutInstance()
            };
            fb0.Add(fb0_child2);

            CustomWidgets.Box fb1 = new CustomWidgets.Box(100, 100)
            {
                BackColor = PixelFarm.Drawing.Color.Red, LayoutInstance = root_child1.ToLayoutInstance()
            };
            _rootPanel.Add(fb1);

            _rootPanel.UpdateLayout();
        }
Beispiel #5
0
        /// <summary>
        /// Insert a child at the given index.
        /// </summary>
        /// <param name="child">The child.</param>
        /// <param name="index">The index.</param>
        public void AddChildAt(ReactShadowNode child, int index)
        {
            if (child._parent != null)
            {
                throw new InvalidOperationException(
                          "Tried to add child that already has a parent! Remove it from its parent first.");
            }

            if (IsDelegatedLayout && (ChildCount > 0 || index != 0))
            {
                throw new InvalidOperationException(
                          "Cannot add more than one child to a CSS node that delegates the layouting!");
            }

            if (_children == null)
            {
                _children = new List <ReactShadowNode>(4);
            }

            _children.Insert(index, child);
            child._parent = this;

            // If a CSS node has measure defined, the layout algorithm will not visit its children. Even
            // more, it asserts that you don't add children to nodes with measure functions.
            if (_yogaNode != null && !_yogaNode.IsMeasureDefined)
            {
                var childYogaNode = child._yogaNode;
                if (childYogaNode == null)
                {
                    throw new InvalidOperationException(
                              "Cannot add a child that doesn't have a CSS node to a node without a measure function!");
                }

                if (IsDelegatedLayout)
                {
                    // Piggyback on child's Yoga node by keeping a reference to it
                    _initialYogaNode = _yogaNode;
                    _yogaNode        = child._yogaNode;

                    // If parent has already been told about a Yoga node, make it aware of the new one
                    if (_parent != null)
                    {
                        _parent.ReplaceYogaNode(_initialYogaNode, _yogaNode);
                    }

                    _hasChildLayoutChanged = true;
                }
                else
                {
                    _yogaNode.Insert(index, childYogaNode);
                }
            }

            MarkUpdated();

            var increase = child._isLayoutOnly ? child._totalNativeChildren : 1;

            _totalNativeChildren += increase;

            UpdateNativeChildrenCountInParent(increase);
        }