Replaces uiProgressBar(Set)Indeterminate() by value=-1

This commit is contained in:
emersion 2016-06-15 23:17:23 +02:00
parent 560cca5bc9
commit 983a53d3c3
3 changed files with 27 additions and 19 deletions

View File

@ -78,7 +78,15 @@ static void showHide(uiButton *b, void *data)
static void setIndeterminate(uiButton *b, void *data)
{
uiProgressBar *p = uiProgressBar(data);
uiProgressBarSetIndeterminate(p, !uiProgressBarIndeterminate(p));
int value = uiProgressBarValue(p);
if (value == -1) {
value = 0;
} else {
value = -1;
}
uiProgressBarSetValue(p, value);
}
static void deleteFirst(uiButton *b, void *data)

2
ui.h
View File

@ -189,8 +189,6 @@ typedef struct uiProgressBar uiProgressBar;
#define uiProgressBar(this) ((uiProgressBar *) (this))
_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 uiProgressBar *uiNewProgressBar(void);
typedef struct uiSeparator uiSeparator;

View File

@ -12,23 +12,16 @@ uiUnixControlAllDefaults(uiProgressBar)
int uiProgressBarValue(uiProgressBar *p)
{
if (p->indeterminate)
return -1;
return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
}
void uiProgressBarSetValue(uiProgressBar *p, int value)
gboolean uiProgressBarPulse(void* data)
{
if (value < 0 || value > 100)
userbug("Value %d is out of range for a uiProgressBar.", value);
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
}
uiProgressBar *p = (uiProgressBar*) data;
int uiProgressBarIndeterminate(uiProgressBar *p)
{
return p->indeterminate;
}
gboolean uiProgressBarPulse(uiProgressBar *p)
{
if (!GTK_IS_WIDGET(p->pbar) || !p->indeterminate)
return 0;
@ -36,12 +29,21 @@ gboolean uiProgressBarPulse(uiProgressBar *p)
return 1;
}
void uiProgressBarSetIndeterminate(uiProgressBar *p, int indeterminate)
void uiProgressBarSetValue(uiProgressBar *p, int value)
{
p->indeterminate = indeterminate;
if (value == -1) {
if (!p->indeterminate) {
p->indeterminate = 1;
g_timeout_add(100, uiProgressBarPulse, p);
}
return;
}
if (indeterminate)
g_timeout_add(100, uiProgressBarPulse, p);
if (value < 0 || value > 100)
userbug("Value %d is out of range for a uiProgressBar.", value);
p->indeterminate = 0;
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
}
uiProgressBar *uiNewProgressBar(void)