ui/winui/list.cpp

branch
newapi
changeset 197
8a82ebe23822
parent 196
320d85f3cd14
child 204
4a258d47f964
--- 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<ComboBox>().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<ListView>();
+    ItemsControl listview = widget->uielement.as<ItemsControl>();
     auto items = listview.Items();
 
     // priority: getvalue, model.getvalue, getstrvalue (fallback)

mercurial