Thread Tools Display Modes
01-05-24, 09:07 PM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Fix over scroll

Hi all

I have a bear-bones scroll set up that is over-scrolling past the last data button.


Here is my code:
Lua Code:
  1. local function updateScrollFrame()
  2.     FauxScrollFrame_Update(
  3.         TestScrollFrame,
  4.         #TestData,
  5.         7,
  6.         20
  7.     )
  8.     for index = 1, 7 do
  9.         local offset = index + FauxScrollFrame_GetOffset(TestScrollFrame)
  10.         local button = TestScrollFrame.buttons[index]
  11.         button:SetNormalFontObject(NumberFontNormalLargeYellow)
  12.         button:SetHighlightFontObject(NumberFontNormalLargeYellow)
  13.         button.index = offset
  14.         if offset <= #TestData then
  15.             button:SetText(TestData[offset])
  16.             button:Show()
  17.         else
  18.             button:Hide()
  19.         end
  20.     end
  21. end
  22.  
  23. local TestScrollFrame = CreateFrame("Frame", "TestScrollFrame", TestInterfaceFrame, "ChatConfigBoxTemplate")
  24. TestScrollFrame:SetSize(500, 150)
  25. TestScrollFrame:SetPoint("TOPLEFT", TestInterfaceFrame, "BOTTOMLEFT")
  26.  
  27. local TestScrollFrame =
  28.     CreateFrame("ScrollFrame", "TestScrollFrame", TestScrollFrame, "FauxScrollFrameTemplate")
  29. TestScrollFrame:SetPoint("TOPLEFT", 0, -8)
  30. TestScrollFrame:SetPoint("BOTTOMRIGHT", -30, 8)
  31. TestScrollFrame:SetScript(
  32.     "OnVerticalScroll",
  33.     function(self, offset)
  34.         FauxScrollFrame_OnVerticalScroll(self, offset, 7, updateScrollFrame)
  35.     end
  36. )
  37.  
  38. TestScrollFrame.buttons = {}
  39. for index = 1, 7 do
  40.     TestScrollFrame.buttons[index] =
  41.         CreateFrame("Button", "$parentbtn" .. index, TestScrollFrame, "OptionsListButtonTemplate")
  42.     local button = TestScrollFrame.buttons[index]
  43.     button:SetSize(500, 20)
  44.     button:SetPoint("TOPLEFT", 8, -(index - 1) * 20 - 8)
  45.     button:SetScript(
  46.         "OnClick",
  47.         function(self, button)
  48.             if button == "RightButton" then
  49.                 print(TestData, self.index)
  50.                 updateScrollFrame()
  51.             end
  52.         end
  53.     )
  54. end

How do I solve the over-scrolling issue?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
01-05-24, 11:23 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
Here's your code with some adjustments with a table of 50 entries to scroll through. See how buttonHeight (the height of a single row button) is used by FauxScrollFrame to calulate the offset of the thumb position in the bar and used in OnVerticalScroll to calculate back to an offset row in your data table for the update functions starting position.

I calculated the buttonHeight based on fitting 7 rows into the height of your ScrollFrame.

I moved the frames to UIParent so, move the back where you want.

Lua Code:
  1. local buttonHeight
  2. local data = {}
  3. for i=1, 50 do
  4.     tinsert(data, { value = random(1, 500), display = i })
  5. end
  6.  
  7. local function updateScrollFrame(self)
  8.     local rowHeight = buttonHeight
  9.     local totalEntries = #data
  10.     local filled, index, row, rowData = 0
  11.     local offset = self.Offset or 0 -- the data row to start at (caculated at OnVertivalScroll or zero)
  12.     local rows, rowHeight = #self.buttons, self.buttons[1]:GetHeight()
  13.     for i=1, totalEntries do -- Fill the 7 rows and show the row button
  14.         index = offset + i
  15.         rowData = data[index]
  16.         if rowData then
  17.             filled = filled + 1
  18.             row = self.buttons[i]
  19.             row:SetText(format("Data Row %d (%d)", rowData.display, rowData.value))
  20.             row.index = index
  21.             row:Show()
  22.             if i == rows then
  23.                 break
  24.             end
  25.         end
  26.     end
  27.     if filled < rows then -- hide any non-filled button (probably not neede for a simple FauxScrollFrame but...
  28.         for i = filled + 1, rows do
  29.             self.buttons[i]:Hide()
  30.         end
  31.     end
  32.     FauxScrollFrame_Update(self, totalEntries, rows, rowHeight) -- Update the scrollbar
  33. end    
  34.    
  35. local TestScrollFrame = CreateFrame("Frame", "TestScrollFrame", UIParent, "ChatConfigBoxTemplate")
  36. TestScrollFrame:SetSize(500, 150)
  37. --    TestScrollFrame:SetPoint("TOPLEFT", TestInterfaceFrame, "BOTTOMLEFT")
  38. TestScrollFrame:SetPoint("CENTER")
  39.      
  40. local TestScrollFrame =
  41.         CreateFrame("ScrollFrame", "TestScrollFrame", TestScrollFrame, "FauxScrollFrameTemplate")
  42. TestScrollFrame:SetPoint("TOPLEFT", 0, 0)
  43. TestScrollFrame:SetPoint("BOTTOMRIGHT", -25, 0)
  44.  
  45. buttonHeight = TestScrollFrame:GetHeight() /  7 -- so you know the height of a button    
  46.  
  47. TestScrollFrame:SetScript(
  48.         "OnVerticalScroll",
  49.         function(self, offset) -- offset is based on the height of the scrollbar / the height of a row button see: FauxScrollFrame_Update
  50.             self.Offset = math.floor(offset / buttonHeight) -- calulate offset back to the data row to start at
  51.             updateScrollFrame(self)
  52.         end
  53. )
  54.      
  55. TestScrollFrame.buttons = {}
  56.  
  57. for index = 1, 7 do
  58.         TestScrollFrame.buttons[index] =
  59.             CreateFrame("Button", "$parentbtn" .. index, TestScrollFrame, "OptionsListButtonTemplate")
  60.         local button = TestScrollFrame.buttons[index]
  61.         button:SetID(index)
  62.         button:SetSize(TestScrollFrame:GetWidth() - 50, buttonHeight)
  63.         if index == 1 then
  64.             button:SetPoint("TOPLEFT", 8, 0)
  65.         else
  66.             button:SetPoint("TOPLEFT", TestScrollFrame.buttons[index - 1], "BOTTOMLEFT")
  67.         end
  68.         button:SetScript(
  69.             "OnClick",
  70.             function(self, button)
  71.                 if button == "RightButton" then
  72.                     print("Button:", self:GetID(), "Value:", data[self.index].value)
  73. --                    updateScrollFrame()
  74.                 end
  75.             end
  76.         )
  77. end
  78. updateScrollFrame(TestScrollFrame) -- Get Started (no offset so updateScrollFrame will start a zero

As an aside, FauxScrollFrame has been deprecated but I don't expect it will go away any time soon but you may want to consider updating or replacing the Faux... methods with your own at some point.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 01-05-24 at 11:34 PM.
  Reply With Quote
01-06-24, 06:22 PM   #3
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi Fizzlemizz

Thanks for your code, it works perfectly; I will have to frankenstein it to meet my needs.

When you say "You may want to consider updating or replacing the Faux... methods with your own at some point." how would I do such a thing?

I am still a novice when it comes to coding.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
01-06-24, 07:14 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
An example by MeoRaw on the new ScrollList interface that replaces FauxScroll and I believe HybridScroll can be found Here.

As I said, probably not an immediate need but something to keep in mind if the time comes.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-08-24, 08:50 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
A page on making Scrollable Frames was added to the wiki yesterday. It doesn't have everything but will hopefully grow and improve over time.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
01-08-24, 09:58 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Cool, quite different to how it worked before so will be handy to know it works now for when I may need it in the future.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Fix over scroll


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