Difference between revisions of "Progressbar"

From uGFX Wiki
Jump to: navigation, search
m
(API reference)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
== API reference ==
 
== API reference ==
The API reference of the progressbar can be found [http://ugfx.org/images/resources/doxygen/master/group___progressbar.html here].
+
The API reference of the progressbar can be found [http://api.ugfx.org/group___progressbar.html here].
  
 
== Custom Draw Routines ==
 
== Custom Draw Routines ==

Latest revision as of 15:48, 4 February 2016

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.

API reference

The API reference of the progressbar can be found here.

Custom Draw Routines

The slider widget predefines a number of custom draw routines. They can be set using gwinSetCustomDraw() or by specifying the custom draw routine in the GWidgetInit structure during creation. The predefined custom draw routines are:

Custom Draw Routine Description
gwinProgressbarDraw_Std The standard progress bar look.
gwinProgressbarDraw_Image The parameter is an open gdispImage that is tiled to fill the active part of the progress bar.

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().

Example

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.

Example

#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;
}