packages feed

vty-ui-1.5: doc/ch4/ProgressBar.tex

\section{Progress Bars}
\label{sec:progress_bars}

The \fw{ProgressBar} module provides the \fw{ProgressBar} type which
you can use to indicate task progression in your applications.

\fw{ProgressBar}s can be created with the \fw{newProgressBar}
function.  The function takes two \fw{Attr} arguments indicating the
attributes to be used for the complete and incomplete portions of the
progress bar, respectively:

\begin{haskellcode}
 bar <- newProgressBar (blue `on` white) (white `on` blue)
\end{haskellcode}

\fw{ProgressBar}s take \fw{Attr} values because these widgets support
text labels.  You can set the label and its alignment as follows:

\begin{haskellcode}
 setProgressText bar "Working..."
 setProgressTextAlignment bar AlignCenter
\end{haskellcode}

\fw{ProgressBar}s can be laid out in your interface like any other
widget:

\begin{haskellcode}
 ui <- (plainText "Progress: ") <--> (return bar)
\end{haskellcode}

A \fw{ProgressBar} tracks progress as an \fw{Int} n ($0 \le n \le
100$).  To set a \fw{ProgressBar}'s progress value, use
\fw{setProgress} or \fw{addProgress}:

\begin{haskellcode}
 setProgress bar 35
 addProgress bar 1
\end{haskellcode}

Calls to \fw{setProgress} and \fw{addProgress} resulting in a progress
value outside the allowable range will have no effect.

To be notified when a \fw{ProgressBar}'s value changes, use the
\fw{onProgressChange} function.  Handlers for this event will receive
the new progress value:

\begin{haskellcode}
 bar `onProgressChange` \newVal -> ...
\end{haskellcode}

\fw{ProgressBar}s are best used with the \fw{schedule} function
described in Section \ref{sec:concurrency}.

\subsubsection{Growth Policy}

\fw{ProgressBar}s grow horizontally but do not grow vertically.