Пример #1
0
        public void TestAnchorLayoutBasic()
        {
            var control = new LayoutContainer {
                Size = new Vector2(100, 100)
            };
            var child = new Control();

            LayoutContainer.SetAnchorRight(child, 1);
            LayoutContainer.SetAnchorBottom(child, 1);
            control.AddChild(child);

            control.Arrange(new UIBox2(0, 0, 100, 100));

            Assert.That(child.Size, Is.EqualTo(new Vector2(100, 100)));
            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));

            LayoutContainer.SetAnchorLeft(child, 0.5f);
            control.InvalidateArrange();
            control.Arrange(new UIBox2(0, 0, 100, 100));
            Assert.That(child.Position, Is.EqualTo(new Vector2(50, 0)));
            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 100)));
            LayoutContainer.SetAnchorTop(child, 0.5f);
            control.InvalidateArrange();
            control.Arrange(new UIBox2(0, 0, 100, 100));

            Assert.That(child.Position, Is.EqualTo(new Vector2(50, 50)));
            Assert.That(child.Size, Is.EqualTo(new Vector2(50, 50)));
        }
Пример #2
0
        public void TestMarginAnchorLayout()
        {
            var control = new LayoutContainer {
                Size = new Vector2(100, 100)
            };
            var child = new Control();

            LayoutContainer.SetMarginRight(child, -10);
            LayoutContainer.SetMarginBottom(child, -10);
            LayoutContainer.SetMarginTop(child, 10);
            LayoutContainer.SetMarginLeft(child, 10);
            LayoutContainer.SetAnchorRight(child, 1);
            LayoutContainer.SetAnchorBottom(child, 1);

            control.AddChild(child);
            control.InvalidateArrange();
            control.Arrange(new UIBox2(0, 0, 100, 100));

            Assert.That(child.Position, Is.EqualTo(new Vector2(10, 10)));
            Assert.That(child.Size, Is.EqualTo(new Vector2(80, 80)));
        }
Пример #3
0
        public void TestGrowEnd()
        {
            var parent = new LayoutContainer();
            var child  = new Control {
                SetSize = (100, 100)
            };

            LayoutContainer.SetAnchorRight(child, 1);

            parent.AddChild(child);
            parent.Arrange(new UIBox2(0, 0, 100, 100));

            // Child should be at 0,0.
            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));

            // Right margin should make the child not have enough space and grow left.
            LayoutContainer.SetMarginRight(child, -100);
            parent.InvalidateArrange();
            parent.Arrange(new UIBox2(0, 0, 100, 100));

            Assert.That(child.Position, Is.EqualTo(Vector2.Zero));
            Assert.That(child.Size, Is.EqualTo(new Vector2(100, 100)));
        }