Scroll the config panels with ClassicAPI's scroll bar

pfUIScrollFrameTemplate (api/ui-widgets.xml) is a ScrollFrame with
pfUIScrollBarTemplate inside its right edge and a Content scroll child,
driven by ScrollUtil.InitScrollFrameWithScrollBar. The panels keep a
ScrollFrame because the engine measures its range from the shown frames
inside the content, which the hand-placed config rows rely on. The bar
follows OnScrollRangeChanged instead of an OnUpdate poll per panel.

A panel measures its range once its rows are built, and the search
results measure theirs with UpdateScrollChildRect instead of hiding,
re-attaching and scrolling a frame later. Clearing the search measures
again too.

CreateScrollFrame and CreateScrollChild have no users left, and nothing
called CreateTabFrame or CreateTabChild; all four are gone. pfQuest's
compat layer brings its own copies of the scroll helpers.
This commit is contained in:
Brues
2026-10-30 00:51:16 -05:00
parent 3987cfb8a0
commit 5d8314b2d4
3 changed files with 40 additions and 195 deletions
-182
View File
@@ -316,117 +316,6 @@ do -- dropdown
end
end
function pfUI.api.CreateTabChild(self, title, bwidth, bheight, bottom, static)
-- create tab button
local b = CreateFrame("Button", "pfConfig" .. title .. "Button", self, "UIPanelButtonTemplate")
b:SetText(title)
-- setup env
local childcount = table.getn(self.childs) + 1
local button_width = bwidth
local button_height = bheight or 20
local border = 4
if not button_width then
button_width = 150
elseif button_width == true then
button_width = _G["pfConfig" .. title .. "ButtonText"]:GetStringWidth() + 4 * border
end
-- set dimensions
b:SetSize(button_width, button_height)
b:SetID(childcount)
if not self.align or self.align == "LEFT" then
local outside = self.outside and -2 * border - button_width or 0
if bottom then
b:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", border + outside, (self.bottomcount-1) * (button_height) + (self.bottomcount * border) )
else
b:SetPoint("TOPLEFT", self, "TOPLEFT", border + outside, -(childcount-1) * (button_height) - (childcount * border) )
end
elseif self.align == "TOP" then
local outside = self.outside and 2 * border + button_height or 0
local prev_button = self.buttons[getn(self.buttons)]
if prev_button then
b:SetPoint("TOPLEFT", prev_button, "TOPRIGHT", border, 0)
else
b:SetPoint("TOPLEFT", self, "TOPLEFT", border + (self.outside and -border), -border + outside )
end
end
SkinButton(b,.2,1,.8)
if childcount ~= 1 then
b:SetTextColor(.5,.5,.5)
else
b:SetTextColor(.2,1,.8)
end
b:SetScript("OnClick", function()
for k,v in pairs(self.childs) do
v:Hide()
end
self.childs[this:GetID()]:Show()
for k,v in pairs(self.buttons) do
v.active = false
v:SetTextColor(.5,.5,.5)
end
self.buttons[this:GetID()]:SetTextColor(.2,1,.8)
end)
self.buttons[childcount] = b
self.bottomcount = bottom and self.bottomcount + 1 or self.bottomcount
-- create child frame
local child, scrollchild = nil, nil
if not static then
child = CreateScrollFrame("pfConfig" .. title .. "Frame", self)
scrollchild = CreateScrollChild("pfConfig" .. title .. "ScrollChild", child)
else
child = CreateFrame("Frame", "pfConfig" .. title .. "Frame", self)
end
if childcount ~= 1 then child:Hide() end
if not self.align or self.align == "LEFT" then
child:SetPoint("TOPLEFT", self, "TOPLEFT", button_width + 2*border + 5, -border -5)
child:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -border -5 , border + 5)
elseif self.align == "TOP" then
if self.outside then
child:SetPoint("TOPLEFT", self, "TOPLEFT", 5, -5)
child:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -5, 5)
end
end
CreateBackdrop(child)
SetAllPointsOffset(child.backdrop, child, -5,5)
local ret = scrollchild or child
ret.button = b
table.insert(self.childs, child)
return ret
end
function pfUI.api.CreateTabFrame(parent, align, outside)
local f = CreateFrame("Frame", nil, parent)
f:SetPoint("TOPLEFT", parent, "TOPLEFT", -5, 5)
f:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", 5, -5)
-- setup env
f.childs = { }
f.buttons = { }
f.align = align
f.outside = outside
f.bottomcount = 1
-- Create Child Frame
f.CreateTabChild = pfUI.api.CreateTabChild
return f
end
-- [ pfUIScrollingEditBoxTemplate ]
-- Mixin of the template in ui-widgets.xml: ClassicAPI's scrolling edit box
-- with pfUI's scroll bar beside it.
@@ -451,77 +340,6 @@ function pfUIScrollingEditBoxMixin:SetFont(font, size, flags)
self:SetFontObject(self.font)
end
function pfUI.api.CreateScrollFrame(name, parent)
local f = CreateFrame("ScrollFrame", name, parent)
-- create slider
f.slider = CreateFrame("Slider", nil, f)
f.slider:SetOrientation('VERTICAL')
f.slider:SetPoint("TOPLEFT", f, "TOPRIGHT", -7, 0)
f.slider:SetPoint("BOTTOMRIGHT", 0, 0)
f.slider:SetThumbTexture(pfUI.media["img:col"])
f.slider.thumb = f.slider:GetThumbTexture()
f.slider.thumb:SetHeight(50)
f.slider.thumb:SetTexture(.3,1,.8,.5)
f.slider:SetScript("OnValueChanged", function()
f:SetVerticalScroll(this:GetValue())
f.UpdateScrollState()
end)
f.UpdateScrollState = function()
f.slider:SetMinMaxValues(0, f:GetVerticalScrollRange())
f.slider:SetValue(f:GetVerticalScroll())
local m = f:GetHeight()+f:GetVerticalScrollRange()
local v = f:GetHeight()
local ratio = v / m
if ratio < 1 then
local size = math.floor(v * ratio)
f.slider.thumb:SetHeight(size)
f.slider:Show()
else
f.slider:Hide()
end
end
f.Scroll = function(self, step)
local step = step or 0
local current = f:GetVerticalScroll()
local max = f:GetVerticalScrollRange()
local new = current - step
f:SetVerticalScroll(Clamp(new, 0, max))
f:UpdateScrollState()
end
f:EnableMouseWheel(1)
f:SetScript("OnMouseWheel", function()
this:Scroll(arg1*10)
end)
return f
end
function pfUI.api.CreateScrollChild(name, parent)
local f = CreateFrame("Frame", name, parent)
-- dummy values required
f:SetSize(1, 1)
f:SetAllPoints(parent)
parent:SetScrollChild(f)
f:SetScript("OnUpdate", function()
this:GetParent():UpdateScrollState()
end)
return f
end
-- [ CreateTextBox ]
-- Creates and returns a default pfUI skinned EditBox
function pfUI.api.CreateTextBox(name, parent)
+30
View File
@@ -29,6 +29,36 @@
</Frames>
</EventFrame>
<!--
A ScrollFrame for free-form content, with pfUIScrollBarTemplate inside its
right edge. Put the content in frame.Content, which spans the frame: the
engine measures the scroll range from the shown frames inside it, so the
content needs no height. Changes inside it are not measured until
frame:UpdateScrollChildRect().
-->
<ScrollFrame name="pfUIScrollFrameTemplate" virtual="true">
<Frames>
<EventFrame parentKey="ScrollBar" inherits="pfUIScrollBarTemplate">
<Anchors>
<Anchor point="TOPRIGHT"/>
<Anchor point="BOTTOMRIGHT"/>
</Anchors>
</EventFrame>
</Frames>
<ScrollChild>
<Frame parentKey="Content">
<Size x="1" y="1"/>
</Frame>
</ScrollChild>
<Scripts>
<OnLoad>
self.Content:SetAllPoints()
self:EnableMouseWheel(true)
ScrollUtil.InitScrollFrameWithScrollBar(self, self.ScrollBar)
</OnLoad>
</Scripts>
</ScrollFrame>
<!--
A WowScrollBoxList with pfUIScrollBarTemplate beside it, both 5px inside the
frame so CreateBackdrop(frame, nil, true) can frame them. Fill it with
+10 -13
View File
@@ -515,14 +515,15 @@ pfUI:RegisterModule("gui", function ()
-- are we a frame with contents?
if func then
f.scroll = CreateScrollFrame(nil, f)
f.scroll = CreateFrame("ScrollFrame", nil, f, "pfUIScrollFrameTemplate")
SetAllPointsOffset(f.scroll, f, 2)
f.scroll.content = CreateScrollChild(nil, f.scroll)
f.scroll.content = f.scroll.Content
f.scroll.content.parent = f.scroll
f.scroll.content:SetScript("OnShow", function()
if not this.setup then
func()
this.setup = true
this.parent:UpdateScrollChildRect()
end
end)
end
@@ -774,7 +775,10 @@ pfUI:RegisterModule("gui", function ()
end
end
if strlen(this:GetText()) < 1 then return end
if strlen(this:GetText()) < 1 then
parent:UpdateScrollChildRect()
return
end
local i = 1
local search = strlower(this:GetText())
@@ -798,16 +802,9 @@ pfUI:RegisterModule("gui", function ()
end
end
-- reload scroll frames
scroll:Hide()
scroll:SetHeight(i * 25 )
scroll:Show()
parent:SetScrollChild(scroll)
QueueFunction(function()
parent:SetVerticalScroll(0)
parent:UpdateScrollState()
parent:Scroll()
end)
-- measure the new results and start at the top
parent:UpdateScrollChildRect()
parent:SetVerticalScroll(0)
end)
pfUI.gui.search:SetScript("OnEditFocusGained", function(self)