libui/unix/progressbar.c

58 lines
1.1 KiB
C
Raw Normal View History

2015-06-11 18:07:06 -05:00
// 11 june 2015
#include "uipriv_unix.h"
2015-08-27 22:00:34 -05:00
struct uiProgressBar {
uiUnixControl c;
2015-06-11 18:07:06 -05:00
GtkWidget *widget;
2015-06-27 18:46:11 -05:00
GtkProgressBar *pbar;
int indeterminate;
2015-06-11 18:07:06 -05:00
};
uiUnixControlAllDefaults(uiProgressBar)
2015-06-11 18:07:06 -05:00
2016-06-15 11:51:12 -05:00
int uiProgressBarValue(uiProgressBar *p)
{
return (int) (gtk_progress_bar_get_fraction(p->pbar) * 100);
}
2015-08-27 22:00:34 -05:00
void uiProgressBarSetValue(uiProgressBar *p, int value)
2015-06-11 18:07:06 -05:00
{
if (value < 0 || value > 100)
2016-05-13 20:00:12 -05:00
userbug("Value %d is out of range for a uiProgressBar.", value);
gtk_progress_bar_set_fraction(p->pbar, ((gdouble) value) / 100);
2015-06-11 18:07:06 -05:00
}
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);
}
2015-06-11 18:07:06 -05:00
uiProgressBar *uiNewProgressBar(void)
{
2015-08-27 22:00:34 -05:00
uiProgressBar *p;
2015-06-11 18:07:06 -05:00
uiUnixNewControl(uiProgressBar, p);
2015-06-11 18:07:06 -05:00
2015-06-27 18:46:11 -05:00
p->widget = gtk_progress_bar_new();
p->pbar = GTK_PROGRESS_BAR(p->widget);
2015-06-11 18:07:06 -05:00
2015-08-27 22:00:34 -05:00
return p;
2015-06-11 18:07:06 -05:00
}