Ejemplo n.º 1
0
        private static void Main()
        {
            var parent = new YogaNode
            {
                Width          = YogaValue.Point(100),
                Height         = YogaValue.Point(100),
                FlexDirection  = YogaFlexDirection.Row,
                JustifyContent = YogaJustify.SpaceAround,
                AlignItems     = YogaAlign.Center
            };

            var childA = new YogaNode
            {
                Width  = YogaValue.Point(25),
                Height = YogaValue.Point(50)
            };

            var childB = new YogaNode
            {
                Width     = YogaValue.Point(25),
                Height    = YogaValue.Point(50),
                AlignSelf = YogaAlign.FlexEnd
            };

            parent.AddChild(childA);
            parent.AddChild(childB);

            parent.CalculateLayout();

            Console.WriteLine($"{parent.LayoutX} {parent.LayoutY} {parent.LayoutWidth} {parent.LayoutHeight}");
            Console.WriteLine($"{childA.LayoutX} {childA.LayoutY} {childA.LayoutWidth} {childA.LayoutHeight}");
            Console.WriteLine($"{childB.LayoutX} {childB.LayoutY} {childB.LayoutWidth} {childB.LayoutHeight}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create the UI Panel
        /// </summary>
        private void CreateUIPanels()
        {
            // create child nodes for that we add to root.
            YogaNode panel1 = new YogaNode()
            {
                Width  = 50,
                Height = 50,
                Margin = 10
            };

            m_Root.AddChild(panel1);

            YogaNode panel2 = new YogaNode()
            {
                Width  = 50,
                Height = 50,
                Margin = 10
            };

            m_Root.AddChild(panel2);

            YogaNode panel3 = new YogaNode()
            {
                Width  = 50,
                Height = 50,
                Margin = 10
            };

            m_Root.AddChild(panel3);
        }
Ejemplo n.º 3
0
    protected override void OnUpdate()
    {
        Entities.ForEach((Entity e, ref UiRenderBounds uiRenderBounds) =>
        {
            if (!nodes.TryGetValue(e, out var yn))
            {
                var yogaNode = new YogaNode(YogaConfig.Default)
                {
                    Data   = e,
                    Margin = YogaValue.Point(10),
                    Flex   = 1,
                };
                nodes.Add(e, yogaNode);
                _root.AddChild(yogaNode);
            }
        });

//        YogaNode n = new YogaNode(YogaConfig.Default)
//        {
//            Data = "root",
//            Display = YogaDisplay.Flex,
//            FlexDirection = YogaFlexDirection.Column,
//        };
//        n.Width = YogaValue.Point(400);
//        n.Height = YogaValue.Point(200);
//        n.AddChild(new YogaNode(YogaConfig.Default)
//        {
//            Data = "child",
//            Margin = YogaValue.Point(10),
//            Flex = 1,
////            Width = YogaValue.Percent(100),
////            Height = YogaValue.Percent(100),
//        });n.AddChild(new YogaNode(YogaConfig.Default)
//        {
//            Data = "child",
//            Margin = YogaValue.Point(10),
//            Flex = 1,
////            Width = YogaValue.Percent(100),
////            Height = YogaValue.Percent(100),
//        });
        var r = Screen.safeArea;

        _root.Width  = YogaValue.Point(r.width);
        _root.Height = YogaValue.Point(r.height);
        _root.CalculateLayout(Single.NaN, Single.NaN);
//        Dump(_root, 0);
        Entities.ForEach((Entity e, ref UiRenderBounds uiRenderBounds) =>
        {
            var yn     = nodes[e];
            var layout = yn.GetLayoutRect();
            uiRenderBounds.Value.Center  = new float3(layout.center.x, layout.center.y, 0);
            uiRenderBounds.Value.Extents = new float3(layout.width / 2, layout.height / 2, 0);
        });

        void Dump(YogaNode yn, int indent)
        {
            Debug.Log($"{new string(' ', 2 * indent)}{yn.Data}: {yn.GetLayoutRect()}");
            foreach (YogaNode child in yn)
            {
                Dump(child, indent + 1);
            }
        }
    }