diff --git a/CHANGELOG.md b/CHANGELOG.md index 6368be1..a419cb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Additions Fixes - Fixed images not updating their hidden state properly when the displayed texture changes - Fixed AutoInline elements overflowing into their parent if it's taller +- Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly Improvements - Increased Element area calculation recursion limit to 64 diff --git a/MLEM.Ui/Elements/Checkbox.cs b/MLEM.Ui/Elements/Checkbox.cs index 1925202..291f8e6 100644 --- a/MLEM.Ui/Elements/Checkbox.cs +++ b/MLEM.Ui/Elements/Checkbox.cs @@ -106,13 +106,12 @@ namespace MLEM.Ui.Elements { } /// - protected override Vector2 CalcActualSize(RectangleF parentArea) { - var size = base.CalcActualSize(parentArea); + public override void SetAreaAndUpdateChildren(RectangleF area) { + base.SetAreaAndUpdateChildren(area); if (this.Label != null) { - this.Label.Size = new Vector2((size.X - size.Y) / this.Scale - this.TextOffsetX, 1); - this.Label.PositionOffset = new Vector2(size.Y / this.Scale + this.TextOffsetX, 0); + this.Label.Size = new Vector2((area.Width - area.Height) / this.Scale - this.TextOffsetX, 1); + this.Label.PositionOffset = new Vector2(area.Height / this.Scale + this.TextOffsetX, 0); } - return size; } /// diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index d73228c..1bd9eb1 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -175,6 +175,13 @@ namespace MLEM.Ui.Elements { this.CanBeMoused = false; } + /// + public override void SetAreaAndUpdateChildren(RectangleF area) { + base.SetAreaAndUpdateChildren(area); + // in case an outside source sets our area, we still want to display our text correctly + this.AlignAndSplitIfNecessary(area.Size); + } + /// protected override Vector2 CalcActualSize(RectangleF parentArea) { var size = base.CalcActualSize(parentArea); @@ -182,6 +189,9 @@ namespace MLEM.Ui.Elements { this.TokenizeIfNecessary(); this.AlignAndSplitIfNecessary(size); var textSize = this.tokenizedText.GetArea(Vector2.Zero, this.TextScale * this.TextScaleMultiplier * this.Scale).Size; + // if we auto-adjust our width, then we would also split the same way with our adjusted width, so cache that + if (this.AutoAdjustWidth) + this.lastAlignSplitWidth = textSize.X; return new Vector2(this.AutoAdjustWidth ? textSize.X + this.ScaledPadding.Width : size.X, textSize.Y + this.ScaledPadding.Height); } @@ -255,7 +265,7 @@ namespace MLEM.Ui.Elements { var width = size.X - this.ScaledPadding.Width; var scale = this.TextScale * this.TextScaleMultiplier * this.Scale; - if (this.lastAlignSplitWidth == width && this.lastAlignSplitScale == scale) + if (this.lastAlignSplitWidth?.Equals(width, Element.Epsilon) == true && this.lastAlignSplitScale?.Equals(scale, Element.Epsilon) == true) return; this.lastAlignSplitWidth = width; this.lastAlignSplitScale = scale;