From f2939253b1934bdfbaff5590282e552644148823 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 1 Nov 2021 13:39:37 +0100 Subject: [PATCH] Skip unnecessary area updates for elements with dirty parents --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Element.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b435f63..5d36f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Improvements - Added style properties for a lot of hardcoded default element styles - Allow style properties to set style values with a higher priority, which allows elements to style their default children - Allow changing the entire ui style for a single element +- Skip unnecessary area updates for elements with dirty parents Fixes - Fixed VerticalSpace height parameter being an integer diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 19bfa3a..c468aaa 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -531,6 +531,12 @@ namespace MLEM.Ui.Elements { this.areaDirty = false; if (this.IsHidden) return; + // if the parent's area is dirty, it would get updated anyway when querying its ChildPaddedArea, + // which would cause our ForceUpdateArea code to be run twice, so we only update our parent instead + if (this.Parent != null && this.Parent.areaDirty) { + this.Parent.ForceUpdateArea(); + return; + } var parentArea = this.Parent != null ? this.Parent.ChildPaddedArea : (RectangleF) this.system.Viewport; var parentCenterX = parentArea.X + parentArea.Width / 2;