diff --git a/CHANGELOG.md b/CHANGELOG.md index 17549d9..ac560db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Improvements - Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs - Allow Tooltip to manage more than one paragraph and make it easier to add new lines - Allow adding dropdown elements at a specified index +- Turned Tooltip paragraph styling into style properties Fixes - Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index d69f34f..62ac0b9 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -31,6 +31,37 @@ namespace MLEM.Ui.Elements { /// The amount of time that the mouse has to be over an element before it appears /// public StyleProp Delay; + /// + /// The that this tooltip's should have + /// + public StyleProp ParagraphTextColor { + get => this.paragraphTextColor; + set { + this.paragraphTextColor = value; + this.UpdateParagraphsStyles(); + } + } + /// + /// The that this tooltip's should have + /// + public StyleProp ParagraphTextScale { + get => this.paragraphTextScale; + set { + this.paragraphTextScale = value; + this.UpdateParagraphsStyles(); + } + } + /// + /// The width that this tooltip's should have + /// + public StyleProp ParagraphWidth { + get => this.paragraphWidth; + set { + this.paragraphWidth = value; + this.UpdateParagraphsStyles(); + } + } + /// /// The paragraph of text that this tooltip displays /// @@ -54,6 +85,9 @@ namespace MLEM.Ui.Elements { private TimeSpan delayCountdown; private bool autoHidden; private Element snapElement; + private StyleProp paragraphWidth; + private StyleProp paragraphTextScale; + private StyleProp paragraphTextColor; /// /// Creates a new tooltip with the given settings @@ -115,15 +149,11 @@ namespace MLEM.Ui.Elements { this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset); this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset); this.Delay = this.Delay.OrStyle(style.TooltipDelay); + this.ParagraphTextColor = this.ParagraphTextColor.OrStyle(style.TooltipTextColor); + this.ParagraphTextScale = this.ParagraphTextScale.OrStyle(style.TextScale); + this.ParagraphWidth = this.ParagraphWidth.OrStyle(style.TooltipTextWidth); this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding); - foreach (var paragraph in this.Paragraphs) - SetParagraphStyle(paragraph, style); - - #pragma warning disable CS0618 - // still set style here in case someone changed the paragraph field manually - if (this.Paragraph != null) - SetParagraphStyle(this.Paragraph, style); - #pragma warning restore CS0618 + this.UpdateParagraphsStyles(); } /// @@ -136,8 +166,7 @@ namespace MLEM.Ui.Elements { public Paragraph AddParagraph(Paragraph paragraph, int index = -1) { this.Paragraphs.Add(paragraph); this.AddChild(paragraph, index); - if (this.Style.HasValue()) - SetParagraphStyle(paragraph, this.Style); + this.UpdateParagraphStyle(paragraph); return paragraph; } @@ -262,9 +291,21 @@ namespace MLEM.Ui.Elements { } } - private static void SetParagraphStyle(Paragraph paragraph, UiStyle style) { - paragraph.TextColor = paragraph.TextColor.OrStyle(style.TooltipTextColor, 1); - paragraph.Size = new Vector2(style.TooltipTextWidth, 0); + private void UpdateParagraphsStyles() { + foreach (var paragraph in this.Paragraphs) + this.UpdateParagraphStyle(paragraph); + + #pragma warning disable CS0618 + // still set style here in case someone changed the paragraph field manually + if (this.Paragraph != null) + this.UpdateParagraphStyle(this.Paragraph); + #pragma warning restore CS0618 + } + + private void UpdateParagraphStyle(Paragraph paragraph) { + paragraph.TextColor = paragraph.TextColor.OrStyle(this.ParagraphTextColor, 1); + paragraph.TextScale = paragraph.TextScale.OrStyle(this.ParagraphTextScale, 1); + paragraph.Size = new Vector2(this.ParagraphWidth, 0); paragraph.AutoAdjustWidth = true; }