Example #1
0
        public void stretch_both()
        {
            var size = LayoutSize.StretchedBoth();

            size.IsFixedAspectRatio().Should().BeFalse();
            size.IsMeasurableAlong(Orientation.Horizontal).Should().BeFalse();
            size.IsMeasurableAlong(Orientation.Vertical).Should().BeFalse();
            size.IsStretchedAlong(Orientation.Vertical).Should().BeTrue();
            size.IsStretchedPerpendicular(Orientation.Vertical).Should().BeTrue();
        }
Example #2
0
        public void linear_layout_test_with_margin_and_padding()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 100), new LayoutStyle(padding: 5, margin: new Point(3, 6)),
                                                   LayoutNode.Leaf("item-1", LayoutSize.StretchedHorizontally(10)),
                                                   LayoutNode.Leaf("item-2", LayoutSize.StretchedHorizontally(20)),
                                                   LayoutNode.Leaf("item-3", LayoutSize.StretchedBoth())
                                                   );

            var layoutResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(layoutResult));
        }
Example #3
0
        public void linear_layout_test()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 100), LayoutStyle.Empty,
                                                   LayoutNode.Leaf("item-1", LayoutSize.StretchedHorizontally(10)),
                                                   LayoutNode.Leaf("item-2", LayoutSize.StretchedHorizontally(20)),
                                                   LayoutNode.Leaf("item-3", LayoutSize.StretchedBoth())
                                                   );

            var layoutResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(layoutResult));
        }
Example #4
0
        public void can_get_baked_layout_node_by_name()
        {
            var layout = LayoutNode.HorizontalParent("root", LayoutSize.Pixels(20, 5), new LayoutStyle(margin: new Point(1, 1), padding: 1, Alignment.TopLeft),
                                                     LayoutNode.Leaf("a", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("b", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("c", LayoutSize.StretchedBoth())
                                                     );

            var subject = layout.Bake();

            var acquiredNode = subject.GetNode("b");

            acquiredNode.Size.Should().Be(new Point(5, 3));
        }
Example #5
0
        public void does_not_stretch_evenly()
        {
            var layout = LayoutNode.HorizontalParent("root", LayoutSize.Pixels(20, 5), new LayoutStyle(margin: new Point(1, 1), padding: 1, Alignment.TopLeft),
                                                     LayoutNode.Leaf("a", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("b", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("c", LayoutSize.StretchedBoth())
                                                     );

            var result = layout.Bake();

            Approvals.Verify(
                LayoutNodeUtils.DrawResult(result)
                );
        }
Example #6
0
        public void bake_a_stretched_node_without_parent()
        {
            var threw = false;

            try
            {
                new RawLayout(LayoutNode.Leaf("Stretch", LayoutSize.StretchedBoth())).Bake();
            }
            catch (ImpossibleLayoutException)
            {
                threw = true;
            }

            threw.Should().BeTrue();
        }
Example #7
0
        public void can_obtain_all_result_nodes_in_order()
        {
            var layout = LayoutNode.HorizontalParent("root", LayoutSize.Pixels(20, 5), new LayoutStyle(margin: new Point(1, 1), padding: 1, Alignment.TopLeft),
                                                     LayoutNode.Leaf("a", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("b", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("c", LayoutSize.StretchedBoth())
                                                     );

            var subject = layout.Bake();

            var result = subject.GetAllResultNodesInHierarchyOrder();

            result.Should().HaveCount(4);

            result.Should().ContainInOrder(subject.GetNode("root"), subject.GetNode("a"), subject.GetNode("b"), subject.GetNode("c"));
        }
Example #8
0
        public void create_window_test()
        {
            var headerHeight = 8;
            var layout       = LayoutNode.VerticalParent("root", LayoutSize.Pixels(80, 40), LayoutStyle.Empty,
                                                         LayoutNode.HorizontalParent("header", LayoutSize.StretchedHorizontally(headerHeight), new LayoutStyle(padding: 2),
                                                                                     LayoutNode.StretchedSpacer(),
                                                                                     LayoutNode.Leaf("minimize", LayoutSize.Square(headerHeight)),
                                                                                     LayoutNode.Leaf("fullscreen", LayoutSize.Square(headerHeight)),
                                                                                     LayoutNode.Leaf("close", LayoutSize.Square(headerHeight))
                                                                                     ),
                                                         LayoutNode.Leaf("canvas", LayoutSize.StretchedBoth())
                                                         );

            var firstBakeResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(firstBakeResult));
        }
Example #9
0
        public void can_obtain_child_nodes_of_particular_node()
        {
            var layout = LayoutNode.HorizontalParent("root", LayoutSize.Pixels(20, 5), new LayoutStyle(margin: new Point(1, 1), padding: 1, Alignment.TopLeft),
                                                     LayoutNode.HorizontalParent("a", LayoutSize.StretchedBoth(), LayoutStyle.Empty,
                                                                                 LayoutNode.Leaf("a1", LayoutSize.StretchedBoth()),
                                                                                 LayoutNode.Leaf("a2", LayoutSize.StretchedBoth()),
                                                                                 LayoutNode.Leaf("a3", LayoutSize.StretchedBoth()),
                                                                                 LayoutNode.Leaf("a4", LayoutSize.StretchedBoth()),
                                                                                 LayoutNode.Leaf("a5", LayoutSize.StretchedBoth())
                                                                                 ),
                                                     LayoutNode.Leaf("b", LayoutSize.StretchedBoth()),
                                                     LayoutNode.Leaf("c", LayoutSize.StretchedBoth())
                                                     );

            var subject = layout.Bake();

            subject.GetDirectChildrenOfNode("a").Should().ContainInOrder(subject.GetNode("a1"), subject.GetNode("a2"), subject.GetNode("a3"), subject.GetNode("a4"), subject.GetNode("a5"));
        }
Example #10
0
        public void resize_and_rebake_test()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 50), LayoutStyle.Empty,
                                                   LayoutNode.Leaf("item-1", LayoutSize.StretchedHorizontally(10)),
                                                   LayoutNode.HorizontalParent("item-2", LayoutSize.StretchedHorizontally(20), new LayoutStyle(new Point(2, 3), 0),
                                                                               LayoutNode.Leaf("item-2a", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2b", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2c", LayoutSize.StretchedHorizontally(10))
                                                                               ),
                                                   LayoutNode.VerticalParent("item-3", LayoutSize.StretchedBoth(), new LayoutStyle(new Point(5, 2), 1),
                                                                             LayoutNode.Leaf("item-3a", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3b", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3c", LayoutSize.StretchedHorizontally(10))
                                                                             )
                                                   );

            var resizedLayout = layout.RootNode.GetResized(new Point(60, 60));

            var firstBakeResult  = layout.Bake();
            var secondBakeResult = resizedLayout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(firstBakeResult) + "\n\n" + LayoutNodeUtils.DrawResult(secondBakeResult));
        }
Example #11
0
        public void nested_layout_test()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 100), LayoutStyle.Empty,
                                                   LayoutNode.Leaf("item-1", LayoutSize.StretchedHorizontally(10)),
                                                   LayoutNode.HorizontalParent("item-2", LayoutSize.StretchedHorizontally(20), new LayoutStyle(new Point(2, 3), 0),
                                                                               LayoutNode.Leaf("item-2a", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2b", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2c", LayoutSize.StretchedHorizontally(10))
                                                                               ),
                                                   LayoutNode.VerticalParent("item-3", LayoutSize.StretchedBoth(), new LayoutStyle(new Point(0, 2), 3),
                                                                             LayoutNode.Leaf("item-3a", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3b", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3c", LayoutSize.StretchedHorizontally(10))
                                                                             )
                                                   );

            var layoutResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(layoutResult));
        }
Example #12
0
        public void fixed_aspect_with_spacers()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 80), LayoutStyle.Empty,
                                                   LayoutNode.StretchedSpacer(),
                                                   LayoutNode.HorizontalParent("aligner", LayoutSize.StretchedBoth(), LayoutStyle.Empty,
                                                                               LayoutNode.StretchedSpacer(),
                                                                               LayoutNode.Leaf("fixed-aspect", LayoutSize.FixedAspectRatio(16, 9)),
                                                                               LayoutNode.StretchedSpacer()
                                                                               ),
                                                   LayoutNode.StretchedSpacer()
                                                   );

            var firstBakeResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(firstBakeResult));
        }
Example #13
0
        public void vertical_stretch_test()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 80), LayoutStyle.Empty,
                                                   LayoutNode.HorizontalParent("group-1", LayoutSize.Pixels(50, 20), new LayoutStyle(margin: new Point(3, 3)),
                                                                               LayoutNode.Leaf("tall-item", LayoutSize.StretchedVertically(15)),
                                                                               LayoutNode.Leaf("both-item", LayoutSize.StretchedBoth())
                                                                               ),
                                                   LayoutNode.StretchedSpacer(),
                                                   LayoutNode.VerticalParent("group-2", LayoutSize.Pixels(50, 20), new LayoutStyle(margin: new Point(3, 3)),
                                                                             LayoutNode.Leaf("tall-item-2", LayoutSize.StretchedVertically(15)),
                                                                             LayoutNode.Leaf("both-item-2", LayoutSize.StretchedBoth())
                                                                             )
                                                   );

            var firstBakeResult = layout.Bake();

            Approvals.Verify(LayoutNodeUtils.DrawResult(firstBakeResult));
        }
Example #14
0
        public void resize_performance_test()
        {
            var layout = LayoutNode.VerticalParent("root", LayoutSize.Pixels(50, 50), LayoutStyle.Empty,
                                                   LayoutNode.Leaf("item-1", LayoutSize.StretchedHorizontally(10)),
                                                   LayoutNode.HorizontalParent("item-2", LayoutSize.StretchedHorizontally(20), new LayoutStyle(new Point(2, 3), 5),
                                                                               LayoutNode.Leaf("item-2a", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2b", LayoutSize.StretchedHorizontally(10)),
                                                                               LayoutNode.Leaf("item-2c", LayoutSize.StretchedHorizontally(10))
                                                                               ),
                                                   LayoutNode.VerticalParent("item-3", LayoutSize.StretchedBoth(), new LayoutStyle(new Point(5, 2), 1),
                                                                             LayoutNode.Leaf("item-3a", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3b", LayoutSize.StretchedBoth()),
                                                                             LayoutNode.Leaf("item-3c", LayoutSize.StretchedHorizontally(10))
                                                                             )
                                                   );

            for (int i = 0; i < 1000; i++)
            {
                var resizedLayout = layout.RootNode.GetResized(new Point(i * 10, i * 10));
                resizedLayout.Bake();
            }
        }