mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Turned Tooltip paragraph styling into style properties
This commit is contained in:
parent
5a1b31e8a3
commit
15a57d8db9
2 changed files with 55 additions and 13 deletions
|
@ -25,6 +25,7 @@ Improvements
|
||||||
- Make use of the new consuming variants in InputHandler and Keybind to consume UiControls inputs
|
- 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 Tooltip to manage more than one paragraph and make it easier to add new lines
|
||||||
- Allow adding dropdown elements at a specified index
|
- Allow adding dropdown elements at a specified index
|
||||||
|
- Turned Tooltip paragraph styling into style properties
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
- Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode
|
||||||
|
|
|
@ -31,6 +31,37 @@ namespace MLEM.Ui.Elements {
|
||||||
/// The amount of time that the mouse has to be over an element before it appears
|
/// The amount of time that the mouse has to be over an element before it appears
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<TimeSpan> Delay;
|
public StyleProp<TimeSpan> Delay;
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="Elements.Paragraph.TextColor"/> that this tooltip's <see cref="Paragraphs"/> should have
|
||||||
|
/// </summary>
|
||||||
|
public StyleProp<Color> ParagraphTextColor {
|
||||||
|
get => this.paragraphTextColor;
|
||||||
|
set {
|
||||||
|
this.paragraphTextColor = value;
|
||||||
|
this.UpdateParagraphsStyles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="Elements.Paragraph.TextScale"/> that this tooltip's <see cref="Paragraphs"/> should have
|
||||||
|
/// </summary>
|
||||||
|
public StyleProp<float> ParagraphTextScale {
|
||||||
|
get => this.paragraphTextScale;
|
||||||
|
set {
|
||||||
|
this.paragraphTextScale = value;
|
||||||
|
this.UpdateParagraphsStyles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The width that this tooltip's <see cref="Paragraphs"/> should have
|
||||||
|
/// </summary>
|
||||||
|
public StyleProp<float> ParagraphWidth {
|
||||||
|
get => this.paragraphWidth;
|
||||||
|
set {
|
||||||
|
this.paragraphWidth = value;
|
||||||
|
this.UpdateParagraphsStyles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The paragraph of text that this tooltip displays
|
/// The paragraph of text that this tooltip displays
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -54,6 +85,9 @@ namespace MLEM.Ui.Elements {
|
||||||
private TimeSpan delayCountdown;
|
private TimeSpan delayCountdown;
|
||||||
private bool autoHidden;
|
private bool autoHidden;
|
||||||
private Element snapElement;
|
private Element snapElement;
|
||||||
|
private StyleProp<float> paragraphWidth;
|
||||||
|
private StyleProp<float> paragraphTextScale;
|
||||||
|
private StyleProp<Color> paragraphTextColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new tooltip with the given settings
|
/// Creates a new tooltip with the given settings
|
||||||
|
@ -115,15 +149,11 @@ namespace MLEM.Ui.Elements {
|
||||||
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
this.MouseOffset = this.MouseOffset.OrStyle(style.TooltipOffset);
|
||||||
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
|
this.AutoNavOffset = this.AutoNavOffset.OrStyle(style.TooltipAutoNavOffset);
|
||||||
this.Delay = this.Delay.OrStyle(style.TooltipDelay);
|
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);
|
this.ChildPadding = this.ChildPadding.OrStyle(style.TooltipChildPadding);
|
||||||
foreach (var paragraph in this.Paragraphs)
|
this.UpdateParagraphsStyles();
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -136,8 +166,7 @@ namespace MLEM.Ui.Elements {
|
||||||
public Paragraph AddParagraph(Paragraph paragraph, int index = -1) {
|
public Paragraph AddParagraph(Paragraph paragraph, int index = -1) {
|
||||||
this.Paragraphs.Add(paragraph);
|
this.Paragraphs.Add(paragraph);
|
||||||
this.AddChild(paragraph, index);
|
this.AddChild(paragraph, index);
|
||||||
if (this.Style.HasValue())
|
this.UpdateParagraphStyle(paragraph);
|
||||||
SetParagraphStyle(paragraph, this.Style);
|
|
||||||
return paragraph;
|
return paragraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,9 +291,21 @@ namespace MLEM.Ui.Elements {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetParagraphStyle(Paragraph paragraph, UiStyle style) {
|
private void UpdateParagraphsStyles() {
|
||||||
paragraph.TextColor = paragraph.TextColor.OrStyle(style.TooltipTextColor, 1);
|
foreach (var paragraph in this.Paragraphs)
|
||||||
paragraph.Size = new Vector2(style.TooltipTextWidth, 0);
|
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;
|
paragraph.AutoAdjustWidth = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue