mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-24 17:29:23 +01:00
more easily allow tooltips to show when hovering elements
This commit is contained in:
parent
13c7aa90e2
commit
cc66c453c5
2 changed files with 8 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue