1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38: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.Text = new Paragraph(Anchor.Center, 1, text, true);
this.AddChild(this.Text); this.AddChild(this.Text);
} }
if (tooltipText != null) { if (tooltipText != null)
this.Tooltip = new Tooltip(tooltipWidth, tooltipText); this.Tooltip = new Tooltip(tooltipWidth, tooltipText, this);
this.OnMouseEnter += element => this.System.Add("ButtonTooltip", this.Tooltip);
this.OnMouseExit += element => this.System.Remove("ButtonTooltip");
}
} }
public override void Draw(GameTime time, SpriteBatch batch, float alpha, Point offset) { 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 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) { base(Anchor.TopLeft, width, text) {
this.AutoAdjustWidth = true; this.AutoAdjustWidth = true;
this.Padding = new Point(2); 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) { public override void Update(GameTime time) {