mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
added a Tooltip constructor that uses TextCallback for the paragraph
This commit is contained in:
parent
81f8485022
commit
e783f4f769
1 changed files with 31 additions and 15 deletions
|
@ -34,23 +34,21 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
||||||
public Tooltip(float width, string text = null, Element elementToHover = null) :
|
public Tooltip(float width, string text = null, Element elementToHover = null) :
|
||||||
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
||||||
if (text != null) {
|
if (text != null)
|
||||||
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text));
|
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, text));
|
||||||
this.Paragraph.AutoAdjustWidth = true;
|
this.Init(elementToHover);
|
||||||
}
|
}
|
||||||
this.SetWidthBasedOnChildren = true;
|
|
||||||
this.SetHeightBasedOnChildren = true;
|
|
||||||
this.ChildPadding = new Vector2(2);
|
|
||||||
this.CanBeMoused = false;
|
|
||||||
|
|
||||||
if (elementToHover != null) {
|
/// <summary>
|
||||||
elementToHover.OnMouseEnter += element => {
|
/// Creates a new tooltip with the given settings
|
||||||
// only display the tooltip if there is anything in it
|
/// </summary>
|
||||||
if (this.Children.Any(c => !c.IsHidden))
|
/// <param name="width">The width of the tooltip</param>
|
||||||
this.Display(element.System, element.GetType().Name + "Tooltip");
|
/// <param name="textCallback">The text to display on the tooltip</param>
|
||||||
};
|
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
|
||||||
elementToHover.OnMouseExit += element => this.Remove();
|
public Tooltip(float width, Paragraph.TextCallback textCallback, Element elementToHover = null) :
|
||||||
}
|
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
|
||||||
|
this.Paragraph = this.AddChild(new Paragraph(Anchor.TopLeft, width, textCallback));
|
||||||
|
this.Init(elementToHover);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -124,5 +122,23 @@ namespace MLEM.Ui.Elements {
|
||||||
this.System.Remove(this.Root.Name);
|
this.System.Remove(this.Root.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Init(Element elementToHover) {
|
||||||
|
this.Paragraph.AutoAdjustWidth = true;
|
||||||
|
|
||||||
|
this.SetWidthBasedOnChildren = true;
|
||||||
|
this.SetHeightBasedOnChildren = true;
|
||||||
|
this.ChildPadding = new Vector2(2);
|
||||||
|
this.CanBeMoused = false;
|
||||||
|
|
||||||
|
if (elementToHover != null) {
|
||||||
|
elementToHover.OnMouseEnter += element => {
|
||||||
|
// only display the tooltip if there is anything in it
|
||||||
|
if (this.Children.Any(c => !c.IsHidden))
|
||||||
|
this.Display(element.System, element.GetType().Name + "Tooltip");
|
||||||
|
};
|
||||||
|
elementToHover.OnMouseExit += element => this.Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue