ProgressBarView¶
-
class
mono::ui::
ProgressBarView
¶ A UI widget displaying a common progress bar.
This progressbar is simply a rectangle with a line (progress indicator) inside. The indicator value is (by default) a value between 0 and 100, but you can set your own minimum and maximum points.
The progress value’s minimum and maximum is automtically calculated into the correct pixel value, scaled to the pixel width of the progressbar.
Example
// Create the progressbar object mono::ui::ProgressBarView prgs(mono::geo::Rect(10,10,156,100)); // set the progressbars indicator value to 50% prgs.setValue(50); // display it prgs.show();
A common mistake
Be aware that the progressbar is painted asynchronously. This means you cannot increment its value inside a for-loop or alike.
This code will not work:
for (int i=0; i<100; i++) { prgs.setValue(i); }
Even if the loop ran veeery slow, you will not see a moving progress indicator. The reason is that the view is only painted in the run-loop, so no screen updates can happen from inside the for-loop!
You should use a continous timer, with a callback that increments the progress indicator:
void updateProgress(){ prgs.setValue(i++); } mono::Timer tim(500); tim.setCallback(&updateProgress);
This code inject a continous task to the run loop that can increment the progressbar. This is the correct way to animate a progressbar.
Inherits from mono::ui::View
Public Functions
-
ProgressBarView
()¶ Create a ProgressBar with a zero view rect (0,0,0,0)
-
ProgressBarView
(geo::Rect rect)¶ Create a ProgressBarView with values from 0 to 100.
Create a new ProgressBarView, with a defined view rect and default progress value span: 0 to 100, with a current value of 0.
- Parameters
rect
-The view rect where the ProgressBar is painted
-
void
setValue
(int newValue)¶ Set a new progress value.
Set a new current value for the progress bar. The value is truncated to the existing value span (min and max values).
Changes to the value will trigger the value changed callback and cause the view to schedule itself for repaint.
- Parameters
newValue
-The new value
-
void
setMaximum
(int max)¶ Define a new minimum value for the progress indicator.
SETTERS.
-
void
setMinimum
(int min)¶ define a new maximum value for the progress indicator
- template <typename Owner>
-
void mono::ui::ProgressBarView::setValueChangedCallback(Owner * cnxt, void(Owner::*)(void) memPtr)
Set a progress value change callback function.
Get notification callback everytime this progressbar changes its value
- Parameters
cnxt
-A pointer to the callback member context (the
this
pointer)memPtr
-A pointer to the callback member function
-
int
Minimum
() const¶ GETTERS.
-
int
Maximum
() const¶ GETTERS.
-