Ejemplo n.º 1
0
        public void VerticalLayoutTest()
        {
            var renderer = Substitute.For <NullRenderer>();  // mock the renderer
            var hardware = new NullHardware(1024, 768);
            var stage    = new GuiStage();

            var hBox = new VBox().SetX(10).SetY(20).SetPadding(10, 20, 30, 40); // makes a size of 60x40 just through padding

            stage.AddChild(hBox);
            stage.CalculateLayout(hardware);     // layout

            Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 60, 40)));

            // add a child
            var spacer1 = new Spacer(200, 100);

            hBox.AddChild(spacer1);          // should increase the size by 200x100
            stage.CalculateLayout(hardware); // layout

            Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 260, 140)));
            // check the absolute position of spacer1
            Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100)));

            // add another child
            var spacer2 = new Spacer(300, 200);

            hBox.AddChild(spacer2);          // should increase the size by 200x100
            stage.CalculateLayout(hardware); // layout

            Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 360, 340)));
            // check the absolute position of spacer1
            Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100)));
            // check the absolute position of spacer1
            Assert.That(spacer2.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 130, 300, 200)));

            // check setting the spacing
            hBox.SetSpacing(100);
            stage.CalculateLayout(hardware);     // layout

            Assert.That(hBox.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(10, 20, 360, 440)));
            // check the absolute position of spacer1
            Assert.That(spacer1.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 30, 200, 100)));
            // check the absolute position of spacer1
            Assert.That(spacer2.GetLayoutProcessingData().AbsoluteGeometry, Is.EqualTo(new Rectangle(50, 230, 300, 200)));
        }