This application is a thorough example of the progress bar widget, consisting of a window with various progress bars, each with a given look/style one can give to those widgets.

With two auxiliary buttons, one can start or stop a timer which will fill in the bars in synchrony, simulating an underlying task being completed.

We create {\bfseries seven} progress bars, being three of them horizontal, three vertical and a final one under the \char`\"{}wheel\char`\"{} alternate style.

For the first one, we add a progress bar on total pristine state, with no other call than the \hyperlink{group__Progressbar_ga73ec06c9c8eb7e5f0263a132432e8cc3}{elm\+\_\+progressbar\+\_\+add()} one\+:  
\begin{DoxyCodeInclude}
   \textcolor{comment}{/* pb with no label, default unit label and no icon */}
   pb = elm_progressbar_add(win);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   elm\_box\_pack\_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb1 = pb;

\end{DoxyCodeInclude}
 See, than, that the defaults of a progress bar are\+:
\begin{DoxyItemize}
\item no primary label shown,
\item unit label set to {\ttfamily \char`\"{}\%.\+0f \%\%\char`\"{}},
\item no icon set
\end{DoxyItemize}

The second progress bar is given a primary label, {\ttfamily \char`\"{}\+Infinite
bounce\char`\"{}}, and, besides, it\textquotesingle{}s set to {\bfseries pulse}. See how, after one starts the progress timer, with the \char`\"{}\+Start\char`\"{} button, it animates differently than the previous one. It won\textquotesingle{}t account for the progress, itself, and just dumbly animate a small bar within its bar region.  
\begin{DoxyCodeInclude}
   \textcolor{comment}{/* pb with label, and set to pulse */}
   pb = elm_progressbar_add(win);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Infinite bounce"});
   elm\_progressbar\_pulse\_set(pb, EINA\_TRUE);
   elm\_box\_pack\_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb2 = pb;

\end{DoxyCodeInclude}


Next, comes a progress bar with an {\bfseries icon}, a primary label and a unit label {\bfseries function} set. It\textquotesingle{}s also made to grow its bar in an {\bfseries inverted} manner, so check that out during the timer\textquotesingle{}s progression\+:  
\begin{DoxyCodeInclude}
   ic1 = elm_icon_add(win);
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/images/logo\_small.png"}, elm_app_data_dir_get());
   elm_image_file_set(ic1, buf, NULL);
   evas\_object\_size\_hint\_aspect\_set(ic1, EVAS\_ASPECT\_CONTROL\_VERTICAL, 1, 1);

   \textcolor{comment}{/* pb with label, icon, custom unit label function and span size set */}
   pb = elm_progressbar_add(win);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Label"});
   elm_object_part_content_set(pb, \textcolor{stringliteral}{"icon"}, ic1);
   elm\_progressbar\_inverted\_set(pb, EINA\_TRUE);
   elm\_progressbar\_unit\_format\_function\_set(pb, \_progress\_format\_cb,
                                            \_progress\_format\_free);
   elm\_progressbar\_span\_size\_set(pb, 200);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_box\_pack\_end(bx, pb);
   evas\_object\_show(ic1);
   evas\_object\_show(pb);
   example\_data.pb3 = pb;

\end{DoxyCodeInclude}
 Another important thing in this one is the call to elm\+\_\+progressbar\+\_\+span\+\_\+size\+\_\+set() -- this is how we forcefully set a minimum horizontal size to our whole window! We\textquotesingle{}re not resizing it manually, as you can see in the \hyperlink{progressbar_example_c}{complete code}.

The format callback is a simple function that gets passed the progress value and returns a string. A free function should be provided as well, if the format callback allocates memory.  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* Format callback */}
\textcolor{keyword}{static} \textcolor{keywordtype}{char} *
\_progress\_format\_cb(\textcolor{keywordtype}{double} val)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{char} buf[30];
   \textcolor{keywordtype}{int} files = (1-val)*14000;
   \textcolor{keywordflow}{if} (snprintf(buf, 30, \textcolor{stringliteral}{"%i files left"}, files) > 0)
     \textcolor{keywordflow}{return} strdup(buf);
   \textcolor{keywordflow}{return} NULL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progress\_format\_free(\textcolor{keywordtype}{char} *str)
\{
   free(str);
\}

\end{DoxyCodeInclude}


The last horizontal progress bar has a callback that gets called when its value is {\bfseries changed}. This callback updates a label to provide an estimate when the operation finishes.  
\begin{DoxyCodeInclude}
   \textcolor{comment}{/* pb with label and changed trigger  */}
   pb = elm_progressbar_add(win);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Label"});
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_box\_pack\_end(bx, pb);
   evas\_object\_show(pb);

   label = elm_label_add(win);
   elm\_object\_text\_set(label, \textcolor{stringliteral}{"ETA: N/A"});
   evas\_object\_size\_hint\_align\_set(label, 0.5, 0.5);
   evas\_object\_size\_hint\_weight\_set(label, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_box\_pack\_end(bx, label);
   evas\_object\_show(label);

   evas\_object\_smart\_callback\_add(pb, \textcolor{stringliteral}{"changed"}, \_on\_changed, label);
   example\_data.pb4 = pb;

\end{DoxyCodeInclude}


The \char`\"{}changed\char`\"{} signal is emitted every time the progressbar value is updated through elm\+\_\+progressbar\+\_\+value\+\_\+set(). This callback calculates and displays the E\+T\+A based on the progress and time that has passed.  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* Callback for "changed" signal */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_on\_changed(\textcolor{keywordtype}{void}        *data,
            Evas\_Object *obj,
            \textcolor{keywordtype}{void}        *event\_info)
\{
   \textcolor{keyword}{static} \textcolor{keywordtype}{char} buf[30];
   \textcolor{keyword}{static} time\_t tstart = 0;
   \textcolor{keyword}{static} \textcolor{keywordtype}{double} eta = 0;
   time\_t tdiff;
   \textcolor{keywordtype}{double} val;
   Evas\_Object *label =  (Evas\_Object *)data;

   val = elm\_progressbar\_value\_get(obj);
   \textcolor{keywordflow}{if} (val == 0)
     \{
        tstart = 0;
        elm\_object\_text\_set(label, \textcolor{stringliteral}{"ETA: N/A"});
        \textcolor{keywordflow}{return};
     \}

   \textcolor{comment}{/* First invocation */}
   \textcolor{keywordflow}{if} (tstart == 0)
     \{
        tstart = time(NULL);
     \}

   \textcolor{comment}{/* Calculate ETA and update */}
   tdiff = time(NULL) - tstart;
   eta = 0.3*eta + 0.7*(tdiff/val)*(1-val);
   snprintf(buf, 30, \textcolor{stringliteral}{"ETA: %.0fs"}, eta);
   elm\_object\_text\_set(label, buf);
\}

\end{DoxyCodeInclude}


The next three progress bars are just variants on the ones already shown, but now all being {\bfseries vertical}. Another time we use one of than to give the window a minimum vertical size, with elm\+\_\+progressbar\+\_\+span\+\_\+size\+\_\+set(). To demonstrate this trick once more, the fifth one, which is also set to pulse, has a smaller hardcoded span size\+:  
\begin{DoxyCodeInclude}
   \textcolor{comment}{/* vertical pb, with pulse and custom (small) span size */}
   pb = elm_progressbar_add(win);
   elm\_progressbar\_horizontal\_set(pb, EINA\_FALSE);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_progressbar\_span\_size\_set(pb, 80);
   elm\_progressbar\_pulse\_set(pb, EINA\_TRUE);
   elm\_progressbar\_unit\_format\_set(pb, NULL);
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Infinite bounce"});
   elm\_box\_pack\_end(hbx, pb);
   evas\_object\_show(pb);
   example\_data.pb6 = pb;

\end{DoxyCodeInclude}


We end the widget demonstration by showing a progress bar with the special {\bfseries \char`\"{}wheel\char`\"{}} progress bar style. One does {\bfseries not} need to set it to pulse, with elm\+\_\+progressbar\+\_\+pulse\+\_\+set(), explicitly, because its theme does not take it in account\+:  
\begin{DoxyCodeInclude}
   \textcolor{comment}{/* "wheel" style progress bar */}
   pb = elm_progressbar_add(win);
   elm_object_style_set(pb, \textcolor{stringliteral}{"wheel"});
   elm\_object\_text\_set(pb, \textcolor{stringliteral}{"Style: wheel"});
   elm\_progressbar\_pulse\_set(pb, EINA\_TRUE);
   evas\_object\_size\_hint\_align\_set(pb, EVAS\_HINT\_FILL, 0.5);
   evas\_object\_size\_hint\_weight\_set(pb, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm\_box\_pack\_end(bx, pb);
   evas\_object\_show(pb);
   example\_data.pb8 = pb;

\end{DoxyCodeInclude}


The two buttons exercising the bars, the facto, follow\+:  
\begin{DoxyCodeInclude}
   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Start"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_progressbar\_example\_start,
                                  NULL);
   elm\_box\_pack\_end(bt\_bx, bt);
   evas\_object\_show(bt);

   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Stop"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_progressbar\_example\_stop,
                                  NULL);
   elm\_box\_pack\_end(bt\_bx, bt);
   evas\_object\_show(bt);

\end{DoxyCodeInclude}


The first of the callbacks will, for the progress bars set to pulse, start the pulsing animation at that time. For the others, a timer callback will take care of updating the values\+:  
\begin{DoxyCodeInclude}
\textcolor{keyword}{static} Eina\_Bool
\_progressbar\_example\_value\_set(\textcolor{keywordtype}{void} *data)
\{
   \textcolor{keywordtype}{double} progress;

   progress = elm\_progressbar\_value\_get(example\_data.pb1);
   \textcolor{keywordflow}{if} (progress < 1.0) progress += 0.0123;
   \textcolor{keywordflow}{else} progress = 0.0;

   \textcolor{comment}{/* just the non-pulsing ones need an update */}
   elm\_progressbar\_value\_set(example\_data.pb1, progress);
   elm\_progressbar\_value\_set(example\_data.pb3, progress);
   elm\_progressbar\_value\_set(example\_data.pb4, progress);
   elm\_progressbar\_value\_set(example\_data.pb5, progress);
   elm\_progressbar\_value\_set(example\_data.pb7, progress);

   \textcolor{keywordflow}{if} (progress < 1.0) \textcolor{keywordflow}{return} ECORE\_CALLBACK\_RENEW;

   example\_data.run = 0;
   \textcolor{keywordflow}{return} ECORE\_CALLBACK\_CANCEL;
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progressbar\_example\_start(\textcolor{keywordtype}{void}        *data,
                           Evas\_Object *obj,
                           \textcolor{keywordtype}{void}        *event\_info)
\{
   elm\_progressbar\_pulse(example\_data.pb2, EINA\_TRUE);
   elm\_progressbar\_pulse(example\_data.pb6, EINA\_TRUE);
   elm\_progressbar\_pulse(example\_data.pb8, EINA\_TRUE);

   \textcolor{keywordflow}{if} (!example\_data.run)
     \{
        example\_data.timer = ecore\_timer\_add(
           0.1, \_progressbar\_example\_value\_set, NULL);
        example\_data.run = EINA\_TRUE;
     \}
\}

\end{DoxyCodeInclude}


Finally, the callback to stop the progress timer will stop the pulsing on the pulsing progress bars and, for the others, to delete the timer which was acting on their values\+:  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* end of show */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_progressbar\_example\_stop(\textcolor{keywordtype}{void}        *data,
                          Evas\_Object *obj,
                          \textcolor{keywordtype}{void}        *event\_info)
\{
   elm\_progressbar\_pulse(example\_data.pb2, EINA\_FALSE);
   elm\_progressbar\_pulse(example\_data.pb6, EINA\_FALSE);
   elm\_progressbar\_pulse(example\_data.pb8, EINA\_FALSE);

   \textcolor{keywordflow}{if} (example\_data.run)
     \{
        ecore\_timer\_del(example\_data.timer);
        example\_data.run = EINA\_FALSE;
     \}
\}

\end{DoxyCodeInclude}


This is how the example program\textquotesingle{}s window looks like\+:  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/progressbar_example}}
\end{DoxyImageNoCaption}


See the full \hyperlink{progressbar_example_c}{source code} for this example. 