TooltipManager

Package: Libraries.Interface · Inherits from: Libraries.Language.Object

The TooltipManager class shows, places and hides the tooltips of a game's controls. A game has one, which it updates every frame; get it with GetTooltipManager on the game or on a GameStateManager. At most one tooltip shows at a time. A tooltip shows when the mouse rests on a control with tooltips turned on (SetTooltipEnabled) for the show delay, half a second by default. Moving to another such control while one shows switches at once. Leaving the control hides it after a short grace time (0.3 seconds), unless the mouse has moved onto the tooltip itself, and pressing the mouse on the control hides it. From the keyboard, Shift+F1 shows the focused control's tooltip at once, and pressing it again, Escape, or moving the focus hides it. A tooltip with buttons (IsTooltipInteractive) takes the focus on its first button; Tab and Shift+Tab move among its buttons, and Escape closes it and returns the focus to the control. Controls never show their own tooltip; they ask the manager, with ShowTooltip and HideTooltip on Control.

Example Code

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

Form form
Page page = form:GetMainPage()

Button button = page:AddButton("Save")
button:SetDescription("Saves the file to the disk")
button:SetTooltipEnabled(true)

// Show tooltips sooner, after a quarter of a second.
GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:SetShowDelay(0.25)

form:Display()

Actions

Escape()

This action is what Escape does: it hides the tooltip if one shows, and returns whether it did.

Returns

boolean: true if a tooltip was hidden.

Example

use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
boolean closed = tooltips:Escape()

GetHideDelay()

This action returns how long a tooltip stays after the mouse leaves its control and the tooltip, in seconds.

Returns

number: The grace time, in seconds.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
number delay = tooltips:GetHideDelay()

GetOwner()

This action returns the control whose tooltip shows, or undefined.

Returns

Libraries.Interface.Controls.Control: The control whose tooltip shows.

Example

use Libraries.Interface.Controls.Control
use Libraries.Interface.TooltipManager

TooltipManager tooltips
Control control = tooltips:GetOwner()

GetShowDelay()

This action returns how long the mouse rests on a control before its tooltip shows, in seconds.

Returns

number: The delay, in seconds.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
number delay = tooltips:GetShowDelay()

GetTitleFont()

This action returns the font of tooltips' titles, or undefined when they use the text's font.

Returns

Libraries.Game.Graphics.Font: The titles' font.

Example

use Libraries.Interface.TooltipManager
use Libraries.Game.Graphics.Font

TooltipManager tooltips
Font font = tooltips:GetTitleFont()

GetTooltip()

This action returns the tooltip the manager shows. There is one for the whole game, filled for each control in turn.

Returns

Libraries.Interface.Controls.Tooltip: The tooltip.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.TooltipManager

TooltipManager tooltips
Tooltip tooltip = tooltips:GetTooltip()

HideTooltip()

This action hides the tooltip, if one shows. If the focus was inside it, the focus goes back to its control.

Example

use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:HideTooltip()

IsShowing()

This action returns whether a tooltip is showing.

Returns

boolean: true if a tooltip shows.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
boolean open = tooltips:IsShowing()

IsShowingFor(Libraries.Interface.Controls.Control control)

This action returns whether the tooltip showing is for this control.

Parameters

Returns

boolean: true if the control's tooltip shows.

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
boolean open = tooltips:IsShowingFor(button)

IsShowingOnKeyboardFocus()

This action returns whether plain tooltips show by themselves when a control gets the focus from the keyboard.

Returns

boolean: true if tooltips show on keyboard focus.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
boolean automatic = tooltips:IsShowingOnKeyboardFocus()

LongPressBegan(Libraries.Interface.Item item)

This action is called when a finger is held on the screen, as a long press. If the item under it is, or is inside, a control with a tooltip, the tooltip shows. A button under the finger is let go of, so lifting the finger doesn't also press it. TooltipLongPressBehavior calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
button:SetDescription("Saves the file to the disk")
button:SetTooltipEnabled(true)
TooltipManager tooltips
tooltips:LongPressBegan(button)

LongPressEnded()

This action is called when the finger of a long press lifts. A tooltip the long press showed hides a moment later. TooltipLongPressBehavior calls this.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:LongPressEnded()

PointerEntered(Libraries.Interface.Controls.Control control)

This action is called when the mouse moves onto a control with tooltips turned on. The tooltip shows after the show delay, or at once if another control's tooltip is already showing. Control:BeginMouseOver calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
tooltips:PointerEntered(button)

PointerEnteredItem(Libraries.Interface.Controls.Control control)

This action is called when the mouse moves onto a control without a tooltip of its own. If the control is inside the open tooltip, such as one of its buttons, the mouse counts as being on the tooltip, which stays open. A button takes the mouse from the tooltip around it, so without this the tooltip would close as the mouse reached the button. Control:BeginMouseOver calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
tooltips:PointerEnteredItem(button)

PointerEnteredTooltip()

This action is called when the mouse moves onto the tooltip, which then stays open. Tooltip:BeginMouseOver calls this.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:PointerEnteredTooltip()

PointerLeft(Libraries.Interface.Controls.Control control)

This action is called when the mouse moves off a control with tooltips turned on. A tooltip showing for it hides after the grace time, unless the mouse moves onto the tooltip. Control:EndMouseOver calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
tooltips:PointerLeft(button)

PointerLeftItem(Libraries.Interface.Controls.Control control)

This action is called when the mouse moves off a control without a tooltip of its own. If the control is inside the open tooltip, the mouse counts as leaving the tooltip; moving onto another part of it right away keeps it open. Control:EndMouseOver calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
tooltips:PointerLeftItem(button)

PointerLeftTooltip()

This action is called when the mouse moves off the tooltip, which then hides after the grace time unless the mouse goes back onto it or its control. Tooltip:EndMouseOver calls this.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:PointerLeftTooltip()

PointerPressed(Libraries.Interface.Controls.Control control)

This action is called when the mouse is pressed on a control with tooltips turned on. Its tooltip hides, and doesn't come back until the mouse leaves the control and returns. Control:ClickedMouse calls this.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager

Button button
TooltipManager tooltips
tooltips:PointerPressed(button)

SetHideDelay(number seconds)

This action sets how long a tooltip stays after the mouse leaves its control and the tooltip, in seconds. The default is 0.3.

Parameters

  • seconds number: The grace time, in seconds.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:SetHideDelay(0.5)

SetShowDelay(number seconds)

This action sets how long the mouse rests on a control before its tooltip shows, in seconds. The default is 0.5. A control can choose its own with GetTooltipShowDelay.

Parameters

  • seconds number: The delay, in seconds.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:SetShowDelay(0.25)

SetShowOnKeyboardFocus(boolean show)

This action sets whether plain tooltips show by themselves when a control gets the focus from the keyboard, as many web pages do. It is off by default. It helps people who see the screen and use the keyboard; screen reader users hear the control's description either way.

Parameters

  • show boolean: true to show tooltips on keyboard focus.

Example

use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:SetShowOnKeyboardFocus(true)

SetTitleFont(Libraries.Game.Graphics.Font font)

This action sets the font of every tooltip's first line, its title, such as a bold font. With undefined, titles use the same font as the text.

Parameters

Example

use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager
use Libraries.Game.Graphics.Font

Font bold
bold:LoadFont("Arial Bold")
GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:SetTitleFont(bold)

Show(Libraries.Interface.Controls.Control control, boolean fromKeyboard)

This action shows a control's tooltip at once, closing any other. It does nothing if the control's tooltips are off, it has nothing to show, or it isn't showing on a layer, which gives it no place on the screen. When the keyboard shows a tooltip with buttons, the focus moves to its first button.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

Button button
button:SetDescription("Saves the file to the disk")
button:SetTooltipEnabled(true)
GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:Show(button, true)

ToggleFromKeyboard(Libraries.Interface.Item focus)

This action is what Shift+F1 does: it shows the tooltip of the focused control, or of the nearest control around it with tooltips turned on, or hides the tooltip if one already shows for it or the focus is inside the tooltip.

Parameters

Example

use Libraries.Interface.Controls.Button
use Libraries.Interface.TooltipManager
use Libraries.Game.GameStateManager

Button button
button:SetDescription("Saves the file to the disk")
button:SetTooltipEnabled(true)
GameStateManager manager
TooltipManager tooltips = manager:GetTooltipManager()
tooltips:ToggleFromKeyboard(button)

Update(number seconds)

This action is called by the game once per frame. It counts down the show delay and the grace time, and hides the tooltip when its control goes away or the focus leaves it. Most users won't need to call it.

Parameters

  • seconds number: The time since the last frame, in seconds.

Example

use Libraries.Interface.TooltipManager

TooltipManager tooltips
tooltips:Update(0.016)

Inherited Actions

3 actions from Libraries.Language.Object