mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
added methods for adding/removing tooltips easily
This commit is contained in:
parent
56db897c00
commit
b963941b5c
1 changed files with 28 additions and 15 deletions
|
@ -46,22 +46,10 @@ namespace MLEM.Ui.Elements {
|
|||
if (elementToHover != null) {
|
||||
elementToHover.OnMouseEnter += element => {
|
||||
// only display the tooltip if there is anything in it
|
||||
if (this.Children.All(c => c.IsHidden))
|
||||
return;
|
||||
element.System.Add(element.GetType().Name + "Tooltip", this);
|
||||
if (this.Delay <= TimeSpan.Zero) {
|
||||
this.IsHidden = false;
|
||||
this.SnapPositionToMouse();
|
||||
} else {
|
||||
this.IsHidden = true;
|
||||
this.delayCountdown = this.Delay;
|
||||
}
|
||||
};
|
||||
elementToHover.OnMouseExit += element => {
|
||||
this.delayCountdown = TimeSpan.Zero;
|
||||
if (this.System != null)
|
||||
this.System.Remove(this.Root.Name);
|
||||
if (this.Children.Any(c => !c.IsHidden))
|
||||
this.Display(element.System, element.GetType().Name + "Tooltip");
|
||||
};
|
||||
elementToHover.OnMouseExit += element => this.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,5 +99,30 @@ namespace MLEM.Ui.Elements {
|
|||
this.PositionOffset = offset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds this tooltip to the given <see cref="UiSystem"/> and either displays it directly or starts the <see cref="Delay"/> timer.
|
||||
/// </summary>
|
||||
/// <param name="system">The system to add this tooltip to</param>
|
||||
/// <param name="name">The name that this tooltip should use</param>
|
||||
public void Display(UiSystem system, string name) {
|
||||
system.Add(name, this);
|
||||
if (this.Delay <= TimeSpan.Zero) {
|
||||
this.IsHidden = false;
|
||||
this.SnapPositionToMouse();
|
||||
} else {
|
||||
this.IsHidden = true;
|
||||
this.delayCountdown = this.Delay;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes this tooltip from its <see cref="UiSystem"/> and resets the <see cref="Delay"/> timer, if there is one.
|
||||
/// </summary>
|
||||
public void Remove() {
|
||||
this.delayCountdown = TimeSpan.Zero;
|
||||
if (this.System != null)
|
||||
this.System.Remove(this.Root.Name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue