mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +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>
|
||||
public Tooltip(float width, string text = null, Element elementToHover = null) :
|
||||
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.AutoAdjustWidth = true;
|
||||
}
|
||||
this.SetWidthBasedOnChildren = true;
|
||||
this.SetHeightBasedOnChildren = true;
|
||||
this.ChildPadding = new Vector2(2);
|
||||
this.CanBeMoused = false;
|
||||
this.Init(elementToHover);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new tooltip with the given settings
|
||||
/// </summary>
|
||||
/// <param name="width">The width of the tooltip</param>
|
||||
/// <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>
|
||||
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 />
|
||||
|
@ -124,5 +122,23 @@ namespace MLEM.Ui.Elements {
|
|||
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