From 2463c27a5dbc465860fec68c0b007e6bdf408347 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 22 May 2023 11:29:41 +0200 Subject: [PATCH] Remove all elements from a UiSystem when it is disposed --- CHANGELOG.md | 1 + MLEM.Ui/UiSystem.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd3a63..ff2d522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Improvements - Improved the SquishingGroup algorithm by prioritizing each element's final size - Allow specifying start and end indices when drawing a Paragraph - Allow elements with larger children to influence a panel's scrollable area +- Remove all elements from a UiSystem when it is disposed Fixes - Fixed images not updating their hidden state properly when the displayed texture changes diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 4e96e2e..a96c4f2 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -419,6 +419,14 @@ namespace MLEM.Ui { root.Element.AndChildren(action); } + /// + protected override void Dispose(bool disposing) { + if (disposing) { + while (this.rootElements.Count > 0) + this.Remove(this.rootElements[0].Name); + } + } + internal void InvokeOnElementDrawn(Element element, GameTime time, SpriteBatch batch, float alpha) { this.OnElementDrawn?.Invoke(element, time, batch, alpha); }