mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
explicitly disallow auto-sizing incompatibilities to make debugging easier
This commit is contained in:
parent
f60c3b288a
commit
f94d471365
2 changed files with 13 additions and 1 deletions
|
@ -626,30 +626,37 @@ namespace MLEM.Ui.Elements {
|
|||
if (this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren) {
|
||||
Element foundChild = null;
|
||||
var autoSize = this.UnscrolledArea.Size;
|
||||
|
||||
if (this.SetHeightBasedOnChildren) {
|
||||
var lowest = this.GetLowestChild(e => !e.IsHidden);
|
||||
if (lowest != null) {
|
||||
autoSize.Y = lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom;
|
||||
foundChild = lowest;
|
||||
} else {
|
||||
if (this.Children.Count > 0)
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its height based on children but it only has children anchored too low ({string.Join(", ", this.Children.Select(c => c.Anchor))})");
|
||||
autoSize.Y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.SetWidthBasedOnChildren) {
|
||||
var rightmost = this.GetRightmostChild(e => !e.IsHidden);
|
||||
if (rightmost != null) {
|
||||
autoSize.X = rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right;
|
||||
foundChild = rightmost;
|
||||
} else {
|
||||
if (this.Children.Count > 0)
|
||||
throw new InvalidOperationException($"{this} with root {this.Root.Name} sets its width based on children but it only has children anchored too far right ({string.Join(", ", this.Children.Select(c => c.Anchor))})");
|
||||
autoSize.X = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.TreatSizeAsMinimum)
|
||||
autoSize = Vector2.Max(autoSize, actualSize);
|
||||
if (!autoSize.Equals(this.UnscrolledArea.Size, 0.01F)) {
|
||||
recursion++;
|
||||
if (recursion >= 16) {
|
||||
throw new ArithmeticException($"The area of {this} with root {this.Root?.Name} has recursively updated too often. Does its child {foundChild} contain any conflicting auto-sizing settings?");
|
||||
throw new ArithmeticException($"The area of {this} with root {this.Root.Name} has recursively updated too often. Does its child {foundChild} contain any conflicting auto-sizing settings?");
|
||||
} else {
|
||||
UpdateDisplayArea(autoSize);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ namespace Tests {
|
|||
invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true));
|
||||
invalidPanel.AddChild(new VerticalSpace(1));
|
||||
Assert.Throws<ArithmeticException>(() => this.AddAndUpdate(invalidPanel));
|
||||
|
||||
invalidPanel = new Panel(Anchor.Center, Vector2.Zero, Vector2.Zero, true);
|
||||
invalidPanel.AddChild(new Group(Anchor.CenterRight, new Vector2(10), false));
|
||||
invalidPanel.AddChild(new Group(Anchor.BottomLeft, new Vector2(10), false));
|
||||
Assert.Throws<InvalidOperationException>(() => this.AddAndUpdate(invalidPanel));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
Loading…
Reference in a new issue