diff --git a/MLEM.Ui/Elements/Button.cs b/MLEM.Ui/Elements/Button.cs index 1669a93..31910bc 100644 --- a/MLEM.Ui/Elements/Button.cs +++ b/MLEM.Ui/Elements/Button.cs @@ -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) { diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index 141272c..d69a8f2 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -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) {