Adds uiProgressBar(Set)Indeterminate for unix

This commit is contained in:
emersion 2016-06-15 21:51:08 +02:00
parent e07a7b3d05
commit 560cca5bc9
3 changed files with 37 additions and 1 deletions

View File

@ -75,6 +75,12 @@ static void showHide(uiButton *b, void *data)
uiControlShow(c); uiControlShow(c);
} }
static void setIndeterminate(uiButton *b, void *data)
{
uiProgressBar *p = uiProgressBar(data);
uiProgressBarSetIndeterminate(p, !uiProgressBarIndeterminate(p));
}
static void deleteFirst(uiButton *b, void *data) static void deleteFirst(uiButton *b, void *data)
{ {
uiForm *f = uiForm(data); uiForm *f = uiForm(data);
@ -89,6 +95,7 @@ uiBox *makePage13(void)
uiButton *b; uiButton *b;
uiForm *f; uiForm *f;
uiEntry *e; uiEntry *e;
uiProgressBar *p;
page13 = newVerticalBox(); page13 = newVerticalBox();
@ -123,6 +130,12 @@ uiBox *makePage13(void)
uiFormAppend(f, "MLE", uiControl(uiNewMultilineEntry()), 1); uiFormAppend(f, "MLE", uiControl(uiNewMultilineEntry()), 1);
p = uiNewProgressBar();
uiBoxAppend(page13, uiControl(p), 0);
b = uiNewButton("Toggle indeterminate");
uiButtonOnClicked(b, setIndeterminate, p);
uiBoxAppend(page13, uiControl(b), 0);
b = uiNewButton("Show/Hide"); b = uiNewButton("Show/Hide");
uiButtonOnClicked(b, showHide, e); uiButtonOnClicked(b, showHide, e);
uiBoxAppend(page13, uiControl(b), 0); uiBoxAppend(page13, uiControl(b), 0);

2
ui.h
View File

@ -190,7 +190,7 @@ typedef struct uiProgressBar uiProgressBar;
_UI_EXTERN int uiProgressBarValue(uiProgressBar *p); _UI_EXTERN int uiProgressBarValue(uiProgressBar *p);
_UI_EXTERN void uiProgressBarSetValue(uiProgressBar *p, int n); _UI_EXTERN void uiProgressBarSetValue(uiProgressBar *p, int n);
_UI_EXTERN int uiProgressBarIndeterminate(uiProgressBar *p); _UI_EXTERN int uiProgressBarIndeterminate(uiProgressBar *p);
_UI_EXTERN void uiProgressBarSetindeterminate(uiProgressBar *p, int indeterminate); _UI_EXTERN void uiProgressBarSetIndeterminate(uiProgressBar *p, int indeterminate);
_UI_EXTERN uiProgressBar *uiNewProgressBar(void); _UI_EXTERN uiProgressBar *uiNewProgressBar(void);
typedef struct uiSeparator uiSeparator; typedef struct uiSeparator uiSeparator;

View File

@ -5,6 +5,7 @@ struct uiProgressBar {
uiUnixControl c; uiUnixControl c;
GtkWidget *widget; GtkWidget *widget;
GtkProgressBar *pbar; GtkProgressBar *pbar;
int indeterminate;
}; };
uiUnixControlAllDefaults(uiProgressBar) uiUnixControlAllDefaults(uiProgressBar)
@ -21,6 +22,28 @@ void uiProgressBarSetValue(uiProgressBar *p, int value)
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100); gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
} }
int uiProgressBarIndeterminate(uiProgressBar *p)
{
return p->indeterminate;
}
gboolean uiProgressBarPulse(uiProgressBar *p)
{
if (!GTK_IS_WIDGET(p->pbar) || !p->indeterminate)
return 0;
gtk_progress_bar_pulse(p->pbar);
return 1;
}
void uiProgressBarSetIndeterminate(uiProgressBar *p, int indeterminate)
{
p->indeterminate = indeterminate;
if (indeterminate)
g_timeout_add(100, uiProgressBarPulse, p);
}
uiProgressBar *uiNewProgressBar(void) uiProgressBar *uiNewProgressBar(void)
{ {
uiProgressBar *p; uiProgressBar *p;