Progressbar
GWIN - Progressbar
A progressbar is a rectangular box to visualize the progression of a progress or an operation. The progressbar widget can either be controlled manually or automatically. In both cases, the range of the progressbar can be changed through the gwinProgressbarSetRange() call. The default values are 0 to 100. Furthermore, the resolution can be modified through gwinProgressbarSetResolution(). This changes the size of the steps in which the progressbar will be incremented or decremented. The default resolution is 1.
Manual There are two ways to change the value that a progressbar displays:
gwinProgressbarSetPosition() gwinProgressbarIncrease() and gwinProgressbarDecrease() You can also use them together and mix them up. Note that the increase and decrease call increment and decrement by the resolution that was set using gwinProgressbarSetResolution().
The following example shows how a progressbar is created and controlled manually. The range of the progressbar has not been modified and is therefore 0 to 100. The resolution has not been modified either and is therefore 1.
#include "gfx.h" GHandle ghProgressbar; static void _createWidget(void) { GWidgetInit wi; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; wi.g.show = TRUE; wi.g.y = 10; wi.g.x = 10; wi.g.width = 200; wi.g.height = 20; wi.text = "Progress 1"; ghProgressbar = gwinProgressbarCreate(NULL, &wi); } int main(void) { gfxInit(); gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); _createWidget(); // use any of these however you need them gwinProgressbarSetPosition(ghProgressbar, 42); gwinProgressbarIncrement(ghProgressbar); gwinProgressbarDecrement(ghProgressbar); while (1) { gfxSleepMilliseconds(500); } return 0; }
Automatic
Note: You have to set GWIN_PROGRESSBAR_AUTO to TRUE in your gfxconf.h to use this feature.
Using the gwinProgressbarStart() call, a progressbar can be automatically increased from its current to its maximum value. The GTIMER module is internally used for this purpose. No event is generated once the progressbar reached its maximum value.
The following example shows how a progressbar is created and controlled automatically. The range of the progressbar has not been modified and is therefore 0 to 100. The resolution is set to 10 and the timer interval to 500ms. Therefore it will take around 5 seconds until the progressbar reached its maximum value.
#include "gfx.h" GHandle ghProgressbar; static void _createWidget(void) { GWidgetInit wi; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; wi.g.show = TRUE; wi.g.y = 10; wi.g.x = 10; wi.g.width = 200; wi.g.height = 20; wi.text = "Progress 1"; ghProgressbar = gwinProgressbarCreate(NULL, &wi); } int main(void) { gfxInit(); gwinSetDefaultFont(gdispOpenFont("UI2")); gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); gdispClear(White); _createWidget(); gwinProgressbarSetResolution(ghProgressbar, 10); gwinProgressbarStart(ghProgressbar, 500); while (1) { gfxSleepMilliseconds(500); } return 0; }