Skip to content

Button

A graphical push button built on Blizzard's UIPanelButtonTemplate.

Create with AceGUI:Create("Button"). It inherits the Common Widget API.

Widget type: Button

Methods

SetText

method#
lua
widget:SetText(text?)

Sets the button's caption. If auto-width is enabled, the button is resized to fit the text (string width + 30px padding).

Parameters

ParameterTypeDefaultDescription
text (optional)stringThe label to display. Passing nil clears the text.

SetAutoWidth

method#
lua
widget:SetAutoWidth(autoWidth)

Toggles automatic width sizing. When enabled, the button immediately resizes to its current text width plus 30px, and every subsequent SetText re-fits the width.

Parameters

ParameterTypeDefaultDescription
autoWidthbooleantrue to size the button to its text, false to keep the fixed width.

SetDisabled

method#
lua
widget:SetDisabled(disabled)

Enables or disables the button. A disabled button cannot be clicked and is greyed out by the template.

Parameters

ParameterTypeDefaultDescription
disabledbooleantrue to disable, false to enable.

Defaults

On acquire the button resets to: height 24, width 200, not disabled, auto-width off, and empty text.

Callbacks

OnClick

callback#
lua
OnClick(...)

Fired when the button is clicked. Before firing, AceGUI clears focus and plays the menu-option click sound. Subscribe with widget:SetCallback.

Parameters

ParameterTypeDefaultDescription
...anyThe native button click args forwarded from the frame's OnClick (e.g. the mouse button and down state).

OnEnter

callback#
lua
OnEnter()

Fired when the mouse enters the button. Subscribe with widget:SetCallback.

OnLeave

callback#
lua
OnLeave()

Fired when the mouse leaves the button. Subscribe with widget:SetCallback.

Example

lua
local btn = AceGUI:Create("Button")
btn:SetText("Apply")
btn:SetAutoWidth(true)
btn:SetCallback("OnClick", function(widget)
    print("Apply clicked")
end)

Ace3, a World of Warcraft addon framework.