WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to track the scroll position of a WowScrollBoxList (https://www.wowinterface.com/forums/showthread.php?t=59858)

LudiusMaximus 04-22-24 05:08 PM

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?

SDPhantom 04-23-24 06:16 AM

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

LudiusMaximus 04-25-24 04:43 PM

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?

SDPhantom 04-28-24 02:53 PM

Quote:

Originally Posted by LudiusMaximus (Post 343789)
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);



Quote:

Originally Posted by LudiusMaximus (Post 343789)
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.



Quote:

Originally Posted by LudiusMaximus (Post 343789)
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

LudiusMaximus 04-28-24 03:16 PM

Great! Thanks again! :)


All times are GMT -6. The time now is 03:24 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI