Skip to content

TreeGroup

A container that switches between groups of widgets using a tree control.

Create with AceGUI:Create("TreeGroup"). This is a container; it inherits the Common Widget API and container methods.

Widget type: TreeGroup

Methods

SetTree

method#
lua
container:SetTree(tree, filter?)

Set the tree to display and refresh it. See Tree node format for the structure of tree.

Parameters

ParameterTypeDefaultDescription
treetableArray of node tables (may contain nested children). Asserted to be a table when non-nil. See Tree node format.
filter (optional)booleanWhen truthy, branches and leaves whose visible is false are hidden, and branches are only shown if they contain at least one visible descendant.

SelectByPath

method#
lua
container:SelectByPath(...)

Select a node by its path of values from the root down, expanding every ancestor group along the way and scrolling the selection into view. Fires OnGroupSelected.

Parameters

ParameterTypeDefaultDescription
...stringThe sequence of node values from the top level to the target node (e.g. "parentValue", "childValue").

SelectByValue

method#
lua
container:SelectByValue(uniquevalue)

Select a node by its full unique value (the path components joined by \001). Splits on \001 to derive the path, expands ancestors, scrolls into view, and fires OnGroupSelected.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe unique value string, e.g. "parentValue\001childValue".

Select

method#
lua
container:Select(uniquevalue, ...)

Lower-level selection method used by SelectByPath/SelectByValue. Disables filtering, expands every group along the path, sets the selection, refreshes (scrolling to the selection), and fires OnGroupSelected.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe unique value to mark as selected.
...stringThe path components used to expand ancestor groups.

SetSelected

method#
lua
container:SetSelected(value)

Set the selected node to value (the node's unique value). Only fires OnGroupSelected if the selection actually changed. Does not expand ancestors or scroll.

Parameters

ParameterTypeDefaultDescription
valuestringThe unique value of the node to select.

SetStatusTable

method#
lua
container:SetStatusTable(status)

Supply an external table for persisting tree state. The container stores/reads groups (expanded-state map keyed by unique value), scrollvalue, treewidth, treesizable, and selected. Missing keys are initialized. After setting, applies the stored tree width and refreshes.

Parameters

ParameterTypeDefaultDescription
statustableA table you own and keep alive (asserted to be of type table).

SetTreeWidth

method#
lua
container:SetTreeWidth(treewidth?, resizable?)

Set the width of the tree pane and whether the user may drag-resize it. treewidth may be omitted or boolean: if a boolean is passed as the first argument, it is treated as resizable and the width defaults to 175. Stores the values in the status table.

Parameters

ParameterTypeDefaultDescription
treewidth (optional)number | booleanWidth in pixels (default 175), or a boolean to set only resizable.
resizable (optional)booleanWhen true, the drag handle is enabled.

GetTreeWidth

method#
lua
container:GetTreeWidth()

Returns the current tree-pane width (defaults to 175 if unset).

Returns

TypeDescription
numberThe current tree-pane width (defaults to 175 if unset).

EnableButtonTooltips

method#
lua
container:EnableButtonTooltips(enable)

Enable or disable the built-in tooltip shown when hovering over a tree button (the tooltip text is the button label). Enabled by default on acquire.

Parameters

ParameterTypeDefaultDescription
enablebooleanWhether the built-in hover tooltip is shown.

RefreshTree

method#
lua
container:RefreshTree(scrollToSelection?, fromOnUpdate?)

Rebuild the visible button list from the current tree and status tables. Called automatically after most mutations; call directly if you mutate the tree table in place.

Parameters

ParameterTypeDefaultDescription
scrollToSelection (optional)booleanPass true to scroll the selected node into view.
fromOnUpdate (optional)booleanInternal flag set when called from the first-frame OnUpdate handler.

The container also defines CreateButton, BuildLevel, and ShowScroll as internal helpers, plus OnWidthSet/ OnHeightSet/LayoutFinished for layout.

Callbacks

OnGroupSelected

callback#
lua
OnGroupSelected(uniquevalue)

Fired when the selected node changes (via SetSelected, Select, SelectByPath, SelectByValue, or clicking a button). Release and rebuild the content here.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe selected node's unique value (path components joined by \001).

OnClick

callback#
lua
OnClick(uniquevalue, selected)

Fired when a tree button is clicked, before selection is applied.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe clicked node's unique value.
selectedbooleanThe button's selected state at click time.

OnButtonEnter

callback#
lua
OnButtonEnter(uniquevalue, buttonFrame)

Fired when the mouse enters a tree button.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe node's unique value.
buttonFrameButtonThe underlying tree button.

OnButtonLeave

callback#
lua
OnButtonLeave(uniquevalue, buttonFrame)

Fired when the mouse leaves a tree button.

Parameters

ParameterTypeDefaultDescription
uniquevaluestringThe node's unique value.
buttonFrameButtonThe underlying tree button.

OnTreeResize

callback#
lua
OnTreeResize(width)

Fired after the user finishes drag-resizing the tree pane.

Parameters

ParameterTypeDefaultDescription
widthnumberThe new tree width in pixels.

Tree node format

SetTree takes an array of node tables. Each node recognizes the following fields (read from the source addLine/UpdateButton):

  • value: the node's identifier within its level. The full path of values (joined by \001) forms the node's * unique value*, which is what OnGroupSelected/OnClick report and what SelectByValue expects. Sibling node values must be unique within their parent.
  • text: the label shown for the node.
  • icon: optional texture (path or file ID) drawn left of the text.
  • iconCoords: optional table of texture coordinates {left, right, top, bottom} (passed to SetTexCoord).
  • disabled: if truthy, the node is greyed out and not mouse-interactive.
  • children: optional array of child node tables. A node with children is a collapsible branch whose expanded state is tracked per unique value in the status table.
  • visible: optional boolean. When the tree is set with a filter, nodes with visible = false are hidden (and empty branches are pruned).

Example

lua
local AceGUI = LibStub("AceGUI-3.0")

local tree = AceGUI:Create("TreeGroup")
tree:SetFullWidth(true)
tree:SetFullHeight(true)
tree:SetLayout("Flow")

tree:SetTree({
    {
        value = "combat",
        text  = "Combat",
        children = {
            { value = "melee",  text = "Melee"  },
            { value = "ranged", text = "Ranged" },
        },
    },
    {
        value = "ui",
        text  = "Interface",
        icon  = "Interface\\Icons\\INV_Misc_Gear_01",
        children = {
            { value = "frames", text = "Frames" },
            { value = "fonts",  text = "Fonts", disabled = true },
        },
    },
})

tree:SetCallback("OnGroupSelected", function(container, event, uniquevalue)
    container:ReleaseChildren()
    -- uniquevalue is e.g. "combat\001melee"
    local lbl = AceGUI:Create("Label")
    lbl:SetText("Selected: " .. uniquevalue)
    container:AddChild(lbl)
end)

-- expand "combat" and select its "melee" child
tree:SelectByPath("combat", "melee")

Ace3, a World of Warcraft addon framework.