Difference between revisions of "Progressbar"

From uGFX Wiki
Jump to: navigation, search
(Created page with "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...")
 
Line 1: Line 1:
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 <code>gwinProgressbarSetRange()</code> call. The default values are 0 to 100. Furthermore, the resolution can be modified through <code>gwinProgressbarSetResolution()</code>. This changes the size of the steps in which the progressbar will be incremented or decremented. The default resolution is 1.
  
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 ==
 
+
Manual
+
 
There are two ways to change the value that a progressbar displays:
 
There are two ways to change the value that a progressbar displays:
  
gwinProgressbarSetPosition()
+
* <code>gwinProgressbarSetPosition()</code>
gwinProgressbarIncrease() and gwinProgressbarDecrease()
+
* <code>gwinProgressbarIncrease()</code> and <code>gwinProgressbarDecrease()</code>
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().
+
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 <code>gwinProgressbarSetResolution()</code>.
  
 +
=== 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.
 
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.
 
<syntaxhighlight lang=c>
 
<syntaxhighlight lang=c>
Line 53: Line 51:
 
   
 
   
  
Automatic
+
== Automatic ==
Note: You have to set GWIN_PROGRESSBAR_AUTO to TRUE in your gfxconf.h to use this feature.
+
'''''Note:''' You have to set <code>GWIN_PROGRESSBAR_AUTO</code> 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.
+
Using the <code>gwinProgressbarStart()</code> 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.
 
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 ===
 
<syntaxhighlight lang=c>
 
<syntaxhighlight lang=c>
 
#include "gfx.h"
 
#include "gfx.h"

Revision as of 18:48, 1 July 2014

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

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