From 543201d17897e2a353e4f67b14c6c7f6de01790d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 5 Nov 2021 23:22:39 +0100 Subject: [PATCH] ensure that relevant panel children are updated when children are changed --- MLEM.Ui/Elements/Panel.cs | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index aeb703c..f0221db 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -128,7 +128,7 @@ namespace MLEM.Ui.Elements { public override void ForceUpdateSortedChildren() { base.ForceUpdateSortedChildren(); if (this.scrollOverflow) - this.relevantChildrenDirty = true; + this.ForceUpdateRelevantChildren(); } /// @@ -147,24 +147,8 @@ namespace MLEM.Ui.Elements { protected override IList GetRelevantChildren() { var relevant = base.GetRelevantChildren(); if (this.scrollOverflow) { - if (this.relevantChildrenDirty) { - this.relevantChildrenDirty = false; - - var visible = this.GetRenderTargetArea(); - this.relevantChildren.Clear(); - foreach (var child in this.SortedChildren) { - if (child.Area.Intersects(visible)) { - this.relevantChildren.Add(child); - } else { - foreach (var c in child.GetChildren(regardGrandchildren: true)) { - if (c.Area.Intersects(visible)) { - this.relevantChildren.Add(child); - break; - } - } - } - } - } + if (this.relevantChildrenDirty) + this.ForceUpdateRelevantChildren(); relevant = this.relevantChildren; } return relevant; @@ -272,5 +256,23 @@ namespace MLEM.Ui.Elements { this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0); } + private void ForceUpdateRelevantChildren() { + this.relevantChildrenDirty = false; + this.relevantChildren.Clear(); + var visible = this.GetRenderTargetArea(); + foreach (var child in this.SortedChildren) { + if (child.Area.Intersects(visible)) { + this.relevantChildren.Add(child); + } else { + foreach (var c in child.GetChildren(regardGrandchildren: true)) { + if (c.Area.Intersects(visible)) { + this.relevantChildren.Add(child); + break; + } + } + } + } + } + } } \ No newline at end of file