Thread Tools Display Modes
04/12/14, 07:19 PM   #1
gamer8bit
Join Date: Apr 2014
Posts: 1
Post window with scrolling

Hi,
I'm working on an auction house addon that will list contents of all my guild stores. I'm having trouble creating a scroll bar that can be clicked on to show extra listings. I'm trying to use a slider, but can't get it to show up. Here is what I have so far in my XML:
<GuiXml>
<Controls>
<TopLevelControl>
<Controls>
<Slider name="$(parent)_Slider" color="aaaaaa" verticalAlignment="CENTER" horizontalAlignment="RIGHT" min="1" max="10" step="1">
<Anchor point="TOPRIGHT"/>
<Dimensions x="10" y="850" />
</Slider>
...
To be perfectly honest, I'm not sure if a slider is the best way to do it. Any help would be awesome

Thank You
  Reply With Quote
04/12/14, 07:53 PM   #2
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
The slider is handy for scrolling lists of items. You would still have to implement the control that the slider will be controlling the offset for.

I did a basic one but not in XML just Lua but you're welcome to have a look.

It's very basic and after coming across textcontrol used in the chat frame I realised I didn't need this way so scrapped it either in the new version or the last uploaded one, I can't quite remember.

Hopefully it will help you get started and can go from there.

Lua Code:
  1. local historyWindow
  2.  
  3. -- Update the History Window by using the slider position to figure out which offset in the data table
  4. -- in this case a simple text list for the label controls used.
  5. local function UpdateHistoryWindow(...)
  6.     local tlw = historyWindow
  7.     tlw.DataOffset = tlw.DataOffset or 0
  8.     if tlw.DataOffset < 0 then tlw.DataOffset = 0 end
  9.     if #tlw.DataLines == 0 then return end
  10.     tlw.Slider:SetMinMax(0,#tlw.DataLines - tlw.MaxLines)
  11.     for i = 1,tlw.MaxLines do
  12.         local curLine = tlw.Lines[i]
  13.         local curData = tlw.DataLines[tlw.DataOffset + i]
  14.         curLine.Text:SetText(curData)
  15.     end
  16. end

Lua Code:
  1. -- Initialise the History Window
  2. -- 30 label controls seemed adequate for a screen full of information,
  3. -- the scroll bar would simply move the starting point in the data list
  4. -- to decide which one goes on which label
  5. local function InitHistoryWindow(...)
  6.     local tlw = WINDOW_MANAGER:CreateTopLevelWindow(nil)   
  7.  
  8.     tlw.DataOffset = 0
  9.     tlw.MaxLines = 30
  10.     tlw.DataLines = {}
  11.     tlw.Lines = {}
  12.  
  13.     tlw:SetHeight(625)
  14.     tlw:SetWidth(575)
  15.     tlw:SetAnchor(CENTER,GuiRoot,CENTER,0,0)
  16.     tlw:SetDrawLayer(DL_BACKGROUND)
  17.     tlw:SetMouseEnabled(true)
  18.     tlw:SetMovable(false)
  19.     tlw:SetClampedToScreen(true)
  20.     tlw:SetHidden(true)
  21.     tlw:SetHandler("OnMouseWheel",function(self,delta)
  22.         local value = tlw.DataOffset - delta
  23.         if value < 0 then
  24.             value = 0
  25.         elseif value > #tlw.DataLines - tlw.MaxLines then
  26.             value = #tlw.DataLines - tlw.MaxLines
  27.         end
  28.         tlw.DataOffset = value
  29.         tlw.Slider:SetValue(tlw.DataOffset)
  30.         UpdateHistoryWindow()
  31.     end)
  32.     tlw:SetHandler("OnShow",function(self)
  33.         local index = 0
  34.  
  35.         -- Make sure we are looking at the latest data  
  36.                 -- I create a quick access table for traversing easily
  37.                 -- for reading purposes only
  38.         UpdateHarvestHistory()
  39.  
  40.         -- Update what the window lines are going to show.
  41.                 -- This is reading through my table of data generated with the function above.
  42.                 -- And generating a text line of information to display on the label
  43.         tlw.DataLines = {}
  44.         for historyIndex,historyData in pairs(harvestHistory) do
  45.             for zoneIndex,zoneData in pairs(historyData) do
  46.                 if zoneIndex ~= "version" then
  47.                     for itemIndex,itemData in pairs(zoneData) do
  48.                         for indexIndex,indexData in pairs(itemData) do
  49.                             index = index + 1
  50.                             tlw.DataLines[index] = string.format("[%d]: %s %s in %s at %0.3f,%0.3f",index,itemIndex,tostring(indexData["Action"]),zoneIndex,indexData["X"],indexData["Y"])
  51.                         end
  52.                     end
  53.                 end
  54.             end
  55.         end
  56.         tlw.Caption.Text:SetText(addonName .. " ["..addonVersion.."] - " .. #tlw.DataLines or 0 .. " Total")
  57.         UpdateHistoryWindow()
  58.     end)
  59.  
  60.     tlw.BackGround = WINDOW_MANAGER:CreateControl(nil,tlw,CT_BACKDROP)
  61.     tlw.BackGround:SetAnchorFill(tlw)
  62.     tlw.BackGround:SetCenterColor(0.0, 0.0, 0.0, 0.5)  
  63.     tlw.BackGround:SetEdgeColor(1.0, 1.0, 0.0, 0.5)
  64.     tlw.BackGround:SetEdgeTexture(nil, 2, 2, 2.0, 2.0)  
  65.  
  66.         -- This is what turns a simple slider into a scrollbar
  67.     local tex = "/esoui/art/miscellaneous/scrollbox_elevator.dds"
  68.     tlw.Slider = WINDOW_MANAGER:CreateControl(nil,tlw,CT_SLIDER)
  69.     tlw.Slider:SetDimensions(30,tlw:GetHeight())
  70.     tlw.Slider:SetMouseEnabled(true)
  71.     tlw.Slider:SetThumbTexture(tex,tex,tex,30,50,0,0,1,1)
  72.     tlw.Slider:SetValue(0)
  73.     tlw.Slider:SetValueStep(1)
  74.     tlw.Slider:SetAnchor(LEFT,tlw,RIGHT,0,0)
  75.  
  76.         -- When we change the slider's value we need to change the data offset and redraw the display
  77.     tlw.Slider:SetHandler("OnValueChanged",function(self,value,eventReason)
  78.         tlw.DataOffset = math.min(value,#tlw.DataLines - tlw.MaxLines)
  79.         UpdateHistoryWindow()
  80.     end)
  81.  
  82.     tlw.Caption = WINDOW_MANAGER:CreateControl(nil,tlw,CT_CONTROL)
  83.     tlw.Caption:SetDimensions(tlw:GetWidth(),30)
  84.     tlw.Caption:SetAnchor(BOTTOMLEFT,tlw,TOPLEFT,0,0)
  85.     tlw.Caption:SetHidden(false)
  86.  
  87.     tlw.Caption.Text = WINDOW_MANAGER:CreateControl(nil,tlw.Caption,CT_LABEL)
  88.     tlw.Caption.Text:SetAnchorFill(tlw.Caption)
  89.     tlw.Caption.Text:SetFont("ZoFontGameLargeBoldShadow")
  90.     tlw.Caption.Text:SetDimensions(tlw.Caption:GetWidth(),tlw.Caption:GetHeight())
  91.     tlw.Caption.Text:SetText(addonName .. " ["..addonVersion.."] - " .. #harvestHistory or 0 .. " Total")
  92.     tlw.Caption.Text:SetHorizontalAlignment(TEXT_ALIGN_LEFT)
  93.     tlw.Caption.Text:SetHidden(false)
  94.  
  95.     tlw.Close = WINDOW_MANAGER:CreateControl(nil,tlw,CT_BUTTON)
  96.     tlw.Close:SetDimensions(tlw.Caption:GetHeight(),tlw.Caption:GetHeight())
  97.     tlw.Close:SetAnchor(BOTTOMRIGHT,tlw.Slider,TOPRIGHT,0,0)
  98.     tlw.Close:SetHidden(false)
  99.     tlw.Close:SetFont("ZoFontGameLargeBoldShadow")
  100.     tlw.Close:SetText("X")
  101.     tlw.Close:SetHandler("OnClicked",function(self)
  102.         tlw:SetHidden(true)
  103.     end)
  104.  
  105.         -- And this is the block of code that generates the group of controls that make up the scrollable area.
  106.         -- As well as labels you could add buttons and other controls and attach them to the lines control.
  107.     for i=1,tlw.MaxLines do
  108.         tlw.Lines[i] = WINDOW_MANAGER:CreateControl(nil,tlw,CT_CONTROL)
  109.         tlw.Lines[i]:SetDimensions(tlw:GetWidth(),20)
  110.         if i == 1 then
  111.             tlw.Lines[i]:SetAnchor(TOPLEFT,tlw,TOPLEFT,5,5)
  112.         else
  113.             tlw.Lines[i]:SetAnchor(TOPLEFT,tlw.Lines[i-1],BOTTOMLEFT,0,0)
  114.         end
  115.  
  116.         tlw.Lines[i].Text = WINDOW_MANAGER:CreateControl(nil,tlw.Lines[i],CT_LABEL)
  117.         tlw.Lines[i].Text:SetFont("ZoFontGame")
  118.         tlw.Lines[i].Text:SetDimensions(tlw.Lines[i]:GetWidth(),30)
  119.         tlw.Lines[i].Text:SetAnchor(LEFT,tlw.Lines[i],LEFT,5,5)
  120.         tlw.Lines[i].Text:SetText(string.format("Line %d Data %s",i,"Line " .. i))
  121.         tlw.Lines[i]:SetHidden(false)
  122.     end
  123.  
  124.         -- transfer simply named control to a more user friendly file wide control name
  125.     historyWindow = tlw
  126. end

Lua Code:
  1. -- Our Addon is loaded so we can start work
  2. local function AddOnLoaded(eventID,addon)
  3.     if addon ~= addonName then return end
  4.     EVENT_MANAGER:UnregisterForEvent(addonName,eventID)
  5.     -- Initialise your saved variables here so it's ready when you need it
  6.     InitHistoryWindow()
  7.     EVENT_MANAGER:RegisterForEvent( addonName ,EVENT_PLAYER_ACTIVATED , PlayerActivated )
  8. end

Lua Code:
  1. -- Track addons loading
  2. EVENT_MANAGER:RegisterForEvent( addonName ,EVENT_ADD_ON_LOADED , AddOnLoaded )
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » window with scrolling


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off