1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 02:09:24 +01:00

made elements be able to set both width and height automatically

This commit is contained in:
Ellpeck 2019-12-19 12:50:50 +01:00
parent c6fff090e6
commit 6faba05b24

View file

@ -316,27 +316,31 @@ namespace MLEM.Ui.Elements {
child.ForceUpdateArea(); child.ForceUpdateArea();
if (this.Children.Count > 0) { if (this.Children.Count > 0) {
var changed = false;
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) {
var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom) / this.Scale; var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Bottom) / this.Scale;
if ((int) newHeight != (int) this.size.Y) { if ((int) newHeight != (int) this.size.Y) {
this.size.Y = newHeight; this.size.Y = newHeight;
this.ForceUpdateArea(); changed = true;
} }
} }
} else 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) {
var newWidth = (rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right) / this.Scale; var newWidth = (rightmost.UnscrolledArea.Right - pos.X + this.ScaledChildPadding.Right) / this.Scale;
if ((int) newWidth != (int) this.size.X) { if ((int) newWidth != (int) this.size.X) {
this.size.X = newWidth; this.size.X = newWidth;
changed = true;
}
}
}
if (changed)
this.ForceUpdateArea(); this.ForceUpdateArea();
} }
} }
}
}
}
protected virtual Vector2 CalcActualSize(RectangleF parentArea) { protected virtual Vector2 CalcActualSize(RectangleF parentArea) {
return new Vector2( return new Vector2(