public void VerticalAlignTest() { var renderer = Substitute.For <NullRenderer>(); // mock the renderer var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); var box = new HBox(); stage.AddChild(box); // makes a size of 60x40 just through padding var spacerNone = new Spacer(100, 100).SetVAlign(VerticalAlign.None); box.AddChild(spacerNone); var spacerTop = new Spacer(100, 100).SetVAlign(VerticalAlign.Top); box.AddChild(spacerTop); var spacerMiddle = new Spacer(100, 100).SetVAlign(VerticalAlign.Middle); box.AddChild(spacerMiddle); var spacerBottom = new Spacer(100, 100).SetVAlign(VerticalAlign.Bottom); box.AddChild(spacerBottom); // we add one child that will free up some height box.AddChild(new Spacer(100, 400)); stage.CalculateLayout(hardware); // since we have not set a height on the hBox yet we expect all children to be not vertically aligned Assert.That(box.GetLayout().GetCalculatedHeight(), Is.EqualTo(400)); Assert.That(box.GetLayout().GetCalculatedContentHeight(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerTop.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerMiddle.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(150)); // MIDDLE 400 / 2 - 100 / 2 Assert.That(spacerBottom.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(300)); // BOTTOM 400 - 100 // new we set a height and then we expect the children to be aligned box.SetHeight(800); stage.CalculateLayout(hardware); Assert.That(box.GetLayout().GetCalculatedHeight(), Is.EqualTo(800)); Assert.That(box.GetLayout().GetCalculatedContentHeight(), Is.EqualTo(400)); Assert.That(spacerNone.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // NONE stays on top Assert.That(spacerTop.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(0)); // TOP stays on top Assert.That(spacerMiddle.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(350)); // MIDDLE 800 / 2 - 100 / 2 Assert.That(spacerBottom.GetLayoutProcessingData().AbsoluteGeometry.Top, Is.EqualTo(700)); // BOTTOM (800 - 100) }