1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

more easily allow tooltips to show when hovering elements

This commit is contained in:
Ellpeck 2019-08-24 20:45:40 +02:00
parent 13c7aa90e2
commit cc66c453c5
2 changed files with 8 additions and 6 deletions

View file

@ -18,11 +18,8 @@ namespace MLEM.Ui.Elements {
this.Text = new Paragraph(Anchor.Center, 1, text, true);
this.AddChild(this.Text);
}
if (tooltipText != null) {
this.Tooltip = new Tooltip(tooltipWidth, tooltipText);
this.OnMouseEnter += element => this.System.Add("ButtonTooltip", this.Tooltip);
this.OnMouseExit += element => this.System.Remove("ButtonTooltip");
}
if (tooltipText != null)
this.Tooltip = new Tooltip(tooltipWidth, tooltipText, this);
}
public override void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) {

View file

@ -9,10 +9,15 @@ namespace MLEM.Ui.Elements {
public Vector2 MouseOffset = new Vector2(2, 3);
public Tooltip(float width, string text) :
public Tooltip(float width, string text, Element elementToHover = null) :
base(Anchor.TopLeft, width, text) {
this.AutoAdjustWidth = true;
this.Padding = new Point(2);
if (elementToHover != null) {
elementToHover.OnMouseEnter += element => element.System.Add(element.GetType().Name + "Tooltip", this);
elementToHover.OnMouseExit += element => element.System.Remove(element.GetType().Name + "Tooltip");
}
}
public override void Update(GameTime time) {