From 8fac4a0b697b052c1da4369c279eb81c1f8550e8 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 24 Jul 2021 07:36:42 +0200 Subject: [PATCH] Allow adding Link children to non-Paragraph elements --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Paragraph.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90de437..39d0a4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Additions Improvements - Removed LINQ Any and All usage in various methods to improve memory usage - Explicitly disallow creating Paragraphs without fonts to make starting out with MLEM.Ui less confusing +- Allow adding Link children to non-Paragraph elements Fixes - Fixed a crash if a paragraph has a link formatting code, but no font diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index f182ee8..d23d3b6 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -237,7 +237,9 @@ namespace MLEM.Ui.Elements { public override void ForceUpdateArea() { // set the position offset and size to the token's first area var area = this.Token.GetArea(Vector2.Zero, this.textScale).FirstOrDefault(); - this.PositionOffset = area.Location + new Vector2(((Paragraph) this.Parent).GetAlignmentOffset() / this.Parent.Scale, 0); + if (this.Parent is Paragraph p) + area.Location += new Vector2(p.GetAlignmentOffset() / p.Scale, 0); + this.PositionOffset = area.Location; this.IsHidden = area.IsEmpty; this.Size = area.Size; base.ForceUpdateArea();