Skip to content

Common Widget API

Every AceGUI-3.0 widget inherits a common set of methods from WidgetBase. Containers inherit an additional set from WidgetContainerBase (which itself extends WidgetBase).

The per-widget pages in this section document only the methods and callbacks specific to that widget; the methods below are available on every widget and are not repeated there.

Widget Methods

Available on every widget and container.

SetWidth

method#
lua
widget:SetWidth(width)

Set the widget's width in pixels. Fires the widget's internal OnWidthSet hook if it defines one.

Parameters

ParameterTypeDefaultDescription
widthnumberThe width in pixels.

SetHeight

method#
lua
widget:SetHeight(height)

Set the widget's height in pixels. Fires the widget's internal OnHeightSet hook if it defines one.

Parameters

ParameterTypeDefaultDescription
heightnumberThe height in pixels.

SetRelativeWidth

method#
lua
widget:SetRelativeWidth(width)

Set the width as a fraction of the parent container's width. width must be greater than 0 and at most 1 (e.g. 0.5 for half width). Errors on an invalid value.

Parameters

ParameterTypeDefaultDescription
widthnumberFraction of the parent's width; must be greater than 0 and at most 1.

SetFullWidth

method#
lua
widget:SetFullWidth(isFull)

When isFull is truthy, the widget fills the full width of its container row. Pass a falsy value to clear it.

Parameters

ParameterTypeDefaultDescription
isFullbooleanTruthy to fill the full row width; falsy to clear.

IsFullWidth

method#
lua
widget:IsFullWidth()

Returns true if the widget is set to full width.

Returns

TypeDescription
booleantrue if the widget is set to full width.

SetFullHeight

method#
lua
widget:SetFullHeight(isFull)

When isFull is truthy, the widget fills the full available height. Pass a falsy value to clear it.

Parameters

ParameterTypeDefaultDescription
isFullbooleanTruthy to fill the full available height; falsy to clear.

IsFullHeight

method#
lua
widget:IsFullHeight()

Returns true if the widget is set to full height.

Returns

TypeDescription
booleantrue if the widget is set to full height.

SetPoint

method#
lua
widget:SetPoint(...)

Passes through to the underlying frame's SetPoint. Manual anchoring is generally unnecessary; let the container's layout position the widget.

Parameters

ParameterTypeDefaultDescription
...anyAnchoring arguments forwarded to the frame's SetPoint.

ClearAllPoints

method#
lua
widget:ClearAllPoints()

Passes through to the underlying frame's ClearAllPoints.

GetPoint

method#
lua
widget:GetPoint(...)

Passes through to the underlying frame's GetPoint.

Parameters

ParameterTypeDefaultDescription
...anyArguments forwarded to the frame's GetPoint.

GetNumPoints

method#
lua
widget:GetNumPoints()

Passes through to the underlying frame's GetNumPoints.

Returns

TypeDescription
numberThe number of anchor points on the underlying frame.

SetCallback

method#
lua
widget:SetCallback(name, func)

Register a callback handler for one of the widget's events. func is called with the widget as its first argument and the callback name as its second, followed by any event-specific arguments. Passing a non-function is ignored.

Parameters

ParameterTypeDefaultDescription
namestringThe callback/event name (e.g. "OnClick").
funcfunctionHandler; called as (widget, event, ...). Non-functions are ignored.

Example

lua
button:SetCallback("OnClick", function(widget, event) print("clicked") end)

Fire

method#
lua
widget:Fire(name, ...)

Fire a registered callback by name, passing along any extra arguments. The handler is invoked with the widget and the event name prepended to the arguments. If the handler ran successfully, its return value is returned. Used internally by widgets; you normally consume callbacks via SetCallback rather than calling Fire yourself.

Parameters

ParameterTypeDefaultDescription
namestringThe callback/event name to fire.
...anyExtra arguments passed along to the handler.

Returns

TypeDescription
anyThe handler's return value, if it ran successfully.

SetUserData

method#
lua
widget:SetUserData(key, value)

Store arbitrary data on the widget under key. Useful for associating application state with a widget instance.

Parameters

ParameterTypeDefaultDescription
keyanyThe key under which to store the value.
valueanyThe value to store.

GetUserData

method#
lua
widget:GetUserData(key)

Retrieve a value previously stored with SetUserData.

Parameters

ParameterTypeDefaultDescription
keyanyThe key to look up.

Returns

TypeDescription
anyThe previously stored value, or nil.

GetUserDataTable

method#
lua
widget:GetUserDataTable()

Returns the widget's full user-data table.

Returns

TypeDescription
tableThe widget's full user-data table.

SetParent

method#
lua
widget:SetParent(parent)

Reparents the widget to another widget's content frame. Containers call this for you in AddChild.

Parameters

ParameterTypeDefaultDescription
parenttableThe widget whose content frame becomes the new parent.

IsVisible

method#
lua
widget:IsVisible()

Returns the underlying frame's visibility (via IsVisible).

Returns

TypeDescription
booleanThe underlying frame's visibility.

IsShown

method#
lua
widget:IsShown()

Returns the underlying frame's shown state (via IsShown).

Returns

TypeDescription
booleanThe underlying frame's shown state.

Release

method#
lua
widget:Release()

Releases the widget back to the widget pool (shortcut for AceGUI:Release(widget)).

IsReleasing

method#
lua
widget:IsReleasing()

Returns true if the widget is currently being released.

Returns

TypeDescription
booleantrue if the widget is currently being released.

Container Methods

Available on every container widget in addition to the widget methods above.

AddChild

method#
lua
container:AddChild(child, beforeWidget?)

Add a child widget to the container and lay it out. If beforeWidget is supplied, the child is inserted before that existing sibling instead of appended.

Parameters

ParameterTypeDefaultDescription
childtableThe child widget to add.
beforeWidget (optional)tableAn existing sibling to insert the child before.

AddChildren

method#
lua
container:AddChildren(...)

Add multiple child widgets at once, then perform a single layout pass.

Parameters

ParameterTypeDefaultDescription
...tableOne or more child widgets to add.

ReleaseChildren

method#
lua
container:ReleaseChildren()

Release all child widgets back to the pool and clear the container's child list. Commonly called before redrawing a group's contents.

SetLayout

method#
lua
container:SetLayout(layout)

Set the layout function used to arrange children, by registered name: "List", "Flow", "Fill" or "Table".

Parameters

ParameterTypeDefaultDescription
layoutstringThe registered layout name: "List", "Flow", "Fill" or "Table".

DoLayout

method#
lua
container:DoLayout()

Lay out the container's children. Called automatically by AddChild/AddChildren; call it manually after changing children outside those methods.

PerformLayout

method#
lua
container:PerformLayout()

Runs the layout function immediately (unless layout is paused). DoLayout is the usual entry point.

PauseLayout

method#
lua
container:PauseLayout()

Suspend automatic layout. Useful when adding many children in a loop to avoid a layout pass per child.

ResumeLayout

method#
lua
container:ResumeLayout()

Resume automatic layout after PauseLayout. Follow with DoLayout to apply.

Example

lua
container:PauseLayout()
for _, item in ipairs(items) do
    local w = AceGUI:Create("Label")
    w:SetText(item)
    container:AddChild(w)
end
container:ResumeLayout()
container:DoLayout()

SetAutoAdjustHeight

method#
lua
container:SetAutoAdjustHeight(adjust)

When adjust is truthy (the default), the container automatically resizes its height to fit its content. Pass false to keep a fixed height.

Parameters

ParameterTypeDefaultDescription
adjustbooleanTruthy (the default) to auto-resize height to fit content; false to keep a fixed height.

Internal hooks

These are optional members a widget implementation may define; AceGUI calls them for you. Addon authors don't call or register them (consume widgets through their public methods); they matter when you build a custom widget. OnAcquire and OnRelease are driven by the widget pool; OnWidthSet / OnHeightSet by sizing; and LayoutFinished by the layout pass.

OnAcquire

callback#
lua
widget:OnAcquire()

Called by AceGUI:Create when the widget is handed out (whether freshly created or reused from the pool) to reset it to its default state (size, text, value, …). This is why a recycled widget never carries over data from its previous user.

OnRelease

callback#
lua
widget:OnRelease()

Called by AceGUI:Release before the widget returns to the pool. Clears the widget's data and hides it.

OnWidthSet

callback#
lua
widget:OnWidthSet(width)

Called by SetWidth after the frame is resized, if the widget defines it. A widget implementation uses this to re-lay-out its contents for the new width. Use this rather than the frame's own OnSizeChanged; AceGUI already manages that.

Parameters

ParameterTypeDefaultDescription
widthnumberThe new width in pixels.

OnHeightSet

callback#
lua
widget:OnHeightSet(height)

Called by SetHeight after the frame is resized, if the widget defines it. A widget implementation uses this to re-lay-out its contents for the new height. Use this rather than the frame's own OnSizeChanged; AceGUI already manages that.

Parameters

ParameterTypeDefaultDescription
heightnumberThe new height in pixels.

LayoutFinished

callback#
lua
widget:LayoutFinished(width, height)

Called on a container after a layout pass finishes. A container implementation uses this to size itself to its content; auto-growing groups add their content height here.

Parameters

ParameterTypeDefaultDescription
widthnumberWidth of the area used by the laid-out controls, or nil if the layout used the existing size.
heightnumberHeight of the area used by the laid-out controls, or nil if the layout used the existing size.

Ace3, a World of Warcraft addon framework.