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

            var box = new VBox();

            stage.AddChild(box);   // makes a size of 60x40 just through padding

            var spacerNone = new Spacer(100, 100).SetHAlign(HorizontalAlign.None);

            box.AddChild(spacerNone);
            var spacerLeft = new Spacer(100, 100).SetHAlign(HorizontalAlign.Left);

            box.AddChild(spacerLeft);
            var spacerCenter = new Spacer(100, 100).SetHAlign(HorizontalAlign.Center);

            box.AddChild(spacerCenter);
            var spacerRight = new Spacer(100, 100).SetHAlign(HorizontalAlign.Right);

            box.AddChild(spacerRight);

            // we add one child that will free up some width
            box.AddChild(new Spacer(400, 100));

            stage.CalculateLayout(hardware);     // layout

            // since we have not set a height on the hBox yet we expect all children to be not vertically aligned
            Assert.That(box.GetLayout().GetCalculatedWidth(), Is.EqualTo(400));
            Assert.That(box.GetLayout().GetCalculatedContentWidth(), Is.EqualTo(400));

            Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0));         // NONE stays on top
            Assert.That(spacerLeft.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0));         // TOP stays on top
            Assert.That(spacerCenter.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(150));     // MIDDLE 400 / 2 - 100 / 2
            Assert.That(spacerRight.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(300));      // BOTTOM 400 - 100

            // new we set a height and then we expect the children to be aligned
            box.SetWidth(800);
            stage.CalculateLayout(hardware);     // layout

            Assert.That(box.GetLayout().GetCalculatedWidth(), Is.EqualTo(800));
            Assert.That(box.GetLayout().GetCalculatedContentWidth(), Is.EqualTo(400));

            Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0));         // NONE stays on top
            Assert.That(spacerLeft.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(0));         // TOP stays on top
            Assert.That(spacerCenter.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(350));     // MIDDLE 800 / 2 - 100 / 2
            Assert.That(spacerRight.GetLayoutProcessingData().AbsoluteGeometry.Left, Is.EqualTo(700));      // BOTTOM (800 - 100)
        }