ui/winui/list.cpp

branch
newapi
changeset 378
d41b1ffc5f77
parent 225
097f45f9c1fa
--- a/ui/winui/list.cpp	Sun Nov 10 10:16:47 2024 +0100
+++ b/ui/winui/list.cpp	Sun Nov 10 15:27:44 2024 +0100
@@ -70,7 +70,10 @@
     if (var) {
         UiList* list = (UiList*)var->value;
         list->update = ui_simple_list_update;
+        list->getselection = ui_listview_getselection;
+        list->setselection = ui_listview_setselection;
         list->obj = widget;
+
         ui_simple_list_update(list, 0);
     }
 
@@ -138,6 +141,8 @@
     if (var) {
         UiList* list = (UiList*)var->value;
         list->update = ui_simple_list_update;
+        list->getselection = ui_dropdown_getselection;
+        list->setselection = ui_dropdown_setselection;
         list->obj = widget;
         ui_simple_list_update(list, 0);
     }
@@ -169,6 +174,51 @@
     return widget;
 }
 
+UiListSelection ui_listview_getselection(UiList *list) {
+    UiWidget *widget = (UiWidget*)list->obj;
+    ListView listview = widget->uielement.as<ListView>();
+    std::vector<int> selectedRows = ui_create_listview_selection(listview);
+
+    UiListSelection selection = { NULL, 0 };
+    if (selectedRows.size() > 0) {
+        selection.count = selectedRows.size();
+        int *data = selectedRows.data();
+        selection.rows = (int*)calloc(selection.count, sizeof(int));
+        memcpy(selection.rows, data, selection.count);
+    }
+
+    return selection;
+}
+
+void ui_listview_setselection(UiList *list, UiListSelection selection) {
+    UiWidget* widget = (UiWidget*)list->obj;
+    if (selection.count > 0) {
+        ListView listview = widget->uielement.as<ListView>();
+        listview.SelectedIndex(selection.rows[0]);
+    }
+}
+
+UiListSelection ui_dropdown_getselection(UiList *list) {
+    UiWidget* widget = (UiWidget*)list->obj;
+    ComboBox cb = widget->uielement.as<ComboBox>();
+    int index = cb.SelectedIndex();
+    UiListSelection selection = { NULL, 0 };
+    if (index >= 0) {
+        selection.rows = (int*)calloc(1, sizeof(int));
+        selection.count = 1;
+        selection.rows[0] = index;
+    }
+    return selection;
+}
+
+void ui_dropdown_setselection(UiList *list, UiListSelection selection) {
+    UiWidget* widget = (UiWidget*)list->obj;
+    if (selection.count > 0) {
+        ComboBox cb = widget->uielement.as<ComboBox>();
+        cb.SelectedIndex(selection.rows[0]);
+    }
+}
+
 UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) {
     UiObject* current = uic_current_obj(obj);
 

mercurial