From 30432e43d4e2849a2761cf45fd3df1fbdad293e8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 21 May 2023 11:19:24 +0200 Subject: [PATCH] Fixed dropdown menu panels not updating their width when the dropdown's width changes --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Dropdown.cs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 149dc1a..4fd3a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Fixes - Fixed AutoInline elements overflowing into their parent if it's taller - Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly - Fixed TextInput and Slider still reacting to input when they are selected, but not part of the active root +- Fixed dropdown menu panels not updating their width when the dropdown's width changes ### MLEM.Data Improvements diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index 3c1b46e..e9f080f 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -37,10 +37,13 @@ namespace MLEM.Ui.Elements { /// The text displayed on the dropdown button /// The text displayed as a tooltip when hovering over the dropdown button public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null) : base(anchor, size, text, tooltipText) { - this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) { + this.Panel = this.AddChild(new Panel(Anchor.TopCenter, Vector2.Zero, Vector2.Zero, true) { IsHidden = true }); - this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale); + this.OnAreaUpdated += e => { + this.Panel.Size = new Vector2(e.Area.Width / e.Scale, 0); + this.Panel.PositionOffset = new Vector2(0, e.Area.Height / e.Scale); + }; this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0; this.OnPressed += e => { this.IsOpen = !this.IsOpen;