# HG changeset patch # User Olaf Wintermann # Date 1696613890 -7200 # Node ID 4a258d47f9641f1bcd3ca309a280c84fd6845c71 # Parent 0e94be3d97227556d784e152740dccdae24fc561 add breadcrumb bar diff -r 0e94be3d9722 -r 4a258d47f964 make/vs/testapp/main.c --- a/make/vs/testapp/main.c Thu Oct 05 18:50:42 2023 +0200 +++ b/make/vs/testapp/main.c Fri Oct 06 19:38:10 2023 +0200 @@ -45,6 +45,7 @@ UiString* t2; UiString* t3; UiList* list2; + UiList* list3; } WindowData; void action1(UiEvent* event, void* data) { @@ -123,6 +124,11 @@ } +void action_breadcrumb(UiEvent* event, void* data) { + int i = event->intval; + printf("index: %d\n", i); +} + void application_startup(UiEvent* event, void* data) { UiObject* obj = ui_window("Test", NULL); WindowData* wdata = ui_malloc(obj->ctx, sizeof(WindowData)); @@ -134,6 +140,7 @@ wdata->password = ui_string_new(obj->ctx, "password"); wdata->list = ui_list_new(obj->ctx, "list"); wdata->list2 = ui_list_new(obj->ctx, "list2"); + wdata->list3 = ui_list_new(obj->ctx, "list3"); wdata->t1 = ui_string_new(obj->ctx, "t1"); wdata->t2 = ui_string_new(obj->ctx, "t2"); wdata->t3 = ui_string_new(obj->ctx, "t3"); @@ -145,6 +152,12 @@ ui_list_append(wdata->list, "Item5"); ui_list_append(wdata->list, "Item6"); + ui_list_append(wdata->list3, "usr"); + ui_list_append(wdata->list3, "share"); + ui_list_append(wdata->list3, "test"); + ui_list_append(wdata->list3, "dir"); + + TableData* td1 = malloc(sizeof(TableData)); TableData* td2 = malloc(sizeof(TableData)); TableData* td3 = malloc(sizeof(TableData)); @@ -190,6 +203,9 @@ ui_switch(obj, .label = "test", .onchange = action_switch); ui_newline(obj); + ui_breadcrumbbar(obj, .list = wdata->list3, .onactivate=action_breadcrumb); + ui_newline(obj); + ui_textfield(obj, .value = wdata->text); ui_passwordfield(obj, .value = wdata->password); ui_newline(obj); diff -r 0e94be3d9722 -r 4a258d47f964 ui/ui/tree.h --- a/ui/ui/tree.h Thu Oct 05 18:50:42 2023 +0200 +++ b/ui/ui/tree.h Fri Oct 06 19:38:10 2023 +0200 @@ -134,27 +134,19 @@ #define ui_listview(obj, ...) ui_listview_create(obj, (UiListArgs) { __VA_ARGS__ } ) #define ui_table(obj, ...) ui_table_create(obj, (UiListArgs) { __VA_ARGS__ } ) #define ui_combobox(obj, ...) ui_combobox_create(obj, (UiListArgs) { __VA_ARGS__ } ) +#define ui_breadcrumbbar(obj, ...) ui_breadcrumbbar_create(obj, (UiListArgs) { __VA_ARGS__ } ) UIEXPORT UIWIDGET ui_listview_create(UiObject* obj, UiListArgs args); UIEXPORT UIWIDGET ui_table_create(UiObject* obj, UiListArgs args); -UIEXPORT UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs); +UIEXPORT UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args); +UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args); -UIWIDGET ui_listview_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata); -UIWIDGET ui_listview_str_deprecated(UiObject *obj, UiList *list, ui_callback f, void *udata); -UIWIDGET ui_listview_nv_deprecated(UiObject *obj, char *listname, ui_getvaluefunc getvalue, ui_callback f, void *udata); - -UIWIDGET ui_table_deprecated(UiObject *obj, UiList *data, UiModel *model, UiListCallbacks cb); -UIWIDGET ui_table_nv_deprecated(UiObject *obj, char *varname, UiModel *model, UiListCallbacks cb); void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...); void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...); void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); -UIWIDGET ui_combobox_deprecated(UiObject *obj, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata); -UIWIDGET ui_combobox_str_deprecated(UiObject *obj, UiList *list, ui_callback f, void *udata); -UIWIDGET ui_combobox_nv_deprecated(UiObject *obj, char *varname, ui_getvaluefunc getvalue, ui_callback f, void *udata); - #ifdef __cplusplus } #endif diff -r 0e94be3d9722 -r 4a258d47f964 ui/winui/list.cpp --- a/ui/winui/list.cpp Thu Oct 05 18:50:42 2023 +0200 +++ b/ui/winui/list.cpp Fri Oct 06 19:38:10 2023 +0200 @@ -165,6 +165,49 @@ return widget; } +UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { + UiObject* current = uic_current_obj(obj); + + // create listview and toolkit wrapper + BreadcrumbBar bcbar = BreadcrumbBar(); + + UIElement elm = bcbar; + UiWidget* widget = new UiWidget(elm); + widget->data1 = args.model; + widget->data2 = args.getvalue; + ui_context_add_widget_destructor(current->ctx, widget); + + // bind var + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); + if (var) { + UiList* list = (UiList*)var->value; + list->update = ui_breadcrumbbar_update; + list->obj = widget; + ui_breadcrumbbar_update(list, 0); + } + + if (args.onactivate) { + ui_callback cb = args.onactivate; + void* cbdata = args.onactivatedata; + bcbar.ItemClicked([cb, cbdata, obj](IInspectable const& sender, BreadcrumbBarItemClickedEventArgs evtargs) { + UiEvent evt; + evt.obj = obj; + evt.window = obj->window; + evt.document = obj->ctx->document; + evt.eventdata = nullptr; + evt.intval = evtargs.Index(); + cb(&evt, cbdata); + }); + } + + // add listview to current container + UI_APPLY_LAYOUT1(current, args); + + current->container->Add(bcbar, false); + + return widget; +} + static void* getstrvalue(void* elm, int ignore) { return elm; } @@ -198,6 +241,37 @@ } } +extern "C" void ui_breadcrumbbar_update(UiList * list, int i) { + UiWidget* widget = (UiWidget*)list->obj; + UiModel* model = (UiModel*)widget->data1; + ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2; + + // priority: getvalue, model.getvalue, getstrvalue (fallback) + if (getvalue == nullptr) { + if (model && model->getvalue) { + getvalue = model->getvalue; + } + else { + getvalue = getstrvalue; + } + } + + BreadcrumbBar bar = widget->uielement.as(); + + Windows::Foundation::Collections::IVector items { winrt::single_threaded_vector() }; + void* elm = list->first(list); + while (elm) { + char* value = (char*)getvalue(elm, 0); + wchar_t* wstr = str2wstr(value, nullptr); + items.Append(box_value(wstr)); + free(wstr); + + elm = list->next(list); + } + + bar.ItemsSource(items); +} + std::vector ui_create_listview_selection(ListView listview) { std::vector selection; int p = 0; diff -r 0e94be3d9722 -r 4a258d47f964 ui/winui/list.h --- a/ui/winui/list.h Thu Oct 05 18:50:42 2023 +0200 +++ b/ui/winui/list.h Fri Oct 06 19:38:10 2023 +0200 @@ -35,5 +35,7 @@ extern "C" void ui_simple_list_update(UiList * list, int i); +extern "C" void ui_breadcrumbbar_update(UiList * list, int i); + std::vector ui_create_listview_selection(winrt::Microsoft::UI::Xaml::Controls::ListView listview);