How to create a simple text tooltip at a control

From ESOUI Wiki

Jump to: navigation, search

Explanation

Sometimes you want to add a simple text tooltip to your controls, if you move the mouse above the control.
And it should be hidden again if you move the mouse away from that control again.

ZOs provides a simple template lua file for this:
https://github.com/esoui/esoui/blob/c47af79c7c51681ae315d4f9a6d70d9e965ad514/esoui/libraries/zo_templates/tooltip.lua

In here you'll find functions for different purposes, like a truncated label tooltip (where the text was truncated), reanchoring tooltips, but also these 2 simple functions:

ZO_Tooltips_ShowTextTooltip(controlToShowTooltipOn, anchorPosition, tooltipText)
ZO_Tooltips_HideTextTooltip()


controlToShowTooltipOn: The control where the tooltip should be shown at if you move the mouse above.
anchorPosition: The anchor position where the tooltip should be shown to the control: LEFT, TOP, RIGHT, BOTTOM
tooltipText: Any String (may contain icons/textures via the |t ... |r and colors added via the |cRRGGBB ... |c tags as well). See function zo_iconTextFormat and others in this file here https://github.com/esoui/esoui/blob/51677bbf3d3c0ce0dd0f5aceab415478db451c10/esoui/libraries/globals/globalapi.lua#L161

A best practice is to use the EventHandler "OnMouseEnter" and "OnMouseExit" on the controls to show or hide the tooltip.

control:SetHandler("OnMouseEnter", function(ctrl) ZO_Tooltips_ShowTextTooltip(ctrl, LEFT, "Tooltip text"))
control:SetHandler("OnMouseExit", function(ctrl) ZO_Tooltips_HideTextTooltip)
Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox