How to create a simple text tooltip at a control

From ESOUI Wiki

Jump to: navigation, search


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:

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)

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

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