--- 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<BreadcrumbBar>(); + + Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable> items { winrt::single_threaded_vector<Windows::Foundation::IInspectable>() }; + 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<int> ui_create_listview_selection(ListView listview) { std::vector<int> selection; int p = 0;