mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58: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) {
|
if (this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren) {
|
||||||
Element foundChild = null;
|
Element foundChild = null;
|
||||||
var autoSize = this.UnscrolledArea.Size;
|
var autoSize = this.UnscrolledArea.Size;
|
||||||
|
|
||||||
if (this.SetHeightBasedOnChildren) {
|
if (this.SetHeightBasedOnChildren) {
|
||||||
var lowest = this.GetLowestChild(e => !e.IsHidden);
|
var lowest = this.GetLowestChild(e => !e.IsHidden);
|
||||||
if (lowest != null) {
|
if (lowest != null) {
|
||||||
autoSize.Y = lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom;
|
autoSize.Y = lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom;
|
||||||
foundChild = lowest;
|
foundChild = lowest;
|
||||||
} else {
|
} 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;
|
autoSize.Y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.SetWidthBasedOnChildren) {
|
if (this.SetWidthBasedOnChildren) {
|
||||||
var rightmost = this.GetRightmostChild(e => !e.IsHidden);
|
var rightmost = this.GetRightmostChild(e => !e.IsHidden);
|
||||||
if (rightmost != null) {
|
if (rightmost != null) {
|
||||||
autoSize.X = rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right;
|
autoSize.X = rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right;
|
||||||
foundChild = rightmost;
|
foundChild = rightmost;
|
||||||
} else {
|
} 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;
|
autoSize.X = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.TreatSizeAsMinimum)
|
if (this.TreatSizeAsMinimum)
|
||||||
autoSize = Vector2.Max(autoSize, actualSize);
|
autoSize = Vector2.Max(autoSize, actualSize);
|
||||||
if (!autoSize.Equals(this.UnscrolledArea.Size, 0.01F)) {
|
if (!autoSize.Equals(this.UnscrolledArea.Size, 0.01F)) {
|
||||||
recursion++;
|
recursion++;
|
||||||
if (recursion >= 16) {
|
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 {
|
} else {
|
||||||
UpdateDisplayArea(autoSize);
|
UpdateDisplayArea(autoSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,11 @@ namespace Tests {
|
||||||
invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true));
|
invalidPanel.AddChild(new Paragraph(Anchor.AutoRight, 1, "This is some test text!", true));
|
||||||
invalidPanel.AddChild(new VerticalSpace(1));
|
invalidPanel.AddChild(new VerticalSpace(1));
|
||||||
Assert.Throws<ArithmeticException>(() => this.AddAndUpdate(invalidPanel));
|
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]
|
[Test]
|
||||||
|
|
Loading…
Reference in a new issue