public void Arrange() { var tooltip = CreateTooltip("4"); tooltip.Anchor = AnchoredRect.CreateTopLeftAnchored(150, 30); tooltip.Measure(new Size(float.PositiveInfinity, float.PositiveInfinity)); tooltip.Arrange(tooltip.ArrangeChild(new Rectangle(10, 20, 200, 20))); tooltip.LayoutRect.Should().Be(new Rectangle(160, 50, 31, 35)); }
public IPopUp <TContent> CreatePopup <TContent>(Point location, TContent content = null) where TContent : class, IWidget { var popUp = new PopUp <TContent>(rootPane.UIStyle) { Anchor = AnchoredRect.CreateTopLeftAnchored(location.X, location.Y), Content = content }; popUp.Closed += HandlePopUpClosed; rootPane.Screen.InvokeAfterEvents(() => { rootPane.AddPopUp(popUp); }); return(popUp); }
public void MeasureNoScrollTopLeft() { var p = new PopUp <IWidget>(LayoutTestStyle.Create()) { Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(40, 50)) }; p.Measure(Size.Auto); p.DesiredSize.Should().Be(new Size(520, 320)); p.Content.DesiredSize.Should().Be(new Size(500, 300)); }
public void ArrangeVertical() { var g = new BoxGroup(LayoutTestStyle.Create()); g.Spacing = 5; g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0))); g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0))); g.Arrange(new Rectangle(10, 20, 400, 300)); g.LayoutRect.Should().Be(new Rectangle(10, 20, 400, 155)); g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 100)); g[1].LayoutRect.Should().Be(new Rectangle(10, 125, 150, 50)); }
public void ArrangeHorizontal() { var g = new BoxGroup(LayoutTestStyle.Create()); g.Spacing = 5; g.Orientation = Orientation.Horizontal; g.Add(LayoutTestWidget.FixedSize(200, 100).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0))); g.Add(LayoutTestWidget.FixedSize(150, 50).WithAnchorRect(AnchoredRect.CreateTopLeftAnchored(0, 0))); g.Arrange(new Rectangle(10, 20, 400, 300)); g.LayoutRect.Should().Be(new Rectangle(10, 20, 355, 300)); g[0].LayoutRect.Should().Be(new Rectangle(10, 20, 200, 100)); g[1].LayoutRect.Should().Be(new Rectangle(215, 20, 150, 50)); }
public void PopUpLayoutTest() { var p = new PopUp <IWidget>(LayoutTestStyle.Create()) { Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300) }; p.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20); var screen = Substitute.For <IScreenService>(); var root = new RootPane(screen, LayoutTestStyle.Create()); root.UIStyle.StyleResolver.AddRoot(root); root.AddPopUp(p); root.Arrange(new Rectangle(0, 0, 1270, 770)); p.LayoutRect.Should().Be(new Rectangle(10, 20, 520, 320)); }
public void InsertOrderTest() { var p = new PopUp <IWidget>(LayoutTestStyle.Create()) { Padding = new Insets(10), Content = LayoutTestWidget.FixedSize(500, 300) }; p.Anchor = AnchoredRect.CreateTopLeftAnchored(10, 20); var screen = Substitute.For <IScreenService>(); var root = new RootPane(screen, LayoutTestStyle.Create()); root.Content = LayoutTestWidget.FixedSize(400, 400).WithAnchorRect(AnchoredRect.Full); root.AddPopUp(p); root.Count.Should().Be(3); // glasspane root[0].Should().BeSameAs(root.Content); root[1].Should().BeAssignableTo <GlassPane>(); root[2].Should().BeSameAs(p); }
void CreateUI(IUIStyle style, Player player) { var powerUpIcons = new Dictionary <IPowerUp, IUITexture>(); var notFoundIcon = new UITexture(null); var g = new Group(style) { // Name in the top-left corner of the screen new Label(style) { Anchor = AnchoredRect.CreateTopLeftAnchored(10, 10) }.DoWith(l => player.BindingFor(p => p.Name).BindTo(text => l.Text = text)), // Hitpoints in the top-right corner of the screen new Label(style) { Anchor = AnchoredRect.CreateTopRightAnchored(10, 10) }.DoWith(l => player .BindingFor(p => p.HitPoints) .Map(value => $"{value:D}") .BindTo(text => l.Text = text)), // Powerups in the top center of the screen new BoxGroup(style) { Anchor = new AnchoredRect(null, 10, null, null, null, null) } // take the power-ups, map them to textures and build image-widgets. // then we'll add those to a list. .DoWith(bg => player.Inventory.ToBinding() .Map(pu => powerUpIcons[pu] ?? notFoundIcon) .Map(img => new Image(style) { Texture = img }) .Map(w => new WidgetAndConstraint <bool>(w)) .BindTo(bg)) }; }
public void MeasureTopLeftThrows() { Assert.Throws<ArgumentOutOfRangeException>(() => AnchoredRect.CreateTopLeftAnchored(1, 2, -1, -1)); }
public void MeasureTopLeft() { AnchoredRect.CreateTopLeftAnchored(1, 2).ResolveSize(new Size(0, 0)).Should().Be(new Size(1, 2)); AnchoredRect.CreateTopLeftAnchored(1, 2).ResolveSize(new Size(10, 10)).Should().Be(new Size(11, 12)); AnchoredRect.CreateTopLeftAnchored(1, 2, 20, 30).ResolveSize(new Size(10, 10)).Should().Be(new Size(21, 32)); }