# HG changeset patch # User Olaf Wintermann # Date 1708979876 -3600 # Node ID 1a30bf64cb225a2e50a5f9090e0fc9793cef01c2 # Parent 94d44bdcad3e36ee321a1f2fdbbf3895793d92e7 add spinner (GTK) diff -r 94d44bdcad3e -r 1a30bf64cb22 ui/gtk/display.c --- 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); + } + } +} diff -r 94d44bdcad3e -r 1a30bf64cb22 ui/gtk/display.h --- 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 } diff -r 94d44bdcad3e -r 1a30bf64cb22 ui/gtk/entry.h --- 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);