# HG changeset patch # User Olaf Wintermann # Date 1696269378 -7200 # Node ID 8a82ebe23822ee2d449a8f8f94fd0528f67cb19f # Parent 320d85f3cd1488e04062ae51a4f13e63a6b15e1e add combobox (WinUI3) diff -r 320d85f3cd14 -r 8a82ebe23822 make/vs/testapp/main.c --- a/make/vs/testapp/main.c Mon Oct 02 19:31:06 2023 +0200 +++ b/make/vs/testapp/main.c Mon Oct 02 19:56:18 2023 +0200 @@ -149,7 +149,7 @@ } */ - ui_listview(obj, .list = wdata->list, .hexpand = true, .vexpand = true, .multiselection = true, .onselection= action_listselection_changed, .onactivate= action_onactivate); + ui_combobox(obj, .list = wdata->list, .onselection= action_listselection_changed, .onactivate= action_onactivate); } } diff -r 320d85f3cd14 -r 8a82ebe23822 ui/winui/list.cpp --- a/ui/winui/list.cpp Mon Oct 02 19:31:06 2023 +0200 +++ b/ui/winui/list.cpp Mon Oct 02 19:56:18 2023 +0200 @@ -116,6 +116,55 @@ return widget; } + +UIWIDGET ui_combobox_create(UiObject* obj, UiListArgs args) { + UiObject* current = uic_current_obj(obj); + + // create listview and toolkit wrapper + ComboBox combobox = ComboBox(); + + UIElement elm = combobox; + 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_simple_list_update; + list->obj = widget; + ui_simple_list_update(list, 0); + } + + if (args.onactivate) { + ui_callback cb = args.onactivate; + void* cbdata = args.onactivatedata; + combobox.SelectionChanged([cb, cbdata, obj](IInspectable const& sender, RoutedEventArgs evtargs) { + int selectedrow = sender.as().SelectedIndex(); + UiListSelection selection; + selection.count = 1; + selection.rows = &selectedrow; + + UiEvent evt; + evt.obj = obj; + evt.window = obj->window; + evt.document = obj->ctx->document; + evt.eventdata = &selection; + evt.intval = selectedrow; + cb(&evt, cbdata); + }); + } + + // add listview to current container + UI_APPLY_LAYOUT1(current, args); + + current->container->Add(combobox, false); + + return widget; +} + static void* getstrvalue(void* elm, int ignore) { return elm; } @@ -124,7 +173,7 @@ UiWidget* widget = (UiWidget*)list->obj; UiModel* model = (UiModel*)widget->data1; ui_getvaluefunc getvalue = (ui_getvaluefunc)widget->data2; - ListView listview = widget->uielement.as(); + ItemsControl listview = widget->uielement.as(); auto items = listview.Items(); // priority: getvalue, model.getvalue, getstrvalue (fallback)