From 03923f91f6ae778a3807a4f6301568f7b2baea49 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 13 Sep 2019 11:53:28 +0200 Subject: [PATCH] some exception handling --- MLEM.Ui/Elements/Element.cs | 10 ++++++---- MLEM.Ui/Elements/Image.cs | 3 ++- MLEM.Ui/Elements/Paragraph.cs | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 8c1c901..30e42dd 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -305,10 +305,12 @@ namespace MLEM.Ui.Elements { if (this.SetHeightBasedOnChildren && this.Children.Count > 0) { var lowest = this.GetLowestChild(e => !e.IsHidden); - var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Y) / this.Scale; - if (newHeight != this.size.Y) { - this.size.Y = newHeight; - this.ForceUpdateArea(); + if (lowest != null) { + var newHeight = (lowest.UnscrolledArea.Bottom - pos.Y + this.ScaledChildPadding.Y) / this.Scale; + if (newHeight != this.size.Y) { + this.size.Y = newHeight; + this.ForceUpdateArea(); + } } } } diff --git a/MLEM.Ui/Elements/Image.cs b/MLEM.Ui/Elements/Image.cs index 38ce989..c1d2036 100644 --- a/MLEM.Ui/Elements/Image.cs +++ b/MLEM.Ui/Elements/Image.cs @@ -14,6 +14,7 @@ namespace MLEM.Ui.Elements { set { if (this.texture != value) { this.texture = value; + this.IsHidden = this.texture == null; if (this.scaleToImage) this.SetAreaDirty(); } @@ -42,7 +43,7 @@ namespace MLEM.Ui.Elements { } protected override Point CalcActualSize(Rectangle parentArea) { - return this.scaleToImage ? this.texture.Size : base.CalcActualSize(parentArea); + return this.texture != null && this.scaleToImage ? this.texture.Size : base.CalcActualSize(parentArea); } public override void Draw(GameTime time, SpriteBatch batch, float alpha) { diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 0fcda97..0fac150 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -29,6 +29,7 @@ namespace MLEM.Ui.Elements { set { if (this.text != value) { this.text = value; + this.IsHidden = string.IsNullOrWhiteSpace(this.text); this.SetAreaDirty(); } }