Sat, 13 Dec 2025 12:37:41 +0100
add support for static elements in the listview/dropdown (Win32)
| application/main.c | file | annotate | diff | comparison | revisions | |
| ui/common/properties.c | file | annotate | diff | comparison | revisions | |
| ui/win32/list.c | file | annotate | diff | comparison | revisions | |
| ui/win32/window.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sat Dec 13 12:19:55 2025 +0100 +++ b/application/main.c Sat Dec 13 12:37:41 2025 +0100 @@ -1254,7 +1254,14 @@ //UiModel *model = ui_model(obj->ctx, UI_STRING, "Name", UI_STRING, "Email", -1); //ui_table(obj, .fill = TRUE, .varname = "persons", .model = model, .getvalue = person_getvalue, .onselection = list_onselection); //ui_model_free(obj->ctx, model); - ui_dropdown(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection, .hexpand = TRUE, .hfill = TRUE); + //ui_dropdown(obj, .varname = "persons", .getvalue = person_getvalue, .onactivate = list_onselection, .hexpand = TRUE, .hfill = TRUE); + char *list[] = { + "test 1", + "test 2", + "test 3", + "test 4" + }; + ui_dropdown(obj, .static_elements = list, .static_nelm = 4); ui_button(obj, .label = "Test 1"); ui_newline(obj);
--- a/ui/common/properties.c Sat Dec 13 12:19:55 2025 +0100 +++ b/ui/common/properties.c Sat Dec 13 12:37:41 2025 +0100 @@ -234,7 +234,7 @@ // try creating the parent int err = ui_mkdir(parent); if(err) { - fprintf(stderr, "Error: Cannot create directory %s: %s\n", strerror(errno)); + fprintf(stderr, "Error: Cannot create directory %s: %s\n", parent, strerror(errno)); free(parent); free(dir); return; @@ -290,7 +290,7 @@ int ret = 0; CxMapIterator i = cxMapIterator(application_properties); cx_foreach(CxMapEntry *, entry, i) { - fprintf(file, "%.*s = %s\n", (int)entry->key->len, entry->key->data, entry->value); + fprintf(file, "%.*s = %s\n", (int)entry->key->len, (char*)entry->key->data, (char*)entry->value); } cxMapRehash(application_properties);
--- a/ui/win32/list.c Sat Dec 13 12:19:55 2025 +0100 +++ b/ui/win32/list.c Sat Dec 13 12:37:41 2025 +0100 @@ -170,6 +170,19 @@ list->setselection = ui_listview_setselection; ui_listview_update(list, -1); + } else if (!table && args->static_elements && args->static_nelm > 0) { + char **static_elements = args->static_elements; + size_t static_nelm = args->static_nelm; + LVITEM item; + item.mask = LVIF_TEXT; + item.iSubItem = 0; + for (int i=0;i<static_nelm;i++) { + item.iItem = i; + item.pszText = static_elements[i]; + ListView_InsertItem(hwnd, &item); + } + listview->getvalue = strmodel_getvalue; + listview->getvaluedata = NULL; } return (W32Widget*)listview; @@ -387,9 +400,16 @@ list->setselection = ui_dropdown_setselection; ui_dropdown_update(list, -1); + } else if (args->static_elements && args->static_nelm > 0) { + char **static_elements = args->static_elements; + size_t static_nelm = args->static_nelm; + for (int i=0;i<static_nelm;i++) { + SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)static_elements[i]); + } + dropdown->getvalue = strmodel_getvalue; + dropdown->getvaluedata = NULL; } - return (W32Widget*)dropdown; }
--- a/ui/win32/window.c Sat Dec 13 12:19:55 2025 +0100 +++ b/ui/win32/window.c Sat Dec 13 12:37:41 2025 +0100 @@ -111,11 +111,11 @@ } UiObject *ui_window(const char *title) { - return create_window(title, window_data, FALSE); + return create_window(title, FALSE); } UiObject *ui_simple_window(const char *title) { - return create_window(title, window_data, TRUE); + return create_window(title, TRUE); } int ui_window_widget_event(W32Widget *widget, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {