diff --git a/Tests/TestGame.cs b/Tests/TestGame.cs index cd83c09..eb306a5 100644 --- a/Tests/TestGame.cs +++ b/Tests/TestGame.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using MLEM.Data.Content; using MLEM.Font; using MLEM.Startup; @@ -20,6 +21,10 @@ public class TestGame : MlemGame { protected override void LoadContent() { base.LoadContent(); this.RawContent = new RawContentManager(this.Services, this.Content.RootDirectory); + + // make sure that the viewport is always the same size, since RunOneFrame doesn't ensure window size is correct + this.UiSystem.Viewport = new Rectangle(0, 0, 1280, 720); + // we use precompiled fonts and kni uses a different asset compilation system, so we just have both stored this.UiSystem.Style.Font = new GenericSpriteFont(MlemGame.LoadContent( #if KNI diff --git a/Tests/UiTests.cs b/Tests/UiTests.cs index 2bc1373..d6f92a5 100644 --- a/Tests/UiTests.cs +++ b/Tests/UiTests.cs @@ -147,6 +147,34 @@ public class UiTests : GameTestFixture { } } + [Test] + public void TestIssue27([Values(5, 50, 15)] int numChildren) { + // Stack overflow related to panel scrolling and scrollbar auto-hiding + + var group = new SquishingGroup(Anchor.TopLeft, Vector2.One); + + var centerGroup = new ScissorGroup(Anchor.TopCenter, Vector2.One); + var centerPanel = new Panel(Anchor.TopRight, Vector2.One); + centerPanel.DrawColor = Color.Red; + centerPanel.Padding = new MLEM.Maths.Padding(5); + centerGroup.AddChild(centerPanel); + group.AddChild(centerGroup); + + var leftColumn = new Panel(Anchor.TopLeft, new Vector2(500, 1), scrollOverflow: true); + group.AddChild(leftColumn); + for (var i = 0; i < numChildren; i++) { + var c = new Panel(Anchor.AutoLeft, new Vector2(1, 30)); + c.DrawColor = Color.Green; + c.Padding = new MLEM.Maths.Padding(5); + leftColumn.AddChild(c); + } + + var bottomPane = new Panel(Anchor.BottomCenter, new Vector2(1, 500)); + group.AddChild(bottomPane); + + this.AddAndUpdate(group, out _, out _); + } + private void AddAndUpdate(Element element, out TimeSpan addTime, out TimeSpan updateTime) { foreach (var root in this.Game.UiSystem.GetRootElements()) this.Game.UiSystem.Remove(root.Name);