Repository navigation
Foundry List
Part of the Foundry API reference.
New to WoW addons? Start here →
Foundry.List collapses Blizzard's ScrollBox system into a single
F.List:New(config) call. That system (the ScrollBox frame, the
ScrollBoxListView, the DataProvider, and the ScrollUtil wiring helpers) is
powerful but punishing to assemble by hand. List wires those four primitives into
a working ScrollBox list, hands you a small controller to put data in and iterate
visible rows, and gives you an escape hatch to the raw Blizzard objects
underneath when you outgrow the wrapper.
This page explains what WoW gives you raw (a five-object composition built in nine ordered steps), then the Foundry.List API with worked examples, then the escape hatch and the scope boundary: what List deliberately does not wrap.
API version: Foundry.List is module API version 1. Assert it with
F:RequireModule("List", 1)if your addon needs the module present at a minimum version. (This is the module's version; the library as a whole isF.API_VERSION.)F:RequireModuleraises in both dev and release builds if the module is missing or too old, so guard your adoption with it rather than callingF.List:Newblind.
Modern clients only. List bridges Blizzard's current ScrollBox system, which shipped engine-wide in the 10.0 UI rewrite. It does not provide a
FauxScrollFrameorHybridScrollFramefallback. On a client that lacks the ScrollBox system,:Newrefuses loudly rather than limping. See Flavor support.
A correct hand-wired ScrollBox list is a composition of five objects: a
WowScrollBoxList frame, a MinimalScrollBar (which must be created as an
EventFrame, not a Frame), a ScrollBoxListLinearView, a DataProvider, and
an initializer closure. They assemble in nine ordered steps with at least four
ordering traps:
-- The hand-wired list: ~30 lines, four traps. This is what List removes.
local box = CreateFrame("Frame", nil, parent, "WowScrollBoxList")
local bar = CreateFrame("EventFrame", nil, parent, "MinimalScrollBar") -- trap: EventFrame, not Frame
box:SetPoint(...) -- you anchor both
bar:SetPoint("TOPLEFT", box, "TOPRIGHT", ...)
local view = CreateScrollBoxListLinearView(0, 0, 0, 0, spacing)
view:SetElementExtent(26) -- trap: a real extent (or a calculator) is mandatory for Lua rows
view:SetElementInitializer("Button", function(row, data) ... end) -- trap: an initializer must exist before the provider
view:SetElementResetter(function(row, data) ... end)
ScrollUtil.InitScrollBoxListWithScrollBar(box, bar, view)
view:SetDataProvider(CreateDataProvider()) -- trap: seed the empty provider AFTER the initializer
-- ...then per refresh:
local provider = view:GetDataProvider()
provider:Flush(); provider:InsertTable(rows)That verbosity is uniform across both studio consumers
(HistoryPanel.lua:1375, OptionsFrame.lua:412), which is exactly why it earns
a bridge.
-- The smallest legal list: name, parent, element identity, extent, initializer, then data.
local list = F.List:New({
name = "HistoryList",
parent = listPane,
elementType = "Button",
extent = 26,
initializer = function(button, entry) RenderHistoryRow(button, entry) end,
})
list:SetData(filteredSortedRows)Six config fields and one call replace the nine-step composition above. The initializer body you write is unchanged, because it is your row paint either way. What goes away is the five-object wiring, the EventFrame-bar trap, the mandatory-initializer-before-provider ordering, and the empty-provider seed.
F.List:New(config) takes a config table, never a bare string, because a list
has too many construction knobs. Fields:
local list = F.List:New({
-- REQUIRED -----------------------------------------------------------
name = "HomesteadOptionsList", -- non-empty string; diagnostics/scoping label
parent = contentFrame, -- the frame List anchors its ScrollBox and ScrollBar within
-- ELEMENT CONTRACT (exactly one of `template` or `elementType`) -------
elementType = "Frame", -- raw frame type ("Frame"/"Button") for Lua-built rows
-- template = "MyRowTemplate", -- OR an XML virtual-template name you authored
extent = 26, -- fixed row height in px (mutually exclusive with extentCalculator)
-- extentCalculator = function(dataIndex, elementData) return px end, -- variable-height rows
initializer = function(rowFrame, elementData) ... end, -- REQUIRED: fully repaint and wire the row
resetter = function(rowFrame, elementData) ... end, -- recommended: tear down what the initializer wired
-- OPTIONAL -----------------------------------------------------------
spacing = 2, -- inter-row gap px (default 0)
managedScrollBarVisibility = true, -- auto show/hide the bar (default false)
})Element identity: exactly one of template or elementType.
-
elementType = "Frame"|"Button"builds Lua rows; you build the row content insideinitializer. This requiresextentorextentCalculator. There is no XML to measure, and a missing extent is dangerous: Blizzard clamps a zero extent to 1px, then tries to display a runaway range of rows and hard-errors once that range hits 1000 (ScrollBoxViewUtil.lua). List requires a positive extent (or a calculator) at:Newso that failure can never reach the screen. -
template = "MyRowTemplate"uses an XML virtual template you authored in your own addon; List passes the name through and never authors XML for your row content.
extent and extentCalculator are mutually exclusive in List by choice. Blizzard
itself would simply prefer extent if both were set; List refuses the ambiguous
config instead.
The initializer repaints the whole row. Frames come from a recycled pool
and retain their previous contents, so your initializer must set every visible
field, not just the changed ones. It runs after the row has been laid out, so
the frame's real dimensions are available inside it. The resetter (recommended)
tears down what the initializer wired so a recycled frame starts clean.
Recycling and data-keyed caches. A
resettermay legitimately detach heavyweight child controls (Hide plusSetParent(nil)) without destroying them, for example a control cached on the data row and reparented across pooled frames. List does not auto-tear-down consumer-attached children, and data-keyed caches are expected to outlive frame recycling. This is Homestead OptionsFrame'sAttachRenderedChildpattern, preserved unchanged on adoption.
Validation is atomic. A rejected :New creates no ScrollBox, no ScrollBar,
no view, no provider, and no frame (byte-for-byte the pre-call state), then calls
F:RaiseDevError and returns nil. See Errors.
:New returns a controller (a plain table). Composition is by reference:
controller:Method(...) is the access style. List never injects its methods onto
your addon table. Mixin(MyAddon, controller) is your opt-in if you want it.
| Method | Signature | Behavior |
|---|---|---|
SetData |
list:SetData(array) |
Replace the entire row set. Builds a fresh DataProvider and reassigns it on the view, which releases and re-acquires every visible row (not an in-place recycle) and scrolls back to the top. This is the full-rebuild path both consumers use on refresh. array must be an array of tables; non-table rows disable recycling. |
ForEachFrame |
list:ForEachFrame(fn) |
Iterate the currently-realized row frames for an in-place visual update with no provider rebuild, for example to repaint the selected row's highlight. fn(frame, elementData); returning a truthy value stops iteration. |
GetNativeHandles |
list:GetNativeHandles() |
The escape hatch. See §6. |
Destroy |
list:Destroy() |
Release the provider, drop the managed-visibility behavior reference (Blizzard exposes no native unregister), hide and release the frames List created, and mark the controller destroyed. After Destroy, every method refuses, and double-Destroy refuses. |
Every method opens with a destroyed-guard. SetData must not be called from
inside an initializer, and List refuses it. Initializers run after layout, so
this is List enforcing its own re-entrancy contract; Blizzard's Acquire
reentrancy guard at ScrollBoxListView.lua:340 covers the separate
factory/acquire window, not this path.
List.API_VERSION lives on the module table, not the controller, so gate
adoption with F:RequireModule("List", n). There is no list:GetApiVersion()
instance accessor: by the time you hold a controller you have already called
:New, which is too late to gate on.
There is no Select or GetSelected in v1, by design. Keep your own selected
id and repaint the highlight in place:
function HistoryPanel:SetSelected(id)
self.selectedId = id
self.list:ForEachFrame(function(row)
row.Highlight:SetShown(row.entry and row.entry.id == id)
end)
endThis is exactly what both studio consumers do. Native selection is reachable raw if you ever need it (see §7).
When rows differ in height, give a calculator instead of a fixed extent:
local list = F.List:New({
name = "HomesteadOptionsList",
parent = contentFrame,
elementType = "Frame",
extentCalculator = function(dataIndex, elementData) return elementData.rowHeight end,
initializer = function(rowFrame, row) OptionsFrame:RenderRow(rowFrame, row) end,
})
list:SetData(currentSection)extentCalculator must return a number > 0 for every row. A non-number return (e.g. a row table missing its height field) raises a located List error in a dev build, and prints the diagnostic then falls back to a safe positive height in a release build, rather than letting nil reach Blizzard's extent math (a cryptic arithmetic on a nil value crash deep in ScrollBoxStride).
extent and extentCalculator are mutually exclusive. Supply exactly one.
When you outgrow the wrapper, :GetNativeHandles() hands you the live Blizzard
objects List composed, so you never have to rip Foundry out to reach the raw API:
local h = list:GetNativeHandles()
-- h.scrollBox -- the live WowScrollBoxList frame (ScrollBoxListMixin; ScrollTemplates.xml:4)
-- h.scrollBar -- the live MinimalScrollBar EventFrame (MinimalScrollBar.xml:15)
-- h.view -- the live ScrollBoxListLinearView table (created by CreateScrollBoxListLinearView; ScrollBoxLinearView.lua:243 is the factory, not a mixin definition)
-- h.dataProvider -- the live DataProvider table (DataProvider.lua:261)All four are always present and are the live objects, which is the point of the hatch. List exposes no internal tables of its own through handles.
If you set both a fixed extent and an extentCalculator on h.view after
:New (via SetElementExtent and SetElementExtentCalculator), Blizzard prefers
the fixed extent and ignores the calculator; List forbids that combination at
:New, so it can only arise through the raw handle.
Re-anchoring (the common one). List anchors its ScrollBox and ScrollBar to
fill parent as a starting point. When your layout reserves a scrollbar gutter
or a header inset, re-anchor through the handle right after :New:
local list = F.List:New({ name = "OptionsList", parent = content, elementType = "Frame",
extentCalculator = rowHeight, initializer = renderRow })
local h = list:GetNativeHandles()
h.scrollBox:ClearAllPoints()
h.scrollBox:SetPoint("TOPLEFT", nav, "TOPRIGHT", 0, 0)
h.scrollBox:SetPoint("BOTTOMRIGHT", content, "BOTTOMRIGHT", -SCROLLBAR_GUTTER, 0)
h.scrollBar:SetPoint("TOPLEFT", h.scrollBox, "TOPRIGHT", 4, 0)List owns frame creation; you own the final SetPoints.
Bolt-on patterns reachable through the hatch (no v1 wrapper, on purpose):
- Native selection:
ScrollUtil.AddSelectionBehavior(h.scrollBox, ...) - Provider mutation that keeps scroll position:
h.dataProvider:Insert(...)/:Remove(...) - A full rebuild retaining scroll position:
h.scrollBox:Rebuild(true) - Native whole-array sort:
h.dataProvider:SetSortComparator(...) - A resizable, sortable column table (such as lib-st or
TableBuilder) bolted ontoh.scrollBox
List bridges plain ScrollBox lists. The following are out of v1 scope and reachable raw through the escape hatch (§6). They are documented, not wrapped:
-
Selection. Both consumers paint their own selection via
ForEachFrame, and the native behavior has no current consumer. The native behavior also clears itself on every provider reassign, so it interacts withSetDatain ways a consumer should opt into deliberately. -
Insert/Remove(provider mutation). These keep scroll position and recycle survivors, unlikeSetData. No shipped consumer streams rows today, so v1 usesSetData(full replace) only. -
Rebuild/Refresh. Reassigns the same provider, which releases and re-acquires all visible frames and clears any native selection. Heavy by design; for an in-place repaint useForEachFrame. -
Sorting. It stays in your Lua upstream of
SetData. - Grids, trees, and column tables. These are out of scope for Foundry: List is not a general-purpose UI toolkit. The ScrollBox system offers grid, tree, and biaxal views; List bridges the linear list view only. The others bolt onto the raw ScrollBox.
- Empty-state text. An empty list is simply empty; List renders no player-facing strings at all. Draw your own "no results" text in the parent.
Scope boundary. List wires the scrolling-list machinery; you own the cell contents. It is not an anchoring or layout engine, and not a widget library for what goes inside a row.
Secure and taint boundary. List operates entirely in the insecure domain. It must not host secure action buttons (spell, macro, or action-bar buttons) inside rows; that stays your responsibility. Any use needing a secure template or a combat-protected frame operation is refused, not wrapped.
List follows Foundry's two-build policy via F:RaiseDevError. Dev builds
error() loudly at the caller; release builds print() and the call refuses
(returns nil). It is never a silent no-op. Messages:
| Condition | Message |
|---|---|
| Non-table config | List:New: config must be a table |
| Missing/empty name | List:New: config.name must be a non-empty string |
| Missing parent | List:New: config.parent must be a frame |
| Neither template nor elementType | List:New: config requires exactly one of template or elementType |
| Both template and elementType | List:New: config.template and config.elementType are mutually exclusive |
template not a string |
List:New: config.template must be a string |
elementType not a string |
List:New: config.elementType must be a string |
| Missing initializer | List:New: config.initializer must be a function |
resetter not a function |
List:New: config.resetter must be a function |
| Frame-type row with no extent | List:New: elementType rows require config.extent (> 0) or config.extentCalculator |
| extent and extentCalculator both set | List:New: config.extent and config.extentCalculator are mutually exclusive |
extentCalculator not a function |
List:New: config.extentCalculator must be a function |
| Non-positive extent | List:New: config.extent must be a number > 0 |
spacing not a number |
List:New: config.spacing must be a number |
SetData non-array or non-table rows |
List:SetData: data must be an array of tables (non-table rows disable recycling) |
| Mutate during initialize | List:SetData: cannot mutate data from inside an initializer |
extentCalculator returns a non-number or ≤ 0 (runtime) |
List: extentCalculator must return a number > 0 (got <value>) |
| Method after Destroy | List:<method> called on a destroyed controller |
| Double-Destroy | List:Destroy called on a destroyed controller |
| ScrollBox system absent (flavor gate) | List:New: this client lacks the modern scrolling-list system (ScrollUtil/CreateScrollBoxListLinearView); Foundry.List is unavailable here |
List targets all three flavors Foundry ships (Retail, Classic Era, Burning
Crusade Classic) as a runtime capability gate, not a compile-time assumption. At :New,
List presence-checks the ScrollBox system. If it is present, List builds the
list; if it is absent, List refuses with the flavor-gate message above and never
silently no-ops. List ships no FauxScrollFrame fallback. A consumer that must
support a client without the ScrollBox system keeps its own legacy path and gates
its List adoption behind a capability check.