Tooltip

Package: Libraries.Interface.Controls · Inherits from: Libraries.Interface.Item, Libraries.Interface.Controls.Control, Libraries.Interface.Item2D, Libraries.Language.Object

The Tooltip class is the small panel of help that appears beside a control when the mouse rests on it, or when the user presses Shift+F1 while the control has the focus. It holds the control's tooltip text, wrapped to a comfortable width, or other content the control gives it, such as a few lines and a button. It floats above everything else in the game, so it is never cut off by a scroll pane, and it takes its colors from the interface options under the key "Tooltip". Programs don't make or show a Tooltip themselves. A control's tooltip is turned on with SetTooltipEnabled, and the game's TooltipManager shows it, places it and hides it. To change what a control's tooltip shows, set its text with SetTooltipText, or, in a subclass of Control, override GetTooltipText or CreateTooltipContent.

Example Code

use Libraries.Interface.Forms.Form
use Libraries.Interface.Forms.Page
use Libraries.Interface.Controls.Button

Form form
Page page = form:GetMainPage()

// Resting the mouse on the button, or pressing Shift+F1 while it has the
// focus, shows a Tooltip with its description.
Button button = page:AddButton("Save")
button:SetDescription("Saves the file to the disk")
button:SetTooltipEnabled(true)

form:Display()

Actions

Close()

This action closes the tooltip, if it is open. If the focus was inside it, the focus goes back to where it was when the tooltip opened. The TooltipManager calls this, so most users won't need to call it directly.

Example

use Libraries.Interface.Controls.Tooltip

Tooltip tooltip
tooltip:Close()

Contains(Libraries.Interface.Item item)

This action returns whether the item is the tooltip or inside it, such as a button in its content.

Parameters

Returns

boolean: true if the item is part of the tooltip.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Controls.Button

Tooltip tooltip
Button button
boolean inside = tooltip:Contains(button)

Fill(Libraries.Interface.Controls.Control control, Libraries.Interface.Controls.Control newContent, text title, text value)

This action fills the tooltip for a control and sizes it to fit. An optional first line, the title, goes at the top, such as a button's name and key. Below it, with no content, the tooltip shows the text, wrapped to about 320 points; otherwise it shows the content. The TooltipManager calls this before the tooltip opens, so most users won't need to call it directly.

Parameters

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Controls.Button

Button button
button:SetName("Save")
Tooltip tooltip
tooltip:Fill(button, undefined, "Save, Control + S", "Saves the file to the disk")

GetContent()

This action returns the content the control gave the tooltip, or undefined when the tooltip shows plain text.

Returns

Libraries.Interface.Controls.Control: The tooltip's content.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Controls.Control

Tooltip tooltip
Control content = tooltip:GetContent()

GetFocusableItems()

This action returns the focusable items inside the tooltip's content, in order, such as its buttons. A tooltip with plain text has none.

Returns

Libraries.Containers.Array<Libraries.Interface.Item2D>: The focusable items in the content.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Item2D
use Libraries.Containers.Array

Tooltip tooltip
Array<Item2D> stops = tooltip:GetFocusableItems()

GetOwner()

This action returns the control the tooltip is showing for, or undefined when it is closed.

Returns

Libraries.Interface.Controls.Control: The control whose tooltip this is.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Controls.Control

Tooltip tooltip
Control control = tooltip:GetOwner()

GetText()

This action returns everything the tooltip says: its title, if it has one, then its text. This is also its name, which screen readers read.

Returns

text: The tooltip's words.

Example

use Libraries.Interface.Controls.Tooltip

Tooltip tooltip
text words = tooltip:GetText()

GetTitle()

This action returns the tooltip's first line, or an empty text when it has none.

Returns

text: The tooltip's title.

Example

use Libraries.Interface.Controls.Tooltip

Tooltip tooltip
text title = tooltip:GetTitle()

GetTitleFont()

This action returns the font of the tooltip's title, or undefined when it uses the text's font.

Returns

Libraries.Game.Graphics.Font: The title's font.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Game.Graphics.Font

Tooltip tooltip
Font font = tooltip:GetTitleFont()

IsAccessibleParent()

This action tells accessibility tools, such as screen readers, that the tooltip holds the controls inside it, so a tooltip with buttons is read as one group.

Returns

boolean: true, because a Tooltip contains its content for accessibility.

IsOpen()

This action returns whether the tooltip is open on the screen.

Returns

boolean: true if the tooltip is showing.

Example

use Libraries.Interface.Controls.Tooltip

Tooltip tooltip
boolean open = tooltip:IsOpen()

LoadGraphics(Libraries.Interface.Layouts.LayoutProperties properties)

This action loads the graphics for the tooltip. It gives the tooltip a ControlShaderView, which draws its rounded background and border in the "Tooltip" colors, and then lets Control finish loading. The game engine calls this as needed, so most users won't need to call it directly.

Parameters

MoveFocus(integer step)

This action moves the focus to the next focusable item in the tooltip, going back to the first after the last, as Tab does inside a tooltip with buttons. With a negative step it moves back, as Shift+Tab does. It returns false when the tooltip has nothing to focus.

Parameters

  • step integer: 1 to move forward, or -1 to move back.

Returns

boolean: true if the focus moved.

Example

use Libraries.Interface.Controls.Tooltip

Tooltip tooltip
tooltip:MoveFocus(1)

Open()

This action opens the tooltip next to its control, where the control's GetTooltipPlacement says: below it, above it, beside it, or over it. A tooltip that doesn't fit on that side moves to the other side, and it is kept inside the window. The TooltipManager calls this, so most users won't need to call it directly.

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Interface.Controls.Button

Button button
button:SetName("Save")
Tooltip tooltip
tooltip:Fill(button, undefined, "", "Saves the file to the disk")
tooltip:Open()

SetTitleFont(Libraries.Game.Graphics.Font font)

This action sets the font of the tooltip's first line, its title, such as a bold font. With undefined, the title uses the same font as the text. TooltipManager:SetTitleFont sets it for every tooltip in the game.

Parameters

Example

use Libraries.Interface.Controls.Tooltip
use Libraries.Game.Graphics.Font

Font bold
bold:LoadFont("Arial Bold")
Tooltip tooltip
tooltip:SetTitleFont(bold)

Inherited Actions

263 actions from Libraries.Interface.Controls.Control
60 actions from Libraries.Interface.Item
202 actions from Libraries.Interface.Item2D
3 actions from Libraries.Language.Object