Tue, 17 Oct 2023 21:50:48 +0200
add progressbar (WinUI3)
make/vs/testapp/main.c | file | annotate | diff | comparison | revisions | |
ui/ui/display.h | file | annotate | diff | comparison | revisions | |
ui/winui/label.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/label.h | file | annotate | diff | comparison | revisions |
--- a/make/vs/testapp/main.c Tue Oct 17 21:00:48 2023 +0200 +++ b/make/vs/testapp/main.c Tue Oct 17 21:50:48 2023 +0200 @@ -46,6 +46,7 @@ UiString* t3; UiList* list2; UiList* list3; + UiDouble* progress; } WindowData; static UiIcon* folder_icon; @@ -58,6 +59,9 @@ int64_t radio = wdata->radio->get(wdata->radio); printf("data: %s %d\n", data, is_checked); + + double d = wdata->progress->get(wdata->progress); + wdata->progress->set(wdata->progress, d + 1); } void action_set_checkbox(UiEvent* event, void* data) { @@ -150,6 +154,7 @@ wdata->t1 = ui_string_new(obj->ctx, "t1"); wdata->t2 = ui_string_new(obj->ctx, "t2"); wdata->t3 = ui_string_new(obj->ctx, "t3"); + wdata->progress = ui_double_new(obj->ctx, "progress"); ui_list_append(wdata->list, "Hello"); ui_list_append(wdata->list, "World"); @@ -262,6 +267,7 @@ ui_newline(obj); ui_label(obj, .label = "Test Label"); + ui_progressbar(obj, .value = wdata->progress, .colspan = 2); ui_newline(obj); ui_newline(obj);
--- a/ui/ui/display.h Tue Oct 17 21:00:48 2023 +0200 +++ b/ui/ui/display.h Tue Oct 17 21:50:48 2023 +0200 @@ -54,7 +54,6 @@ UiBool vexpand; int colspan; int rowspan; - int width; const char* label; UiAlignment align; @@ -62,6 +61,20 @@ const char* varname; } UiLabelArgs; +typedef struct UiProgressbarArgs { + UiTri fill; + UiBool hexpand; + UiBool vexpand; + int colspan; + int rowspan; + int width; + + double min; + double max; + UiDouble* value; + const char* varname; +} UiProgressbarArgs; + /* label widgets */ #define ui_label(obj, ...) ui_label_create(obj, (UiLabelArgs) { __VA_ARGS__ }) @@ -73,16 +86,14 @@ UIEXPORT UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args); UIEXPORT UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args); -UIWIDGET ui_label_deprecated(UiObject *obj, char *label); -UIWIDGET ui_llabel_deprecated(UiObject *obj, char *label); -UIWIDGET ui_rlabel_deprecated(UiObject *obj, char *label); - UIWIDGET ui_space(UiObject *obj); UIWIDGET ui_separator(UiObject *obj); /* progress bar */ -UIWIDGET ui_progressbar(UiObject *obj, UiDouble *value); -UIWIDGET ui_progressbar_nv(UiObject *obj, char *varname); + +#define ui_progressbar(obj, ...) ui_progressbar_create(obj, (UiProgressbarArgs) { __VA_ARGS__ } ) + +UIEXPORT UIWIDGET ui_progressbar_create(UiObject *obj, UiProgressbarArgs args); #ifdef __cplusplus
--- a/ui/winui/label.cpp Tue Oct 17 21:00:48 2023 +0200 +++ b/ui/winui/label.cpp Tue Oct 17 21:50:48 2023 +0200 @@ -70,7 +70,7 @@ // TODO: } - // add button to current container + // add label to current container UI_APPLY_LAYOUT1(current, args); current->container->Add(label, false); @@ -102,3 +102,54 @@ TextBox box = widget->uielement.as<TextBox>(); box.Text(ui_string_set(str, newvalue)); } + + +// -------------------- progressbar ------------------------- + +UIWIDGET ui_progressbar_create(UiObject* obj, UiProgressbarArgs args) { + UiObject* current = uic_current_obj(obj); + + // create textbox and toolkit wrapper + ProgressBar progressbar = ProgressBar(); + progressbar.Minimum(args.min); + progressbar.Maximum(args.max == 0 ? 100 : args.max); + if (args.width > 0) { + progressbar.Width(args.width); + } + + UIElement elm = progressbar; + UiWidget* widget = new UiWidget(elm); + ui_context_add_widget_destructor(current->ctx, widget); + + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_DOUBLE); + if (var) { + UiDouble* value = (UiDouble*)var->value; + value->obj = widget; + value->get = ui_progressbar_get; + value->set = ui_progressbar_set; + + // listener for notifying observers + // TODO: + } + + // add button to current container + UI_APPLY_LAYOUT1(current, args); + + current->container->Add(progressbar, false); + + return widget; +} + +double ui_progressbar_get(UiDouble * d) { + UiWidget* widget = (UiWidget*)d->obj; + ProgressBar progressbar = widget->uielement.as<ProgressBar>(); + d->value = progressbar.Value(); + return d->value; +} + +void ui_progressbar_set(UiDouble * d, double newvalue) { + UiWidget* widget = (UiWidget*)d->obj; + ProgressBar progressbar = widget->uielement.as<ProgressBar>(); + d->value = newvalue; + progressbar.Value(newvalue); +}
--- a/ui/winui/label.h Tue Oct 17 21:00:48 2023 +0200 +++ b/ui/winui/label.h Tue Oct 17 21:50:48 2023 +0200 @@ -33,4 +33,7 @@ #include "../ui/display.h" extern "C" char* ui_label_get(UiString * str); -extern "C" void ui_label_set(UiString * str, const char* newvalue); \ No newline at end of file +extern "C" void ui_label_set(UiString * str, const char* newvalue); + +extern "C" double ui_progressbar_get(UiDouble *d); +extern "C" void ui_progressbar_set(UiDouble *d, double newvalue);