From 7f4cc773ec5eaa17138c05732c13bcc7f02152b9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 30 Mar 2024 12:24:57 +0100 Subject: [PATCH] Fixed scrolling panels calculating their height incorrectly when their first child is hidden --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Panel.cs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf845d..4b36196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Improvements Fixes - Fixed panels updating their relevant children too much when the scroll bar is hidden - Fixed a stack overflow exception when a panel's scroll bar auto-hiding causes elements to gain height +- Fixed scrolling panels calculating their height incorrectly when their first child is hidden ### MLEM.Extended Improvements diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 65b974f..5c87a01 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -223,10 +223,10 @@ namespace MLEM.Ui.Elements { /// /// The y coordinate to scroll to, which should have this element's applied. public void ScrollToElement(float elementY) { - var firstChild = this.Children.FirstOrDefault(c => c != this.ScrollBar); - if (firstChild == null) + var highestValidChild = this.Children.FirstOrDefault(c => c != this.ScrollBar && !c.IsHidden); + if (highestValidChild == null) return; - this.ScrollBar.CurrentValue = (elementY - this.Area.Height / 2 - firstChild.Area.Top) / this.Scale + this.ChildPadding.Value.Height / 2; + this.ScrollBar.CurrentValue = (elementY - this.Area.Height / 2 - highestValidChild.Area.Top) / this.Scale + this.ChildPadding.Value.Height / 2; } /// @@ -282,9 +282,9 @@ namespace MLEM.Ui.Elements { float childrenHeight; if (this.Children.Count > 1) { - var firstChild = this.Children.FirstOrDefault(c => c != this.ScrollBar); + var highestValidChild = this.Children.FirstOrDefault(c => c != this.ScrollBar && !c.IsHidden); var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden, true); - childrenHeight = lowestChild.GetTotalCoveredArea(false).Bottom - firstChild.Area.Top; + childrenHeight = lowestChild.GetTotalCoveredArea(false).Bottom - highestValidChild.Area.Top; } else { // if we only have one child (the scroll bar), then the children take up no visual height childrenHeight = 0;