LibCandyBar-3.0

LibCandyBar-3.0 provides elegant timerbars with icons for use in addons.
It is based of the original ideas of the CandyBar and CandyBar-2.0 library. In contrary to the earlier libraries LibCandyBar-3.0 provides you with a timerbar object with a simple API.

Creating a new timerbar using the ':New' function will return a new timerbar object. This timerbar object inherits all of the barPrototype functions listed here.

Example

mybar = Libstub("LibCandyBar-3.0"):New("Interface\\AddOns\\MyAddOn\\media\\statusbar.tga", 100, 16)


barPrototype:AddUpdateFunction(func)

Adds a function to the timerbar.
The function will run every update and will receive the bar as a parameter.

Parameters

func
Function to run every update

Usage

-- The example below will print the time remaining to the chatframe every update. Yes, that's a whole lot of spam
mybar:AddUpdateFunction( function(bar) print(bar.remaining) end )


barPrototype:Get(key)

Retrieves user data from the timerbar object.

Parameters

key
Key to retrieve


barPrototype:Set(key, data)

Sets user data in the timerbar object.

Parameters

key
Key to use for the data storage
data
Data to store


barPrototype:SetColor(r, g, b, a)

Sets the color of the bar This is basically a direct call to SetStatusBarColor and

Parameters

r
Red component 0-1
g
Green component 0-1
b
Blue component 0-1
a
Alpha 0-1


barPrototype:SetDuration(duration)

Sets the duration of the bar This can also be used while the bar is running to adjust the time remaining, within the bounds of the original duration.

Parameters

duration
Duration of the bar in seconds


barPrototype:SetIcon(icon)

Sets the icon next to the bar

Parameters

icon
Path to the icon texture or nil to not display an icon


barPrototype:SetLabel(text)

Sets the label on the bar

Parameters

text
Label text


barPrototype:SetTexture(texture)

Sets the texture of the bar This should only be needed on running bars that get changed on the fly

Parameters

texture
Path to the bar texture


barPrototype:SetTimeVisibility(bool)

Sets wether or not the time indicator on the right of the bar should be shown Time is shown by default

Parameters

bool
true to show the time, false/nil to hide the time.


barPrototype:Start()

Shows the bar and starts it off


barPrototype:Stop()

Stops the bar This will stop the timerbar running fire the LibCandyBar_Stop callback and then recycle the bar into the candybar barpool Note: make sure you remove all references to the bar in your addon upon receiving the LibCandyBar_Stop callback for that bar

Usage

-- The example below shows the use of the LibCandyBar_Stop callback by printing the contents of the label in the chatframe
local function barstopped( callback, bar )
  print( bar.candybarLabel:GetText(), "stopped")
end
LibStub("LibCandyBar-3.0"):RegisterCallback(myaddonobject, "LibCandyBar_Stop", barstopped)


lib:New(texture, width, height)

Creates a new timerbar object

Parameters

texture
Path to the texture used for the bar
width
Width of the bar
height
Height of the bar

Usage

-- Create a simple bar using a custom texture
mybar = Libstub("LibCandyBar-3.0"):New("Interface\\AddOns\\MyAddOn\\media\\statusbar.tga", 100, 16)


You must login to post a comment. Don't have an account? Register to get one!