Thread Tools Display Modes
04-22-24, 05:08 PM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 323
How to track the scroll position of a WowScrollBoxList

I would like my addon to keep track of the current scroll position of the achievements frame scroll box.
But the scroll box only seems to have an OnMouseWheel script.

Lua Code:
  1. AchievementFrameAchievements.ScrollBox:HookScript("OnMouseWheel", function(self)
  2.   print(AchievementFrameAchievements.ScrollBox.scrollPercentage)
  3. end)

The same goes for its scroll bar.

Lua Code:
  1. AchievementFrameAchievements.ScrollBar:HookScript("OnMouseWheel", function(self)
  2.   print(AchievementFrameAchievements.ScrollBox.scrollPercentage)
  3. end)

But what if the user changes the scroll position dragging the scroll bar or clicking the scroll bar steppers?
Are there scripts to hook as well?

Is there not an easier way? Like a scroll frames' OnVerticalScroll script?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
04-23-24, 06:16 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
I'm seeing more, but ultimately, all of .ScrollBox's scripts manipulate .ScrollBar, which fires an OnScroll event through its inherited CallbackRegistry. The event fires with the scroll percent, so you don't need to fetch it yourself.

Lua Code:
  1. local ScrollBar=AchievementFrameAchievements.ScrollBar;
  2. ScrollBar:RegisterCallback(ScrollBar.Event.OnScroll,function(_,scrollpercent)
  3.     print(scrollpercent);
  4. end);

Sources of note:
ScrollUtil.InitScrollFrameWithScrollBar() - SharedXML/Scroll/ScrollUtil.lua:197
ScrollBarMixin:SetScrollPercentage() & ScrollBarMixin:SetScrollPercentageInternal() - SharedXML/Scroll/ScrollBar.lua:163 & 180
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-23-24 at 06:55 AM.
  Reply With Quote
04-25-24, 04:43 PM   #3
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 323
Thank you so much! This worked perfectly.

Could you also tell me how to do this in Wrath Classic?
I tried this:

Lua Code:
  1. local ScrollBar = AchievementFrameAchievementsContainer.scrollBar
  2. ScrollBar:RegisterCallback(ScrollBar.Event.OnScroll, function(_,scrollpercent)
  3.   print(scrollpercent)
  4. end)

But AchievementFrameAchievementsContainer.scrollBar does not seem to have Event.


In general: What did you do to see all the scripts of the scroll bar/box?
Could you recommend a resource where I could learn about the details of CallbackRegistries?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
04-28-24, 02:53 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
Originally Posted by LudiusMaximus View Post
Could you also tell me how to do this in Wrath Classic?
Wrath Classic just has the OnValueChanged script on .scrollBar. The OnMouseWheel script on the scroll frame just calls :SetValue() on the bar, which triggers it.

Lua Code:
  1. AchievementFrameAchievementsContainer.ScrollBar:HookScript("OnValueChanged",function(self,value)
  2.     print(value);
  3. end);



Originally Posted by LudiusMaximus View Post
In general: What did you do to see all the scripts of the scroll bar/box?
Most of what I've done has been tweaking Blizzard code to add features or change how things worked. I've just had a lot of experience in reading Blizzard's UI source code to know where to look to find things. In this case, I looked for the initialization function(s) that are called on load that registers handling user interaction and follow the trail. It helps having an IDE that lets you search an entire directory tree for a keyword.



Originally Posted by LudiusMaximus View Post
Could you recommend a resource where I could learn about the details of CallbackRegistries?
I learned it from reading Blizzard's source code, but Warcraft Wiki has a page on it.
https://warcraft.wiki.gg/wiki/EventRegistry

Note: The linked page appears to be a merged topic on the EventRegistry (aka GlobalCallbackRegistry), but there is a section about the CallbackRegistryMixin.

If you want to see the relevant code yourself:
SharedXML/GlobalCallbackRegistry.lua
SharedXML/CallbackRegistry.lua
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-28-24 at 03:21 PM.
  Reply With Quote
04-28-24, 03:16 PM   #5
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 323
Great! Thanks again!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to track the scroll position of a WowScrollBoxList


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