From 560cca5bc990dc413cd50ba5f759a0771dede206 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 15 Jun 2016 21:51:08 +0200 Subject: [PATCH] Adds uiProgressBar(Set)Indeterminate for unix --- test/page13.c | 13 +++++++++++++ ui.h | 2 +- unix/progressbar.c | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/page13.c b/test/page13.c index 0f3f358c..7908b780 100644 --- a/test/page13.c +++ b/test/page13.c @@ -75,6 +75,12 @@ static void showHide(uiButton *b, void *data) uiControlShow(c); } +static void setIndeterminate(uiButton *b, void *data) +{ + uiProgressBar *p = uiProgressBar(data); + uiProgressBarSetIndeterminate(p, !uiProgressBarIndeterminate(p)); +} + static void deleteFirst(uiButton *b, void *data) { uiForm *f = uiForm(data); @@ -89,6 +95,7 @@ uiBox *makePage13(void) uiButton *b; uiForm *f; uiEntry *e; + uiProgressBar *p; page13 = newVerticalBox(); @@ -123,6 +130,12 @@ uiBox *makePage13(void) 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"); uiButtonOnClicked(b, showHide, e); uiBoxAppend(page13, uiControl(b), 0); diff --git a/ui.h b/ui.h index 0131fe0d..42370453 100644 --- a/ui.h +++ b/ui.h @@ -190,7 +190,7 @@ typedef struct uiProgressBar uiProgressBar; _UI_EXTERN int uiProgressBarValue(uiProgressBar *p); _UI_EXTERN void uiProgressBarSetValue(uiProgressBar *p, int n); _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); typedef struct uiSeparator uiSeparator; diff --git a/unix/progressbar.c b/unix/progressbar.c index 725a6f5f..4d502f34 100644 --- a/unix/progressbar.c +++ b/unix/progressbar.c @@ -5,6 +5,7 @@ struct uiProgressBar { uiUnixControl c; GtkWidget *widget; GtkProgressBar *pbar; + int indeterminate; }; uiUnixControlAllDefaults(uiProgressBar) @@ -21,6 +22,28 @@ void uiProgressBarSetValue(uiProgressBar *p, int value) 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 *p;