예제 #1
0
        public void logger_node_with_percentage_absolute_position_and_margin()
        {
            YogaConfig config = new YogaConfig {
                LoggerFunc = _unmanagedLogger
            };

            YogaNode root = Node(config,
                                 positionType: PositionType.Absolute,
                                 width: 50.Percent(),
                                 height: 75.Percent(),
                                 flex: 1,
                                 margin: new Edges(right: 10, left: YogaValue.Auto));

            YogaArrange.CalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            new YogaNodePrint(PrintOptions.Layout | PrintOptions.Children | PrintOptions.Style)
            .Output(root);

            string expected = "<div layout=\"width: 0; height: 0; top: 0; left: 0; margin: (0, 0, 10, 0);\" style=\"flex: 1; margin-left: auto; margin-right: 10px; width: 50%; height: 75%; position: absolute; \" ></div>";

            Assert.AreEqual(expected, _writeBuffer.ToString());
        }
예제 #2
0
        public void aspect_ratio_both_dimensions_defined_column()
        {
            var root = new YogaNode();

            root.AlignItems = AlignType.FlexStart;
            root.Width      = 100;
            root.Height     = 100;

            var root_child0 = new YogaNode();

            root_child0.Width       = 100;
            root_child0.Height      = 50;
            root_child0.AspectRatio = 1;
            root.Children.Add(root_child0);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(50, root_child0.Layout.Width);
            Assert.AreEqual(50, root_child0.Layout.Height);
        }
예제 #3
0
        static YogaSize MeasureView(YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            var constrainedWidth  = (widthMode == YogaMeasureMode.Undefined) ? float.MaxValue : width;
            var constrainedHeight = (heightMode == YogaMeasureMode.Undefined) ? float.MaxValue : height;

            NativeView view = null;

            if (YogaKit.Bridges.ContainsKey(node))
            {
                view = YogaKit.Bridges[node] as NativeView;
            }

            float sizeThatFitsWidth  = 0;
            float sizeThatFitsHeight = 0;

            MeasureNativeView(view, constrainedWidth, constrainedHeight, out sizeThatFitsWidth, out sizeThatFitsHeight);

            var finalWidth  = SanitizeMeasurement(constrainedWidth, sizeThatFitsWidth, widthMode);
            var finalHeight = SanitizeMeasurement(constrainedHeight, sizeThatFitsHeight, heightMode);

            return(MeasureOutput.Make(finalWidth, finalHeight));
        }
예제 #4
0
        public void padding_flex_child()
        {
            var config = new YogaConfig();

            var root = new YogaNode(config);

            root.Padding = new Edges(10, 10, 10, 10);
            root.Width   = 100;
            root.Height  = 100;

            var root_child0 = new YogaNode(config);

            root_child0.FlexGrow = 1;
            root_child0.Width    = 10;
            root.Children.Add(root_child0);
            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(100, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(10, root_child0.Layout.Position.Left);
            Assert.AreEqual(10, root_child0.Layout.Position.Top);
            Assert.AreEqual(10, root_child0.Layout.Width);
            Assert.AreEqual(80, root_child0.Layout.Height);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.RTL);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(100, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(80, root_child0.Layout.Position.Left);
            Assert.AreEqual(10, root_child0.Layout.Position.Top);
            Assert.AreEqual(10, root_child0.Layout.Width);
            Assert.AreEqual(80, root_child0.Layout.Height);
        }
        public void position_root_with_rtl_should_position_withoutdirection()
        {
            var root = new YogaNode
            {
                Width    = 52, Height = 52,
                Position = { Left = 72 }
            };

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(72, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(52, root.Layout.Width);
            Assert.AreEqual(52, root.Layout.Height);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.RTL);

            Assert.AreEqual(72, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(52, root.Layout.Width);
            Assert.AreEqual(52, root.Layout.Height);
        }
예제 #6
0
        public void aspect_ratio_with_min_main_defined()
        {
            var root = new YogaNode();

            root.AlignItems = AlignType.FlexStart;
            root.Width      = 100;
            root.Height     = 100;

            var root_child0 = new YogaNode();

            root_child0.Width       = 30;
            root_child0.MinHeight   = 40;
            root_child0.AspectRatio = 1;
            root.Children.Add(root_child0);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(40, root_child0.Layout.Width);
            Assert.AreEqual(40, root_child0.Layout.Height);
        }
예제 #7
0
        public void dirty_propagation()
        {
            YogaNode rootChild0, rootChild1;
            YogaNode root = Node(alignItems: YogaAlign.FlexStart, width: 100, height: 100)
                            .Add(rootChild0 = Node(width: 50, height: 20))
                            .Add(rootChild1 = Node(width: 50, height: 20));

            YogaArrange.CalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);


            rootChild0.Style.Width = 20;

            Assert.IsTrue(rootChild0.IsDirty);
            Assert.IsFalse(rootChild1.IsDirty);
            Assert.IsTrue(root.IsDirty);

            YogaArrange.CalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.IsFalse(rootChild0.IsDirty);
            Assert.IsFalse(rootChild1.IsDirty);
            Assert.IsFalse(root.IsDirty);
        }
        public void absolute_layout_align_items_center_on_child_only()
        {
            var root = new YogaNode
            {
                FlexGrow = 1, Width = 110, Height = 100
            };

            var root_child0 = new YogaNode
            {
                AlignSelf    = AlignType.Center,
                PositionType = PositionType.Absolute,
                Width        = 60, Height = 40
            };

            root.Children.Add(root_child0);
            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(110, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(25, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(60, root_child0.Layout.Width);
            Assert.AreEqual(40, root_child0.Layout.Height);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.RTL);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(110, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(25, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(60, root_child0.Layout.Width);
            Assert.AreEqual(40, root_child0.Layout.Height);
        }
        public void absolute_layout_in_wrap_reverse_column_container()
        {
            var root = new YogaNode
            {
                FlexWrap = WrapType.WrapReverse,
                Width    = 100, Height = 100
            };

            var root_child0 = new YogaNode
            {
                PositionType = PositionType.Absolute,
                Width        = 20, Height = 20
            };

            root.Children.Add(root_child0);
            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(100, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(80, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(20, root_child0.Layout.Width);
            Assert.AreEqual(20, root_child0.Layout.Height);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.RTL);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(100, root.Layout.Width);
            Assert.AreEqual(100, root.Layout.Height);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(20, root_child0.Layout.Width);
            Assert.AreEqual(20, root_child0.Layout.Height);
        }
예제 #10
0
        public void dirtied_hierarchy()
        {
            YogaNode root = YGNodeNew();

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

            YogaNode rootChild0 = YGNodeNew();

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

            YogaNode rootChild1 = YGNodeNew();

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

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            rootChild0.Context     = 0;
            rootChild0.DirtiedFunc = _dirtied;

            Assert.AreEqual(0, (int)rootChild0.Context);

            // `_dirtied` must NOT be called for descendants.
            root.MarkDirtyAndPropagate();
            Assert.AreEqual(0, (int)rootChild0.Context);

            // `_dirtied` must NOT be called for the sibling node.
            rootChild1.MarkDirtyAndPropagate();
            Assert.AreEqual(0, (int)rootChild0.Context);

            // `_dirtied` MUST be called in case of explicit dirtying.
            rootChild0.MarkDirtyAndPropagate();
            Assert.AreEqual(1, (int)rootChild0.Context);
        }
예제 #11
0
        public void dirtied_hierarchy()
        {
            YogaNode root_child0;
            YogaNode root_child1;
            var      root = new YogaNode
            {
                AlignItems = AlignType.FlexStart, Width = 100, Height = 100,
                Children   =
                {
                    (root_child0 = new YogaNode {
                        Width    = 50, Height = 20
                    }),
                    (root_child1 = new YogaNode {
                        Width    = 50, Height = 20
                    })
                }
            };

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            var dirtiedCount = 0;

            root_child0.Context     = dirtiedCount;
            root_child0.DirtiedFunc = n => { dirtiedCount++; };

            Assert.AreEqual(0, dirtiedCount);

            // `_dirtied` must NOT be called for descendants.
            root.MarkDirty();
            Assert.AreEqual(0, dirtiedCount);

            // `_dirtied` must NOT be called for the sibling node.
            root_child1.MarkDirty();
            Assert.AreEqual(0, dirtiedCount);

            // `_dirtied` MUST be called in case of explicit dirtying.
            root_child0.MarkDirty();
            Assert.AreEqual(1, dirtiedCount);
        }
예제 #12
0
        public void aspect_ratio_overrides_flex_grow_column()
        {
            var root = new YogaNode();

            root.AlignItems = AlignType.FlexStart;
            root.Width      = 100;
            root.Height     = 100;

            var root_child0 = new YogaNode();

            root_child0.Height      = 50;
            root_child0.FlexGrow    = 1;
            root_child0.AspectRatio = 2;
            root.Children.Add(root_child0);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(200, root_child0.Layout.Width);
            Assert.AreEqual(100, root_child0.Layout.Height);
        }
        private YogaSize MeasureButton(ReactButtonShadowNode textNode, YogaNode node, float width,
                                       YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            Log.Info(ReactConstants.Tag, "[1] MeasureButton node=" + textNode.ReactTag + " with=" + width + " height=" + height + " content=" + _preparedSpannableText);
            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.

            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                var btnView = new Button(ReactProgram.RctWindow);

                var normalizedWidth  = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width;
                var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height;

                btnView.Resize((int)normalizedWidth, (int)normalizedHeight);
                btnView.Text = _preparedSpannableText;

                var btnPartObject = btnView.EdjeObject["elm.text"];
                if (btnPartObject == null)
                {
                    throw new Exception("Invalid Button.EdjeObject[\"elm.text\"]");
                }
                Size size = btnPartObject.TextBlockFormattedSize;
                Log.Info(ReactConstants.Tag, "[2] EDC conf info ={ width: " + size.Width + " height:" + size.Height + "}");
                btnView.Unrealize();

                return(MeasureOutput.Make(
                           (float)(size.Width + 80),
                           (float)(size.Height < 80 ? 80 : size.Height)));
            });

            return(task.Result);
        }
예제 #14
0
        public void TestChildren()
        {
            YogaNode parent = new YogaNode();

            foreach (YogaNode node in parent)
            {
                Assert.Fail(node.ToString());
            }

            YogaNode child0 = new YogaNode();

            Assert.AreEqual(-1, parent.IndexOf(child0));
            parent.Insert(0, child0);
            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(0, parent.IndexOf(node));
            }

            YogaNode child1 = new YogaNode();

            parent.Insert(1, child1);
            int index = 0;

            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(index++, parent.IndexOf(node));
            }

            parent.RemoveAt(0);
            Assert.AreEqual(-1, parent.IndexOf(child0));
            Assert.AreEqual(0, parent.IndexOf(child1));

            parent.Clear();
            Assert.AreEqual(0, parent.Count);

            parent.Clear();
            Assert.AreEqual(0, parent.Count);
        }
        private static YogaSize MeasureText(ReactSimpleTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            // TODO: Measure text with DirectWrite or other API that does not
            // require dispatcher access. Currently, we're instantiating a
            // second CoreApplicationView (that is never activated) and using
            // its Dispatcher thread to calculate layout.
            var textBlock = new TextBlock
            {
                TextWrapping  = TextWrapping.Wrap,
                TextAlignment = TextAlignment.DetectFromContent,
                TextTrimming  = TextTrimming.CharacterEllipsis,
            };

            textNode.UpdateTextBlockCore(textBlock, true);

            var normalizedWidth  = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width;
            var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height;

            textBlock.Measure(new Size(normalizedWidth, normalizedHeight));
            return(MeasureOutput.Make(
                       (float)Math.Ceiling(textBlock.DesiredSize.Width),
                       (float)Math.Ceiling(textBlock.DesiredSize.Height)));
        }
예제 #16
0
        public void aspect_ratio_top_bottom_absolute()
        {
            var root = new YogaNode();

            root.Width  = 100;
            root.Height = 100;

            var root_child0 = new YogaNode();

            root_child0.PositionType    = PositionType.Absolute;
            root_child0.Position.Left   = 10;
            root_child0.Position.Top    = 10;
            root_child0.Position.Bottom = 10;
            root_child0.AspectRatio     = 1;
            root.Children.Add(root_child0);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(10, root_child0.Layout.Position.Left);
            Assert.AreEqual(10, root_child0.Layout.Position.Top);
            Assert.AreEqual(80, root_child0.Layout.Width);
            Assert.AreEqual(80, root_child0.Layout.Height);
        }
예제 #17
0
        public void aspect_ratio_width_height_flex_grow_column()
        {
            YogaNode root = YGNodeNew();

            YGNodeStyleSetAlignItems(root, YogaAlign.FlexStart);
            YGNodeStyleSetWidth(root, 200);
            YGNodeStyleSetHeight(root, 100);

            YogaNode rootChild0 = YGNodeNew();

            YGNodeStyleSetWidth(rootChild0, 50);
            YGNodeStyleSetHeight(rootChild0, 50);
            YGNodeStyleSetFlexGrow(rootChild0, 1);
            YGNodeStyleSetAspectRatio(rootChild0, 1);
            YGNodeInsertChild(root, rootChild0, 0);

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(0, YGNodeLayoutGetLeft(rootChild0));
            Assert.AreEqual(0, YGNodeLayoutGetTop(rootChild0));
            Assert.AreEqual(100, YGNodeLayoutGetWidth(rootChild0));
            Assert.AreEqual(100, YGNodeLayoutGetHeight(rootChild0));
        }
예제 #18
0
        public void aspect_ratio_both_dimensions_defined_row()
        {
            YogaNode root = YGNodeNew();

            YGNodeStyleSetFlexDirection(root, FlexDirection.Row);
            YGNodeStyleSetAlignItems(root, YogaAlign.FlexStart);
            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YogaNode rootChild0 = YGNodeNew();

            YGNodeStyleSetWidth(rootChild0, 100);
            YGNodeStyleSetHeight(rootChild0, 50);
            YGNodeStyleSetAspectRatio(rootChild0, 1);
            YGNodeInsertChild(root, rootChild0, 0);

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(0, YGNodeLayoutGetLeft(rootChild0));
            Assert.AreEqual(0, YGNodeLayoutGetTop(rootChild0));
            Assert.AreEqual(100, YGNodeLayoutGetWidth(rootChild0));
            Assert.AreEqual(100, YGNodeLayoutGetHeight(rootChild0));
        }
예제 #19
0
        public void aspect_ratio_top_bottom_absolute()
        {
            YogaNode root = YGNodeNew();

            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YogaNode rootChild0 = YGNodeNew();

            YGNodeStyleSetPositionType(rootChild0, PositionType.Absolute);
            YGNodeStyleSetPosition(rootChild0, Edge.Left, 10);
            YGNodeStyleSetPosition(rootChild0, Edge.Top, 10);
            YGNodeStyleSetPosition(rootChild0, Edge.Bottom, 10);
            YGNodeStyleSetAspectRatio(rootChild0, 1);
            YGNodeInsertChild(root, rootChild0, 0);

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(10, YGNodeLayoutGetLeft(rootChild0));
            Assert.AreEqual(10, YGNodeLayoutGetTop(rootChild0));
            Assert.AreEqual(80, YGNodeLayoutGetWidth(rootChild0));
            Assert.AreEqual(80, YGNodeLayoutGetHeight(rootChild0));
        }
예제 #20
0
        public void border_container_match_child()
        {
            var config = new YogaConfig();

            var root = new YogaNode(config);

            root.Border = new Edges(10, 10, 10, 10);

            var root_child0 = new YogaNode(config);

            root_child0.Width  = 10;
            root_child0.Height = 10;
            root.Children.Add(root_child0);
            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(30, root.Layout.Width);
            Assert.AreEqual(30, root.Layout.Height);

            Assert.AreEqual(10, root_child0.Layout.Position.Left);
            Assert.AreEqual(10, root_child0.Layout.Position.Top);
            Assert.AreEqual(10, root_child0.Layout.Width);
            Assert.AreEqual(10, root_child0.Layout.Height);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.RTL);

            Assert.AreEqual(0, root.Layout.Position.Left);
            Assert.AreEqual(0, root.Layout.Position.Top);
            Assert.AreEqual(30, root.Layout.Width);
            Assert.AreEqual(30, root.Layout.Height);

            Assert.AreEqual(10, root_child0.Layout.Position.Left);
            Assert.AreEqual(10, root_child0.Layout.Position.Top);
            Assert.AreEqual(10, root_child0.Layout.Width);
            Assert.AreEqual(10, root_child0.Layout.Height);
        }
예제 #21
0
        public void dirtied_propagation()
        {
            var root = new YogaNode();

            root.AlignItems = AlignType.FlexStart;
            root.Width      = 100;
            root.Height     = 100;

            var root_child0 = new YogaNode();

            root_child0.Width  = 50;
            root_child0.Height = 20;
            root.Children.Add(root_child0);

            var root_child1 = new YogaNode();

            root_child1.Width  = 50;
            root_child1.Height = 20;
            root.Children.Insert(1, root_child1);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            var dirtiedCount = 0;

            root.Context     = dirtiedCount;
            root.DirtiedFunc = n => { dirtiedCount++; };

            Assert.AreEqual(0, dirtiedCount);

            // `_dirtied` MUST be called for the first time.
            root_child0.MarkDirty();
            Assert.AreEqual(1, dirtiedCount);

            // `_dirtied` must NOT be called for the second time.
            root_child0.MarkDirty();
            Assert.AreEqual(1, dirtiedCount);
        }
예제 #22
0
        public void set_children_replaces_non_common_children()
        {
            YogaNode root       = YGNodeNew();
            YogaNode rootChild0 = YGNodeNew();
            YogaNode rootChild1 = YGNodeNew();
            YogaNode rootChild2 = YGNodeNew();
            YogaNode rootChild3 = YGNodeNew();

            rootChild0.LineIndex = 0;
            rootChild1.LineIndex = 1;
            rootChild2.LineIndex = 2;
            rootChild3.LineIndex = 3;

            YGNodeSetChildren(root, new List <YogaNode> {
                rootChild0, rootChild1
            });

            YGNodeSetChildren(root, new List <YogaNode> {
                rootChild2, rootChild3
            });

            List <YogaNode> children         = GetChildren(root);
            List <YogaNode> expectedChildren = new List <YogaNode> {
                rootChild2, rootChild3
            };

            Assert.AreEqual(children, expectedChildren);

            List <YogaNode> owners = new List <YogaNode> {
                YGNodeGetOwner(rootChild0), YGNodeGetOwner(rootChild1)
            };
            List <YogaNode> expectedOwners = new List <YogaNode> {
                null, null
            };

            Assert.AreEqual(owners, expectedOwners);
        }
예제 #23
0
        public void set_children_keeps_and_reorders_common_children()
        {
            YogaNode root       = YGNodeNew();
            YogaNode rootChild0 = YGNodeNew();
            YogaNode rootChild1 = YGNodeNew();
            YogaNode rootChild2 = YGNodeNew();
            YogaNode rootChild3 = YGNodeNew();

            rootChild0.LineIndex = 0;
            rootChild1.LineIndex = 1;
            rootChild2.LineIndex = 2;
            rootChild3.LineIndex = 3;

            YGNodeSetChildren(root, new YogaNode[] { rootChild0, rootChild1, rootChild2 });

            YGNodeSetChildren(root, new YogaNode[] { rootChild2, rootChild1, rootChild3 });

            List <YogaNode> children         = GetChildren(root);
            List <YogaNode> expectedChildren = new List <YogaNode> {
                rootChild2, rootChild1, rootChild3
            };

            Assert.AreEqual(children, expectedChildren);

            List <YogaNode> owners = new List <YogaNode>
            {
                YGNodeGetOwner(rootChild0),
                YGNodeGetOwner(rootChild1),
                YGNodeGetOwner(rootChild2),
                YGNodeGetOwner(rootChild3)
            };
            var expectedOwners = new List <YogaNode> {
                null, root, root, root
            };

            Assert.AreEqual(owners, expectedOwners);
        }
예제 #24
0
        public void at_most_main_axis_column()
        {
            var constraintList = new MeasureConstraintList();

            YogaNode root = YGNodeNew();

            YGNodeStyleSetWidth(root, 100);
            YGNodeStyleSetHeight(root, 100);

            YogaNode rootChild0 = YGNodeNew();

            rootChild0.Context = constraintList;
            YGNodeSetMeasureFunc(rootChild0, _measure);
            YGNodeInsertChild(root, rootChild0, 0);

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(1, constraintList.Count);

            Assert.AreEqual(100, constraintList[0].Height);
            Assert.AreEqual(MeasureMode.AtMost, constraintList[0].HeightMode);

            //free(constraintList.constraints);
        }
예제 #25
0
        public void percent_absolute_position_infinite_height()
        {
            YogaNode rootChild0, rootChild1;
            YogaNode root = Node(flexDirection: FlexDirection.Row, width: 300)
                            .Add(rootChild0 = Node(width: 300, height: 300))
                            .Add(rootChild1 = Node(positionType: PositionType.Absolute, left: 20.Percent(), top: 20.Percent(), width: 20.Percent(), height: 20.Percent()));

            YogaArrange.CalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(0, root.Layout.Left);
            Assert.AreEqual(0, root.Layout.Top);
            Assert.AreEqual(300, root.Layout.Width);
            Assert.AreEqual(300, root.Layout.Height);

            Assert.AreEqual(0, rootChild0.Layout.Left);
            Assert.AreEqual(0, rootChild0.Layout.Top);
            Assert.AreEqual(300, rootChild0.Layout.Width);
            Assert.AreEqual(300, rootChild0.Layout.Height);

            Assert.AreEqual(60, rootChild1.Layout.Left);
            Assert.AreEqual(0, rootChild1.Layout.Top);
            Assert.AreEqual(60, rootChild1.Layout.Width);
            Assert.AreEqual(0, rootChild1.Layout.Height);
        }
예제 #26
0
        public void set_children_adds_children_to_parent()
        {
            YogaNode root       = new YogaNode();
            YogaNode rootChild0 = new YogaNode();
            YogaNode rootChild1 = new YogaNode();

            root.SetChildren(new[] { rootChild0, rootChild1 });

            var children         = GetChildren(root);
            var expectedChildren = new List <YogaNode> {
                rootChild0, rootChild1
            };

            Assert.AreEqual(children, expectedChildren);

            List <YogaNode> owners = new List <YogaNode> {
                rootChild0.Owner, rootChild1.Owner
            };
            List <YogaNode> expectedOwners = new List <YogaNode> {
                root, root
            };

            Assert.AreEqual(owners, expectedOwners);
        }
예제 #27
0
        public void border_no_size()
        {
            YogaConfig config = YGConfigNew();

            YogaNode root = YGNodeNewWithConfig(config);

            YGNodeStyleSetBorder(root, Edge.Left, 10);
            YGNodeStyleSetBorder(root, Edge.Top, 10);
            YGNodeStyleSetBorder(root, Edge.Right, 10);
            YGNodeStyleSetBorder(root, Edge.Bottom, 10);
            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.LTR);

            Assert.AreEqual(0, YGNodeLayoutGetLeft(root));
            Assert.AreEqual(0, YGNodeLayoutGetTop(root));
            Assert.AreEqual(20, YGNodeLayoutGetWidth(root));
            Assert.AreEqual(20, YGNodeLayoutGetHeight(root));

            YGNodeCalculateLayout(root, YogaValue.YGUndefined, YogaValue.YGUndefined, Direction.RTL);

            Assert.AreEqual(0, YGNodeLayoutGetLeft(root));
            Assert.AreEqual(0, YGNodeLayoutGetTop(root));
            Assert.AreEqual(20, YGNodeLayoutGetWidth(root));
            Assert.AreEqual(20, YGNodeLayoutGetHeight(root));
        }
        private static YogaSize MeasureText(ReactTextShadowNode textNode, YogaNode node, float width, YogaMeasureMode widthMode, float height, YogaMeasureMode heightMode)
        {
            // This is not a terribly efficient way of projecting the height of
            // the text elements. It requires that we have access to the
            // dispatcher in order to do measurement, which, for obvious
            // reasons, can cause perceived performance issues as it will block
            // the UI thread from handling other work.
            //
            // TODO: determine another way to measure text elements.
            var task = DispatcherHelpers.CallOnDispatcher(() =>
            {
                var textBlock = new TextBlock
                {
                    TextAlignment = TextAlignment.Left,
                    TextWrapping  = TextWrapping.Wrap,
                    TextTrimming  = TextTrimming.CharacterEllipsis,
                };

                textNode.UpdateTextBlockCore(textBlock, true);

                for (var i = 0; i < textNode.ChildCount; ++i)
                {
                    var child = textNode.GetChildAt(i);
                    textBlock.Inlines.Add(ReactInlineShadowNodeVisitor.Apply(child));
                }

                var normalizedWidth  = YogaConstants.IsUndefined(width) ? double.PositiveInfinity : width;
                var normalizedHeight = YogaConstants.IsUndefined(height) ? double.PositiveInfinity : height;
                textBlock.Measure(new Size(normalizedWidth, normalizedHeight));
                return(MeasureOutput.Make(
                           (float)Math.Ceiling(textBlock.DesiredSize.Width),
                           (float)Math.Ceiling(textBlock.DesiredSize.Height)));
            });

            return(task.Result);
        }
예제 #29
0
        public void TestPrint()
        {
            YogaNode parent = new YogaNode();

            parent.Width  = 100;
            parent.Height = 120;
            YogaNode child0 = new YogaNode();

            child0.Width  = 30;
            child0.Height = 40;
            YogaNode child1 = new YogaNode();

            child1.Width  = 35;
            child1.Height = 45;
            parent.Insert(0, child0);
            parent.Insert(0, child1);
            parent.CalculateLayout();
            Assert.AreEqual(parent.Print(),
                            "<div layout=\"width: 100; height: 120; top: 0; left: 0;\" style=\"width: 100px; height: 120px; \" >\n" +
                            "  <div layout=\"width: 35; height: 45; top: 0; left: 0;\" style=\"width: 35px; height: 45px; \" ></div>\n" +
                            "  <div layout=\"width: 30; height: 40; top: 45; left: 0;\" style=\"width: 30px; height: 40px; \" ></div>\n" +
                            "</div>"
                            );
        }
예제 #30
0
        public void reset_layout_when_child_removed()
        {
            var root = new YogaNode();

            var root_child0 = new YogaNode();

            root_child0.Width  = 100;
            root_child0.Height = 100;
            root.Children.Add(root_child0);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.AreEqual(100, root_child0.Layout.Width);
            Assert.AreEqual(100, root_child0.Layout.Height);

            root.Children.Remove(root_child0);

            Assert.AreEqual(0, root_child0.Layout.Position.Left);
            Assert.AreEqual(0, root_child0.Layout.Position.Top);
            Assert.IsTrue(root_child0.Layout.Width.IsNaN());
            Assert.IsTrue(root_child0.Layout.Height.IsNaN());
        }