From 55fae16768d0594a4d6d9cdbd8f8cfba2409a5ea Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 11 Dec 2021 17:39:49 +0100 Subject: [PATCH] Allow overriding SetAreaAndUpdateChildren and switch to using it in some locations --- MLEM.Ui/Elements/Element.cs | 4 ++-- MLEM.Ui/Elements/Panel.cs | 7 +++++-- MLEM.Ui/Elements/SquishingGroup.cs | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index faeee87..a0e8e29 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -646,7 +646,7 @@ namespace MLEM.Ui.Elements { newSize.Y = parentArea.Bottom - pos.Y; } - this.SetAreaDirectlyAndUpdateChildren(new RectangleF(pos, newSize)); + this.SetAreaAndUpdateChildren(new RectangleF(pos, newSize)); if (this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren) { Element foundChild = null; @@ -701,7 +701,7 @@ namespace MLEM.Ui.Elements { /// Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all. /// /// - public void SetAreaDirectlyAndUpdateChildren(RectangleF area) { + public virtual void SetAreaAndUpdateChildren(RectangleF area) { this.area = area; this.System.InvokeOnElementAreaUpdated(this); foreach (var child in this.Children) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 3d8fab6..8d8d663 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -104,12 +104,15 @@ namespace MLEM.Ui.Elements { throw new NotSupportedException($"A panel that scrolls overflow cannot contain another panel that scrolls overflow ({child})"); } } - base.ForceUpdateArea(); + this.SetScrollBarStyle(); + } + /// + public override void SetAreaAndUpdateChildren(RectangleF area) { + base.SetAreaAndUpdateChildren(area); this.ScrollChildren(); this.ScrollSetup(); - this.SetScrollBarStyle(); } private void ScrollChildren() { diff --git a/MLEM.Ui/Elements/SquishingGroup.cs b/MLEM.Ui/Elements/SquishingGroup.cs index 7d29fa6..fe8acda 100644 --- a/MLEM.Ui/Elements/SquishingGroup.cs +++ b/MLEM.Ui/Elements/SquishingGroup.cs @@ -20,13 +20,13 @@ namespace MLEM.Ui.Elements { } /// - public override void ForceUpdateArea() { - base.ForceUpdateArea(); + public override void SetAreaAndUpdateChildren(RectangleF area) { + base.SetAreaAndUpdateChildren(area); // we squish children in order of priority, since auto-anchoring is based on addition order for (var i = 0; i < this.SortedChildren.Count; i++) { var child = this.SortedChildren[i]; if (SquishChild(child, out var squished)) - child.SetAreaDirectlyAndUpdateChildren(squished); + child.SetAreaAndUpdateChildren(squished); } }