View Single Post
04-28-23, 10:38 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,895
Lists are complicated until you understand them.

This is a list example created by someone else and loosly based on what I know of your addon.

The AppendListItem function is actually creating the the information table that is displayed in the list.

XML
XML Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ http://wowprogramming.com/FrameXML/UI.xsd">
  2.     <!-- formatting for each row of the list -->
  3.     <Frame name="AMD_ScrollableListItemTemplate" mixin="AMD_ScrollableListItemMixin" virtual="true">
  4.         <Size y="21"/>
  5.         <Layers>
  6.             <Layer level="BACKGROUND">
  7.                 <Texture parentKey="Background" setAllPoints="true"/>
  8.             </Layer>
  9.             <Layer level="OVERLAY">
  10.                 <FontString parentKey="Text" inherits="GameFontHighlight" setAllPoints="true"/>
  11.             </Layer>
  12.         </Layers>
  13.     </Frame>
  14.  
  15.     <!-- Create a list template extending the Blizzard scrollbox code for customised use -->
  16.     <Frame name="AMD_ScrollableListTemplate" mixin="AMD_ScrollableListMixin" virtual="true">
  17.         <Frames>
  18.             <Frame parentKey="ScrollBox" inherits="WowScrollBoxList"/>
  19.             <EventFrame parentKey="ScrollBar" inherits="WowTrimScrollBar">
  20.                 <Anchors>
  21.                     <Anchor point="TOPRIGHT"/>
  22.                     <Anchor point="BOTTOMRIGHT"/>
  23.                 </Anchors>
  24.             </EventFrame>
  25.         </Frames>
  26.         <Scripts>
  27.             <OnLoad method="OnLoad"/>
  28.         </Scripts>
  29.     </Frame>
  30.  
  31.     <Frame name="AMD_TabOnCharacterFrame" parent="CharacterFrame" mixin="AMD_TabOnCharacterFrameMixin" frameStrata="HIGH" enableMouse="true" movable="true" setallpoints="true" id="4" inherits="ButtonFrameTemplate">
  32.         <Frames>
  33.  
  34.             <!-- add the listbox top you frame -->
  35.             <Frame parentKey="ListFrame" inherits="AMD_ScrollableListTemplate">
  36.                 <Anchors>
  37.                     <Anchor point="TOPLEFT">
  38.                         <Offset><AbsDimension y="-50"/></Offset>
  39.                     </Anchor>
  40.                     <Anchor point="BOTTOMRIGHT">
  41.                         <Offset><AbsDimension y="25"/></Offset>
  42.                     </Anchor>
  43.                 </Anchors>
  44.             </Frame>
  45.  
  46.             <Frame name="$parent_History" parent="AMD_TabOnCharacterFrame">
  47.                 <Anchors>
  48.                     <Anchor point="CENTER" relativePoint="CENTER" relativeTo="CharacterFrame"/>
  49.                 </Anchors>
  50.             </Frame>
  51.             <Button name="$parent_Options" inherits="PanelTopTabButtonTemplate" text="Options">
  52.                 <Anchors>
  53.                     <Anchor point="BOTTOMLEFT" x="98" y="440"/>
  54.                 </Anchors>
  55.                 <ButtonText parentKey="Text">
  56.                     <Size x="0" y="10"/>
  57.                     <Anchors>
  58.                         <Anchor point="CENTER" x="0" y="-8"/>
  59.                     </Anchors>
  60.                 </ButtonText>
  61.             </Button>
  62.             <Button name="$parent_PreviousButton" inherits="UIPanelButtonTemplate" text="NEXT">
  63.                 <Size x="109" y="22"/>
  64.                 <Anchors>
  65.                     <Anchor point="BOTTOMRIGHT" x="-6" y="6"/>
  66.                 </Anchors>
  67.             </Button>
  68.             <Button name="$parent_SaveButton" inherits="UIPanelButtonTemplate" text="BACK">
  69.                 <Size x="100" y="22"/>
  70.                 <Anchors>
  71.                     <Anchor point="BOTTOMLEFT" x="95" y="83"/>
  72.                 </Anchors>
  73.             </Button>
  74.             <Button name="$parent_NextButton" inherits="UIPanelButtonTemplate" text="PREVIOUS">
  75.                 <Size x="109" y="22"/>
  76.                 <Anchors>
  77.                     <Anchor point="BOTTOMLEFT" x="6" y="6"/>
  78.                 </Anchors>
  79.             </Button>
  80.         </Frames>
  81.             <Scripts>
  82.                 <OnLoad method="OnLoad"/>
  83.             </Scripts>
  84.     </Frame>
  85. </Ui>

lua:
Lua Code:
  1. AMD_ScrollableListItemMixin = {} -- does the visual row display as the list is scrolled
  2. function AMD_ScrollableListItemMixin:Init(elementData)
  3.     self.Background:SetColorTexture(elementData.color:GetRGBA())
  4.     self.Text:SetText(elementData.text)
  5. end
  6.  
  7. AMD_TabOnCharacterFrameMixin = {}
  8. function AMD_TabOnCharacterFrameMixin:OnLoad() -- add 100 items to the list to be scrolled
  9.     for _ = 1, 100 do
  10.         self.ListFrame:AppendListItem()
  11.     end
  12. end
  13.  
  14. AMD_ScrollableListMixin = {}
  15. function AMD_ScrollableListMixin:OnLoad() -- initialise the list
  16.     -- The data provider acts as the backing model for a scrollview each
  17.     -- element ("elementData") in the data provider corresponds to one row
  18.     -- in the displayed list. The actual values can be anything. The default
  19.     -- below creates an empty data provider, but you can pass a table in as
  20.     -- the first argument to pre-populate it with values.
  21.  
  22.     self.DataProvider = CreateDataProvider()
  23.  
  24.     -- The scroll view is responsible for managing the acquisition of pooled
  25.     -- frames and laying them out for display. This needs to be supplied with
  26.     -- a data provider, an element extent (size), and an element factory or
  27.     -- initializer at minimum.
  28.     --
  29.     -- The extent must be the actual height of each row. It can be dynamically
  30.     -- calculated with a function, but a fixed extent is much more performant.
  31.  
  32.     local elementExtent = 21
  33.  
  34.     self.ScrollView = CreateScrollBoxListLinearView()
  35.     self.ScrollView:SetDataProvider(self.DataProvider)
  36.     self.ScrollView:SetElementExtent(elementExtent)
  37.  
  38. --[[ -- Currently use on Wrath pre 3.4.1 and Vanilla
  39.     self.ScrollView:SetElementInitializer("Frame", "AMD_ScrollableListItemTemplate", function(frame, elementData)
  40.         -- This is called each time the scrollview acquires a frame this
  41.         -- should generally call a method on the acquired frame and update
  42.         -- its visual state accordingly.
  43.  
  44.         frame:Init(elementData)
  45.     end)
  46.  
  47. ]]--
  48. --[[ Use on Retail and Wrath post 3.4.1 ]]--
  49.     self.ScrollView:SetElementInitializer("AMD_ScrollableListItemTemplate", function(frame, elementData)
  50.         -- This is called each time the scrollview acquires a frame this
  51.         -- should generally call a method on the acquired frame and update
  52.         -- its visual state accordingly.
  53.  
  54.         frame:Init(elementData)
  55.     end)
  56.  
  57.     -- Padding and spacing are optional these are just demo values. The
  58.     -- defaults if no padding is configured will all be zero.
  59.  
  60.     local paddingT = 10
  61.     local paddingB = 10
  62.     local paddingL = 10
  63.     local paddingR = 10
  64.     local spacing = 5
  65.  
  66.     self.ScrollView:SetPadding(paddingT, paddingB, paddingL, paddingR, spacing)
  67.  
  68.     -- The below call is required to hook everything up automatically.
  69.  
  70.     ScrollUtil.InitScrollBoxListWithScrollBar(self.ScrollBox, self.ScrollBar, self.ScrollView)
  71.  
  72.     -- If you want the scrollbar to show or hide automatically based on
  73.     -- whether or not the region can be scrolled, you'll need two anchor
  74.     -- tables to configure the managed scroll visibility behavior.
  75.  
  76.     local anchorsWithBar = {
  77.         CreateAnchor("TOPLEFT", self, "TOPLEFT", 4, -4),
  78.         CreateAnchor("BOTTOMRIGHT", self.ScrollBar, "BOTTOMLEFT", 0, 4),
  79.     }
  80.  
  81.     local anchorsWithoutBar = {
  82.         CreateAnchor("TOPLEFT", self, "TOPLEFT", 4, -4),
  83.         CreateAnchor("BOTTOMRIGHT", self, "BOTTOMRIGHT", -4, 4),
  84.     }
  85.  
  86.     ScrollUtil.AddManagedScrollBarVisibilityBehavior(self.ScrollBox, self.ScrollBar, anchorsWithBar, anchorsWithoutBar)
  87. end
  88.  
  89. function AMD_ScrollableListMixin:AppendListItem() -- this creates the line items
  90.     local color = CreateColor(fastrandom(), fastrandom(), fastrandom())
  91.     local text = string.format("Time: %.5f", GetTime())
  92.  
  93.     local elementData = -- Used by the list to display each list row text and color as they're scrolled
  94.     {
  95.         color = color,
  96.         text = text,
  97.     }
  98.  
  99.     self.DataProvider:Insert(elementData)
  100.     self.ScrollBox:ScrollToEnd(ScrollBoxConstants.NoScrollInterpolation)
  101. end
  102.  
  103. function AMD_ScrollableListMixin:RemoveListItem()
  104.     local lastIndex = self.DataProvider:GetSize()
  105.     self.DataProvider:RemoveIndex(lastIndex)
  106. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote