Getting started

Embedding LibQTip into your addon

LibQTip uses LibStub, and is designed to be embedded directly within your AddOn.

Using the WoWAce .pkgmeta feature

If your AddOn is hosted on WoWAce, you can use the .pkgmeta externals feature to have the packager embed LibQTip for you. This .pkgmeta example automatically embeds the latest tagged version of LibStub and LibQTip-1.0:


externals:
   libs/LibStub: 
     url: svn://svn.wowace.com/wow/libstub/mainline/trunk
     tag: latest
   libs/LibQTip-1.0:
     url: svn://svn.wowace.com/wow/libqtip-1-0/mainline/trunk
     tag: latest

Then add references to them in the .toc file:

libs\LibStub\LibStub.lua
libs\LibQTip-1.0\LibQTip-1.0.lua

Minimalist hard-embedding

Download the latest beta or release package and copy LibStub.lua and LibQTip-1.0.lua into your addon folder. Then references them in the .toc file:

LibStub.lua
LibQTip-1.0.lua

Simple Use

Provided you have an existing anchor frame in your FooBarAddon, here is how to add a simple tooltip:

 -- Get a reference to the lib
 local LibQTip = LibStub('LibQTip-1.0')
 
 local function anchor_OnEnter(self)
   
   -- Acquire a tooltip with 3 columns, respectively aligned to left, center and right
   local tooltip = LibQTip:Acquire("FooBarTooltip", 3, "LEFT", "CENTER", "RIGHT")
   self.tooltip = tooltip 
   
   -- Add an header filling only the first two columns
   tooltip:AddHeader('Anchor', 'Tooltip')
   
   -- Add an new line, using all columns
   tooltip:AddLine('Hello', 'World', '!')
   
   -- Use smart anchoring code to anchor the tooltip to our frame
   tooltip:SmartAnchorTo(self)
   
   -- Show it, et voilà !
   tooltip:Show()
   
 end
 
 local function anchor_OnLeave(self)
   
   -- Release the tooltip
   LibQTip:Release(self.tooltip)
   self.tooltip = nil
   
 end
 
 -- Somewhere in the anchor initialization
 anchor:SetScript('OnEnter', anchor_OnEnter)
 anchor:SetScript('OnLeave', anchor_OnLeave)

Please note that releasing a tooltip is not intended to be optional. Doing so has very little overhead versus clearing it and hiding it, and allows an overall reduction in frame usage. If your code does not release the tooltip, it locks its frames and forces LibQTip to create more frames for other tooltips.

Changing fonts

The fonts can be changed using the :SetFont and :SetHeaderFont methods of the tooltip. This will not change existing text, so it should be done before adding anything to the tooltip. As the fonts are reset each time the tooltip is acquired, these methods must be called each time.

 -- New font looking like GameTooltipText but red with height 15
 local red15Font = CreateFont("FooBarRed15Font")
 red15Font:SetFont(GameTooltipText:GetFont(), 15)
 red15Font:SetTextColor(1,0,0)
  
 -- New font looking like red15font but with height 17
 local red17Font = CreateFont("FooBarRed17Font")
 red17Font:CopyFontObject(red15Font)
 red17Font:SetFont(red17Font:GetFont(), 17) 
 
 local function anchor_OnEnter(self)
   
   -- Acquire a tooltip
   local tooltip = LibQTip:Acquire("FooBarTooltip", 3, "LEFT", "CENTER", "RIGHT")
   
   -- Set the fonts
   tooltip:SetFont(red15font)
   tooltip:SetHeaderFont(red17font)
   
   -- ...

To be continued.


Comments

Posts Quoted:
Reply
Clear All Quotes