diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 5445b95..2b8c92f 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -253,6 +253,12 @@ namespace MLEM.Ui.Elements { /// public bool SetWidthBasedOnChildren; /// + /// Set this field to true to cause this element's final display area to never exceed that of its . + /// If the resulting area is too large, the size of this element is shrunk to fit the target area. + /// This can be useful if an element should fill the remaining area of a parent exactly. + /// + public bool PreventParentSpill; + /// /// The transparency (alpha value) that this element is rendered with. /// Note that, when is called, this alpha value is multiplied with the 's alpha value and passed down to this element's . /// @@ -576,6 +582,17 @@ namespace MLEM.Ui.Elements { } } + if (this.PreventParentSpill) { + if (pos.X < parentArea.X) + pos.X = parentArea.X; + if (pos.Y < parentArea.Y) + pos.Y = parentArea.Y; + if (pos.X + actualSize.X > parentArea.Right) + actualSize.X = parentArea.Right - pos.X; + if (pos.Y + actualSize.Y > parentArea.Bottom) + actualSize.Y = parentArea.Bottom - pos.Y; + } + this.area = new RectangleF(pos, actualSize); this.System.OnElementAreaUpdated?.Invoke(this); diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index f3854a0..f6d27e4 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -149,8 +149,7 @@ namespace Sandbox { var testPanel = new Panel(Anchor.Center, new Vector2(0.5F, 100), Vector2.Zero); testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(0.25F, -1))); - testPanel.AddChild(new Button(Anchor.AutoInline, new Vector2(0.25F, -1.5F))); - testPanel.AddChild(new Button(Anchor.AutoInline, new Vector2(0.5F, -1))); + testPanel.AddChild(new Button(Anchor.AutoLeft, new Vector2(2500, 1)) {PreventParentSpill = true}); this.UiSystem.Add("Test", testPanel); }