From 6faba05b24fdfe9eb78c6b4f00ded35b9691e349 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 19 Dec 2019 12:50:50 +0100 Subject: [PATCH] made elements be able to set both width and height automatically --- MLEM.Ui/Elements/Element.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index b19fa0b..a514592 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -316,25 +316,29 @@ namespace MLEM.Ui.Elements { child.ForceUpdateArea(); if (this.Children.Count > 0) { + var changed = false; if (this.SetHeightBasedOnChildren) { var lowest = this.GetLowestChild(e => !e.IsHidden); if (lowest != null) { var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom) / this.Scale; if ((int) newHeight != (int) this.size.Y) { this.size.Y = newHeight; - this.ForceUpdateArea(); + changed = true; } } - } else if (this.SetWidthBasedOnChildren) { + } + if (this.SetWidthBasedOnChildren) { var rightmost = this.GetRightmostChild(e => !e.IsHidden); if (rightmost != null) { var newWidth = (rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right) / this.Scale; if ((int) newWidth != (int) this.size.X) { this.size.X = newWidth; - this.ForceUpdateArea(); + changed = true; } } } + if (changed) + this.ForceUpdateArea(); } }