From 98118e540aaf0fb70e8942c5ebf1f14df418dedc Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 4 May 2022 13:22:24 +0200 Subject: [PATCH] Allow manually hiding a paragraph without its text overriding the hidden state --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Paragraph.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 809fb83..cc6c365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Improvements - Turned Tooltip paragraph styling into style properties - Improved ElementHelper.AddTooltip overloads - Don't query a paragraph's text callback in the constructor +- Allow manually hiding a paragraph without its text overriding the hidden state Fixes - Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 3f127b5..1d29a06 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -59,7 +59,7 @@ namespace MLEM.Ui.Elements { set { if (this.text != value) { this.text = value; - this.IsHidden = string.IsNullOrWhiteSpace(this.text); + this.forceHide = string.IsNullOrWhiteSpace(this.text); this.SetTextDirty(); } } @@ -99,9 +99,13 @@ namespace MLEM.Ui.Elements { } } + /// + public override bool IsHidden => base.IsHidden || this.forceHide; + private string text; private StyleProp alignment; private StyleProp regularFont; + private bool forceHide; /// /// Creates a new paragraph with the given settings. @@ -110,14 +114,12 @@ namespace MLEM.Ui.Elements { /// The paragraph's width. Note that its height is automatically calculated. /// The paragraph's text /// Whether the paragraph's width should automatically be calculated based on the text within it. - public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool autoAdjustWidth = false) : this(anchor, width, "", autoAdjustWidth) { - this.IsHidden = true; + public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool autoAdjustWidth = false) : this(anchor, width, string.Empty, autoAdjustWidth) { this.GetTextCallback = textCallback; } /// public Paragraph(Anchor anchor, float width, string text, bool autoAdjustWidth = false) : base(anchor, new Vector2(width, 0)) { - this.IsHidden = true; this.Text = text; this.AutoAdjustWidth = autoAdjustWidth; this.CanBeSelected = false;