1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-25 14:08:34 +01:00

Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly

This commit is contained in:
Ell 2023-04-06 15:54:24 +02:00
parent 4994bb3d5d
commit 1a7cb65cf2
3 changed files with 16 additions and 6 deletions

View file

@ -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

View file

@ -106,13 +106,12 @@ namespace MLEM.Ui.Elements {
}
/// <inheritdoc />
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;
}
/// <inheritdoc />

View file

@ -175,6 +175,13 @@ namespace MLEM.Ui.Elements {
this.CanBeMoused = false;
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
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;