Mon, 26 Feb 2024 21:37:56 +0100
add spinner (GTK)
ui/gtk/display.c | file | annotate | diff | comparison | revisions | |
ui/gtk/display.h | file | annotate | diff | comparison | revisions | |
ui/gtk/entry.h | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/display.c Sun Feb 25 21:57:49 2024 +0100 +++ b/ui/gtk/display.c Mon Feb 26 21:37:56 2024 +0100 @@ -148,3 +148,42 @@ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(d->obj), value); d->value = value; } + + +/* ------------------------- progress spinner ------------------------- */ + +UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) { + UiObject* current = uic_current_obj(obj); + + GtkWidget *spinner = gtk_spinner_new(); + + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); + if(var && var->value) { + UiInteger *value = var->value; + value->get = ui_spinner_get; + value->set = ui_spinner_set; + value->obj = spinner; + ui_spinner_set(value, value->value); + } + + UI_APPLY_LAYOUT1(current, args); + current->container->add(current->container, spinner, FALSE); + + return spinner; +} + +int64_t ui_spinner_get(UiInteger *i) { + return i->value; +} + +void ui_spinner_set(UiInteger *i, int64_t value) { + i->value = value; + if(i->obj) { + GtkSpinner *spinner = GTK_SPINNER(i->obj); + if(value != 0) { + gtk_spinner_start(spinner); + } else { + gtk_spinner_stop(spinner); + } + } +}
--- a/ui/gtk/display.h Sun Feb 25 21:57:49 2024 +0100 +++ b/ui/gtk/display.h Mon Feb 26 21:37:56 2024 +0100 @@ -42,6 +42,8 @@ UIWIDGET ui_progressbar_var(UiObject *obj, UiVar *var); double ui_progressbar_get(UiDouble *d); void ui_progressbar_set(UiDouble *d, double value); +int64_t ui_spinner_get(UiInteger *i); +void ui_spinner_set(UiInteger *i, int64_t value); #ifdef __cplusplus }
--- a/ui/gtk/entry.h Sun Feb 25 21:57:49 2024 +0100 +++ b/ui/gtk/entry.h Mon Feb 26 21:37:56 2024 +0100 @@ -22,7 +22,6 @@ extern "C" { #endif -UIWIDGET ui_spinner_var(UiObject *obj, double step, int digits, UiVar *var, UiVarType type); void ui_spinner_changed(GtkSpinButton *spinner, UiVarEventData *event); int64_t ui_spinbutton_getint(UiInteger *i);