Thread Tools Display Modes
10-22-22, 09:55 AM   #1
dust514
A Defias Bandit
Join Date: Oct 2022
Posts: 2
Question wow ScrollFrame ui

This is my first time using Lua and I try to make the button scroll

I would like to know how to make the button scroll in the ScrollFrame

Sorry, English is not my native language

I hope someone can help me, this confused me for a long time,Thanks

Code:
local fk_ui = {}
local backdrop = {
    bgFile = "Interface/BUTTONS/WHITE8X8",
    edgeFile = "Interface/GLUES/Common/Glue-Tooltip-Border",
    tile = true,
    edgeSize = 8,
    tileSize = 8,
    insets = {
        left = 5,
        right = 5,
        top = 5,
        bottom = 5,
    },
}

local f = CreateFrame("Frame", "MyScrollMessageTextFrame", UIParent)
f:SetSize(450, 450)
f:SetPoint("CENTER")
f:SetFrameStrata("BACKGROUND")
f:SetBackdrop(backdrop)
f:SetBackdropColor(0, 0, 0)
f.Close = CreateFrame("Button", "$parentClose", f)
f.Close:SetSize(24, 24)
f.Close:SetPoint("TOPRIGHT")
f.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")
f.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")
f.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")
f.Close:SetScript("OnClick", function(self)
    self:GetParent():Hide()
end)

f.SF = CreateFrame("ScrollFrame", "$parent_DF", f, "UIPanelScrollFrameTemplate")
f.SF:SetPoint("TOPLEFT", f, 12, -30)
f.SF:SetPoint("BOTTOMRIGHT", f, -30, 10)

for i = 1,15 do
	fk_ui[i] = "fk_1a"..i
	fk_ui[i] = CreateFrame("Button",fk_ui[i],fk_box,"GameMenuButtonTemplate")
	fk_ui[i]:SetPoint("CENTER",-6,120+(i*-40))
	fk_ui[i]:SetSize(128,35)
end
this is all

I referenced the content here
https://www.wowinterface.com/forums/...50&postcount=2

  Reply With Quote
10-22-22, 12:18 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
It works a bit differently than using an EditBox as your "source" list (table).

Using the games FauxScrollFrame, you would need to create the number of rows you want your scroll list to show (5 rows to scroll, each with a button in the code below) and then as the list is scrolled, the information from your source table, starting at the entry indicated by the position of the scroll thumb, is "copied" to the corresponding "row and button" in the scroll list". The math for the thumb position is calculated based on the height of a single row in the scroll list (35 in this case which is both the row and button height)

Lua Code:
  1. local fk_ui = {}
  2. local backdrop = {
  3.     bgFile = "Interface/BUTTONS/WHITE8X8",
  4.     edgeFile = "Interface/GLUES/Common/Glue-Tooltip-Border",
  5.     tile = true,
  6.     edgeSize = 8,
  7.     tileSize = 8,
  8.     insets = {
  9.         left = 5,
  10.         right = 5,
  11.         top = 5,
  12.         bottom = 5,
  13.     },
  14. }
  15.  
  16. local function OnClick(self)
  17.     local entry = fk_ui[self:GetParent().index]
  18.     print("You Clicked: ", entry)
  19. end
  20.  
  21. local function Update_List(self)
  22.     local table = fk_ui
  23.     if not table then return end
  24.     local offset = self.offset or 0
  25.     local index, row
  26.     local entries = #table
  27.     local include = 0
  28.     local rows = #self.Rows
  29.     for i=1, rows do
  30.         index = offset + i
  31.         if table[index] then
  32.             include = include + 1
  33.             row = self.Rows[include]
  34.             row:Show()
  35.             row.index = index
  36.             row.Button:SetText(table[index])
  37.             if include == entries then break end -- only loop enough to fill #rows (5)
  38.         end
  39.     end
  40.     if include < rows then
  41.         for i = include + 1, rows do
  42.             self.Rows[i]:Hide()
  43.         end
  44.     end
  45.     FauxScrollFrame_Update(self, entries, rows, 35)
  46. end
  47.  
  48. local function OnVerticalScroll(self, offset)
  49.     self.ScrollBar:SetValue(offset)
  50.     self.offset = math.floor((offset / 35) + 0.5)
  51.     Update_List(self)
  52. end
  53.  
  54. local f = CreateFrame("Frame", "MyScrollMessageTextFrame", UIParent, BackdropTemplateMixin and "BackdropTemplate")
  55. f:SetSize(450, 450)
  56. f:SetPoint("CENTER")
  57. f:SetFrameStrata("BACKGROUND")
  58. f:SetBackdrop(backdrop)
  59. f:SetBackdropColor(0, 0, 0)
  60. f.Close = CreateFrame("Button", "$parentClose", f)
  61. f.Close:SetSize(24, 24)
  62. f.Close:SetPoint("TOPRIGHT")
  63. f.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")
  64. f.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")
  65. f.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")
  66. f.Close:SetScript("OnClick", function(self)
  67.     self:GetParent():Hide()
  68. end)
  69.  
  70. f.SF = CreateFrame("ScrollFrame", "$parent_DF", f, "FauxScrollFrameTemplate")
  71. f.SF:SetPoint("TOPLEFT", f, 12, -30)
  72. f.SF:SetPoint("BOTTOMRIGHT", f, -30, 10)
  73.  
  74. f.SF.Rows = {}
  75. for i=1, 5 do
  76.     local fr = CreateFrame("Button", "#parentRow"..i, f.SF)
  77.     tinsert(f.SF.Rows, fr)
  78.     fr:SetSize(f.SF:GetWidth(), 35)
  79.     if i == 1 then
  80.         fr:SetPoint("TOPLEFT")
  81.     else
  82.         fr:SetPoint("TOPLEFT", f.SF.Rows[i-1], "BOTTOMLEFT")
  83.     end
  84.  
  85.     fr.Button = CreateFrame("Button", "$parentButton", fr, "GameMenuButtonTemplate")
  86.     fr.Button:SetPoint("CENTER")
  87.     fr.Button:SetSize(128,35)
  88.     fr.Button:SetScript("OnClick", OnClick)
  89. end
  90.  
  91.  
  92. for i = 1,15 do
  93.     fk_ui[i] = "Press for " .. i
  94. --[[
  95.     fk_ui[i] = "fk_1a"..i
  96.     fk_ui[i] = CreateFrame("Button",fk_ui[i],fk_box,"GameMenuButtonTemplate")
  97.     fk_ui[i]:SetPoint("CENTER",-6,120+(i*-40))
  98.     fk_ui[i]:SetSize(128,35)
  99. ]]--
  100. end
  101.  
  102. f.SF.ScrollBar = FauxScrollFrame_GetChildFrames(f.SF)
  103. f.SF:SetScript("OnVerticalScroll", OnVerticalScroll) -- set the list to update when scrolled
  104. Update_List(f.SF) -- initialise the list with the first 5 entries in the source table to get started

Each buttons gets information from the source table based on the .index set for the row when the text is set for the button (see the OnClick function).

Normally you would re-size the scrollframe (or add more rows and adjust the code) to fit the area you want to display on-screen.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-22-22 at 03:28 PM.
  Reply With Quote
10-22-22, 09:04 PM   #3
dust514
A Defias Bandit
Join Date: Oct 2022
Posts: 2
Originally Posted by Fizzlemizz View Post
It works a bit differently than using an EditBox as your "source" list (table).

Using the games FauxScrollFrame, you would need to create the number of rows you want your scroll list to show (5 rows to scroll, each with a button in the code below) and then as the list is scrolled, the information from your source table, starting at the entry indicated by the position of the scroll thumb, is "copied" to the corresponding "row and button" in the scroll list". The math for the thumb position is calculated based on the height of a single row in the scroll list (35 in this case which is both the row and button height)

Lua Code:
  1. local fk_ui = {}
  2. local backdrop = {
  3.     bgFile = "Interface/BUTTONS/WHITE8X8",
  4.     edgeFile = "Interface/GLUES/Common/Glue-Tooltip-Border",
  5.     tile = true,
  6.     edgeSize = 8,
  7.     tileSize = 8,
  8.     insets = {
  9.         left = 5,
  10.         right = 5,
  11.         top = 5,
  12.         bottom = 5,
  13.     },
  14. }
  15.  
  16. local function OnClick(self)
  17.     local entry = fk_ui[self:GetParent().index]
  18.     print("You Clicked: ", entry)
  19. end
  20.  
  21. local function Update_List(self)
  22.     local table = fk_ui
  23.     if not table then return end
  24.     local offset = self.offset or 0
  25.     local index, row
  26.     local entries = #table
  27.     local include = 0
  28.     local rows = #self.Rows
  29.     for i=1, rows do
  30.         index = offset + i
  31.         if table[index] then
  32.             include = include + 1
  33.             row = self.Rows[include]
  34.             row:Show()
  35.             row.index = index
  36.             row.Button:SetText(table[index])
  37.             if include == entries then break end -- only loop enough to fill #rows (5)
  38.         end
  39.     end
  40.     if include < rows then
  41.         for i = include + 1, rows do
  42.             self.Rows[i]:Hide()
  43.         end
  44.     end
  45.     FauxScrollFrame_Update(self, entries, rows, 35)
  46. end
  47.  
  48. local function OnVerticalScroll(self, offset)
  49.     self.ScrollBar:SetValue(offset)
  50.     self.offset = math.floor((offset / 35) + 0.5)
  51.     Update_List(self)
  52. end
  53.  
  54. local f = CreateFrame("Frame", "MyScrollMessageTextFrame", UIParent, BackdropTemplateMixin and "BackdropTemplate")
  55. f:SetSize(450, 450)
  56. f:SetPoint("CENTER")
  57. f:SetFrameStrata("BACKGROUND")
  58. f:SetBackdrop(backdrop)
  59. f:SetBackdropColor(0, 0, 0)
  60. f.Close = CreateFrame("Button", "$parentClose", f)
  61. f.Close:SetSize(24, 24)
  62. f.Close:SetPoint("TOPRIGHT")
  63. f.Close:SetNormalTexture("Interface/Buttons/UI-Panel-MinimizeButton-Up")
  64. f.Close:SetPushedTexture("Interface/Buttons/UI-Panel-MinimizeButton-Down")
  65. f.Close:SetHighlightTexture("Interface/Buttons/UI-Panel-MinimizeButton-Highlight", "ADD")
  66. f.Close:SetScript("OnClick", function(self)
  67.     self:GetParent():Hide()
  68. end)
  69.  
  70. f.SF = CreateFrame("ScrollFrame", "$parent_DF", f, "FauxScrollFrameTemplate")
  71. f.SF:SetPoint("TOPLEFT", f, 12, -30)
  72. f.SF:SetPoint("BOTTOMRIGHT", f, -30, 10)
  73.  
  74. f.SF.Rows = {}
  75. for i=1, 5 do
  76.     local fr = CreateFrame("Button", "#parentRow"..i, f.SF)
  77.     tinsert(f.SF.Rows, fr)
  78.     fr:SetSize(f.SF:GetWidth(), 35)
  79.     if i == 1 then
  80.         fr:SetPoint("TOPLEFT")
  81.     else
  82.         fr:SetPoint("TOPLEFT", f.SF.Rows[i-1], "BOTTOMLEFT")
  83.     end
  84.  
  85.     fr.Button = CreateFrame("Button", "$parentButton", fr, "GameMenuButtonTemplate")
  86.     fr.Button:SetPoint("CENTER")
  87.     fr.Button:SetSize(128,35)
  88.     fr.Button:SetScript("OnClick", OnClick)
  89. end
  90.  
  91.  
  92. for i = 1,15 do
  93.     fk_ui[i] = "Press for " .. i
  94. --[[
  95.     fk_ui[i] = "fk_1a"..i
  96.     fk_ui[i] = CreateFrame("Button",fk_ui[i],fk_box,"GameMenuButtonTemplate")
  97.     fk_ui[i]:SetPoint("CENTER",-6,120+(i*-40))
  98.     fk_ui[i]:SetSize(128,35)
  99. ]]--
  100. end
  101.  
  102. f.SF.ScrollBar = FauxScrollFrame_GetChildFrames(f.SF)
  103. f.SF:SetScript("OnVerticalScroll", OnVerticalScroll) -- set the list to update when scrolled
  104. Update_List(f.SF) -- initialise the list with the first 5 entries in the source table to get started

Each buttons gets information from the source table based on the .index set for the row when the text is set for the button (see the OnClick function).

Normally you would re-size the scrollframe (or add more rows and adjust the code) to fit the area you want to display on-screen.

Thank you

I found wow 3.3.5 API no FauxScrollFrame_GetChildFrames
  Reply With Quote
10-22-22, 09:13 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Originally Posted by dust514 View Post
I found wow 3.3.5 API no FauxScrollFrame_GetChildFrames
This site does not support private servers, sorry.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » wow ScrollFrame ui


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