API
LibActionButton-1.0 provides a fully functional action button on which you can base complete Action Button addons, or simple helper addons providing extra action buttons.
Usage
You need a secure header to drive this button. To change the buttons state, execute a childupdate handler on the "state" attribute.
Basic sample code:
-- Create a Header to drive this CreateFrame("Frame", "LABTestHeader", UIParent, "SecureHandlerStateTemplate") RegisterStateDriver(LABTestHeader, "page", "[mod:alt]2;1") LABTestHeader:SetAttribute("_onstate-page", [[ self:SetAttribute("state", newstate) control:ChildUpdate("state", newstate) ]]) -- Create a button on the header local button = LibStub("LibActionButton-1.0"):CreateButton(1, "LABTest1", LABTestHeader) button:SetPoint("CENTER", UIParent) button:Show() button:SetState(1, "action", 1) button:SetState(2, "action", 2)
Library API
lib:CreateButton(id, name, header, config)
Creates a new button. Returns a reference to the created button.
Parameters
- id
- Id of the button. Not used by LibActionButton-1.0 directly, it is however passed back to the addon using the library in callbacks for identification purposes.
- name
- Name of the Button. Due to the nature of the Action Button Template that LAB-1.0 uses, all buttons are required to have a name.
- header
- The secure header that controls this button.
- config
- The configuration table for this button. If nil, the default configuration will be used. See Button Configuration for reference.
This is the only external API of the library. All other APIs are per-button and are exposed on the button directly, rather then through the library.
Button API
Button:SetState(state, kind, action)
Set the button kind and button action for a specific state.
Parameters
- state
- The state to change. A state is any string. All input is tostring'ed for good measure.
- kind
- The kind of the button in this state.
- action
- The action of the button. The action is dependent on the kind specified.
Button:ClearStates()
Remove all configured states from the button.
Button:DisableDragNDrop(flag)
Enable/Disable drag'n'drop of the buttons.
Note that only buttons not using the "action" or "pet" type can disable their drag'n'drop.
Parameters
- flag
- Boolean flag to enable/disable DragNDrop. (True to disable, false/nil to enable)
Button:AddToButtonFacade(group)
Add the button to the ButtonFacade group specified
Parameters
- group
- The Addons ButtonFacade group to add this button to.
Button:AddToMasque(group)
Add the button to the Masque group specified
Parameters
- group
- The Addons Masque group to add this button to.
Button:UpdateConfig(config)
Update the configuration of the button.
Parameters
- config
- New configuration to apply to the button. If nil, the default configuration will be used.