-
Notifications
You must be signed in to change notification settings - Fork 0
Tooltip
StdUi has 2 Tooltip methods:
StdUi:FrameTooltip(owner, text, tooltipName, anchor, automatic)
Description:
Frame tooltip is the simplest implementation of tooltip which doesn't use GameTooltip
.
Making it really lightweight and still very flexible.
It is essentially just a Frame
+ FontString
. Frame has strata set to TOOLTIP
.
owner
, unlike parent
, is only a reference to some other element that is suppose to be tooltip
owner. Real parent of this tooltip is always UIParent
(world frame).
Unlike GameTooltip
, FrameTooltip
doesn't clear it's content after hiding.
Arguments:
-
owner
- Frame - Object that should be a owner of the tooltip. -
text
- string|function - Text that should be visible or function to create tooltip contents. -
tooltipName
- string - Name of the tooltip (to make it resuable). It is NOT the actual Frame name. -
anchor
- string - anchor ofowner
to which should be tooltip attached. -
automatic
- bool - if you set this to true, OnEnter/OnLeave events ofowner
will be hooked to show tooltip. Otherwise you will need to handle showing and hiding tooltip yourself.
Named children:
-
tooltip.text
- FontString - string that is used to display text
Methods:
FrameTooltip has all Frame
methods plus:
-
SetText(text, r, g, b)
- sets the tooltip text, colorr
,g
,b
is optional. Automatically callsRecalculateSize
. -
GetText()
- Gets the tooltip text -
AddLine(text, r, g, b)
- Adds a line to tooltip. Color is optional. UnlikeGameTooltip
this one keeps all text in one string with line breaks. -
RecalculateSize()
- Calculates width and height of string inside tooltip and sets tooltip size accordingly. Warning:- It is being called automatically on
Show
- If you provide a function as
text
in constructor. You need to override this function.
- It is being called automatically on
Returns:
Example:
local tooltip = StdUi:FrameTooltip(button, 'Click to change anchor', 'simp_tooltip4', 'TOPRIGHT', true);
StdUi:Tooltip(owner, text, tooltipName, anchor, automatic)
Description:
GameTooltip
implementation of tooltip. Please keep in mind that this kind tooltips are heavy.
Warning: It actually creates new instance of GameTooltip! Leaving blizzard tooltip intact.
Difference between blizzard GameTooltip
and this one are:
- Anchors works differently. If you set anchor to
TOPRIGHT
you will see your tooltip attached to top right corner of theowner
, not top left corner like blizzard tooltip does. - It does have StdUi backdrop.
Arguments:
-
owner
- Frame - Object that should be a owner of the tooltip. -
text
- string|function - Text that should be visible or function to create tooltip contents. -
tooltipName
- string - Name of the tooltip. Warning: it IS the real name of the frame, so make sure you use some unique name as it will be in global namespace. -
anchor
- string - anchor ofowner
to which should be tooltip attached. -
automatic
- bool - if you set this to true, OnEnter/OnLeave events ofowner
will be hooked to show tooltip. Otherwise you will need to handle showing and hiding tooltip yourself.
Methods:
Tooltip has all GameTooltip
methods and StdUi doesn't add anything on its own.
Returns:
Example:
local tooltip = StdUi:Tooltip(button, 'Simple text in blizzard tooltip', 'simp_tooltip', 'TOPRIGHT', true);
Code:
---@type StdUi
local StdUi = LibStub('StdUi');
local window = StdUi:Window(UIParent, 'Title', 500, 500);
window:SetPoint('CENTER');
local anchor = 'TOPRIGHT';
local b1 = StdUi:Button(window, 100, 24, 'GameTooltip');
local b2 = StdUi:Button(window, 100, 24, 'FrameTooltip');
local b3 = StdUi:Button(window, 100, 24, 'GameTooltip Spell');
StdUi:GlueTop(b1, window, 0, -40);
StdUi:GlueBelow(b2, b1, 0, -20);
StdUi:GlueBelow(b3, b2, 0, -20);
local t1 = StdUi:Tooltip(b1, 'Simple text in blizzard tooltip', 'simp_tooltip', anchor, true);
local txt = 'Simple text in frame tooltip\n'..
'This one does support\n'..
'line breaks\n'..
'\n'..
'And |c00ff00ffColors|r';
local t2 = StdUi:FrameTooltip(b2, txt, 'simp_tooltip2', anchor, true);
---@param tip GameTooltip
local function makeTip(tip)
tip:SetSpellByID(19434);
end
local t3 = StdUi:Tooltip(b3, makeTip, 'simp_tooltip3', anchor, true);
local bA = StdUi:Button(window, 140, 24, 'Anchor: ' .. anchor);
StdUi:GlueTop(bA, window, -10, -40, 'RIGHT');
StdUi:FrameTooltip(bA, 'Click to change anchor', 'simp_tooltip4', 'TOPRIGHT', true);
bA:SetScript('OnClick', function(s)
if anchor == 'TOP' then anchor = 'TOPRIGHT';
elseif anchor == 'BOTTOM' then anchor = 'BOTTOMLEFT';
elseif anchor == 'LEFT' then anchor = 'TOPLEFT';
elseif anchor == 'RIGHT' then anchor = 'BOTTOMRIGHT';
elseif anchor == 'TOPLEFT' then anchor = 'TOP';
elseif anchor == 'TOPRIGHT' then anchor = 'RIGHT';
elseif anchor == 'BOTTOMLEFT' then anchor = 'LEFT';
elseif anchor == 'BOTTOMRIGHT' then anchor = 'BOTTOM';
else anchor = 'CENTER';
end
s:SetText('Anchor: ' .. anchor);
t1.anchor = anchor;
t2.anchor = anchor;
t3.anchor = anchor;
end);