Introduction
This class is a progress bar that allows you to automatically split up a large job into small chunks, so the client won't freeze for a long time while performing it. You specify a target frame rate (e.g. 10 FPS) and a work function (
workFunc). The amount of work requested (
workToDo) is adjusted automatically up and down to achieve the desired frame rate.
How to Use
When instantiating the
ProgressBar class, you supply a work function (
workFunc) and a target frame rate (
targetFrameRate). At each frame update, your work function is called with a single integer argument:
workToDo. This is the number of iterations of your "work" (whatever that may be) that you should complete before returning. Your function should then return a number between 0 and 1 indicating the total progress completed so far. (After your function returns 1, it will not be called again.)
Based on the amount of time elapsed, the
workToDo argument will be adjusted up or down, and
workFunc will be called again. (
workToDo will always be at least 1.)
Displaying the progress bar is optional; to do so, call
SetParent() to add it to a window. You can set the position and size as usual. To modify the appearance, see ProgressBar.lua; it is quite simple to understand and customize.
If you would like notifications when the progress bar updates, you may register a
ProgressChanged event handler.
Example plugin included. See the source code for more details.
Revision History- Version 1.00 (31-Mar-2022): Initial release.