Lore archive · Warcraft Wiki, 2023 dump
HybridScrollFrame
Last wiki revision 2023-07-19
The HybridScrollFrame is a FrameXML-provided frame that is used by the UI to display large collections of items/object but without creating a new frame for each.
XML listview item template <UI> <Frame name="HybridScrollFrameItem" mixin="HybridScrollFrameItemMixin" virtual="true" enableMouse="true"> <Size x="196" y="60"/> <Layers> <Layer level="BACKGROUND"> <Texture parentKey="Background" atlas="Garr_ListButton" useAtlasSize="false"> <Size x="196" y="60"/> <Anchors> <Anchor point="CENTER"/> </Anchors> </Texture> </Layer> <Layer level="OVERLAY"> <FontString parentKey="Subject" inherits="GameFontNormal" justifyH="CENTER"> <Size x="160" y="50"/> <Color r="1" g="1" b="1"/> <Anchors> <Anchor point="CENTER" x="0" y="0"/> </Anchors> </FontString> </Layer> </Layers> </Frame> </UI>
lua listview item template mixin HybridScrollFrameItemMixin = {} function HybridScrollFrameItemMixin:SetSubject(subject) self.Subject:SetText(subject) end
addon file -- create a table of items local items = {} for i = 1, 10 do table.insert(items, { Subject = "Subject "..i, }) end -- create the hybrid scroll frame local hsf = CreateFrame("ScrollFrame", "MyScrollFrame", UIParent, "HybridScrollFrameTemplate") hsf:SetPoint("CENTER", 0, 0) hsf:SetSize(200, 300) hsf.items = items -- add a scroll bar hsf.ScrollBar = CreateFrame("Slider", "$parentScrollBar", hsf, "HybridScrollBarTemplate") hsf.ScrollBar:SetPoint("TOPLEFT", hsf, "TOPRIGHT", 1, -16) hsf.ScrollBar:SetPoint("BOTTOMLEFT", hsf, "BOTTOMRIGHT", 1, 12) -- this will create listview items using the template define, the number of buttons is determined by the HybridScrollFrame_CreateButtons(hsf, "HybridScrollFrame_Item", 0, 0, "TOP", "TOP", 0, 0, "TOP", "BOTTOM") -- this is the update function, this will be called by the HybridScrollFrameTemplate, all that needs doing here is mapping your data to the buttons hsf.update = function local items = hsf.items; local buttons = HybridScrollFrame_GetButtons(hsf); local offset = HybridScrollFrame_GetOffset(hsf); local buttonHeight; for buttonIndex = 1, #buttons do local button = buttons[buttonIndex] local itemIndex = buttonIndex + offset buttonHeight = button:GetHeight -- set the button height var to use in the update call later if itemIndex <= #items then local item = items[itemIndex] button:SetSubject(item.Subject) end end HybridScrollFrame_Update(hsf, #hsf.items * buttonHeight, hsf:GetHeight) end
Source
https://warcraft.wiki.gg/wiki/HybridScrollFrame · retrieved 2023-11-13 · CC BY-SA 4.0
Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.
This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.