1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

fixed stack overflow with auto-sizing elements

This commit is contained in:
Ellpeck 2019-12-26 12:49:04 +01:00
parent 4640a59054
commit 937b1757fe
2 changed files with 18 additions and 2 deletions

View file

@ -321,7 +321,7 @@ namespace MLEM.Ui.Elements {
var lowest = this.GetLowestChild(e => !e.IsHidden);
if (lowest != null) {
var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom) / this.Scale;
if ((int) newHeight != (int) this.size.Y) {
if (!newHeight.Equals(this.size.Y, 0.01F)) {
this.size.Y = newHeight;
changed = true;
}
@ -331,7 +331,7 @@ namespace MLEM.Ui.Elements {
var rightmost = this.GetRightmostChild(e => !e.IsHidden);
if (rightmost != null) {
var newWidth = (rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right) / this.Scale;
if ((int) newWidth != (int) this.size.X) {
if (!newWidth.Equals(this.size.X, 0.01F)) {
this.size.X = newWidth;
changed = true;
}

View file

@ -13,6 +13,22 @@ namespace MLEM.Extensions {
return (int) Math.Ceiling(f);
}
public static bool Equals(this float first, float second, float tolerance) {
return Math.Abs(first- second) <= tolerance;
}
public static bool Equals(this Vector2 first, Vector2 second, float tolerance) {
return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance;
}
public static bool Equals(this Vector3 first, Vector3 second, float tolerance) {
return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance && Math.Abs(first.Z - second.Z) <= tolerance;
}
public static bool Equals(this Vector4 first, Vector4 second, float tolerance) {
return Math.Abs(first.X - second.X) <= tolerance && Math.Abs(first.Y - second.Y) <= tolerance && Math.Abs(first.Z - second.Z) <= tolerance && Math.Abs(first.W - second.W) <= tolerance;
}
public static Vector2 Floor(this Vector2 vec) {
return new Vector2(vec.X.Floor(), vec.Y.Floor());
}