Tue, 30 Jan 2024 13:10:16 +0100
add support for table string values, that need to be freed
ui/common/types.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/tree.h | file | annotate | diff | comparison | revisions | |
ui/ui/window.h | file | annotate | diff | comparison | revisions | |
ui/winui/pch.h | file | annotate | diff | comparison | revisions | |
ui/winui/table.cpp | file | annotate | diff | comparison | revisions | |
ui/winui/window.cpp | file | annotate | diff | comparison | revisions |
--- a/ui/common/types.c Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/common/types.c Tue Jan 30 13:10:16 2024 +0100 @@ -456,3 +456,13 @@ l->update = NULL; l->obj = NULL; } + + + +UiStr ui_str(char *cstr) { + return (UiStr) { cstr, NULL }; +} + +UiStr ui_str_free(char *str, void (*freefunc)(void *v)) { + return (UiStr) { str, freefunc }; +}
--- a/ui/ui/toolkit.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/toolkit.h Tue Jan 30 13:10:16 2024 +0100 @@ -474,6 +474,10 @@ UIEXPORT UiIcon* ui_foldericon(size_t size); UIEXPORT UiIcon* ui_fileicon(size_t size); + +UiStr ui_str(char *cstr); +UiStr ui_str_free(char *str, void (*free)(void *v)); + #ifdef __cplusplus } #endif
--- a/ui/ui/tree.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/tree.h Tue Jan 30 13:10:16 2024 +0100 @@ -44,9 +44,11 @@ typedef enum UiModelType { UI_STRING = 0, + UI_STRING_FREE, UI_INTEGER, UI_ICON, UI_ICON_TEXT, + UI_ICON_TEXT_FREE } UiModelType; struct UiModel { @@ -154,6 +156,7 @@ void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...); void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm); + #ifdef __cplusplus } #endif
--- a/ui/ui/window.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/ui/window.h Tue Jan 30 13:10:16 2024 +0100 @@ -38,6 +38,8 @@ UIEXPORT UiObject* ui_window(const char *title, void *window_data); UIEXPORT UiObject* ui_simplewindow(char *title, void *window_data); +UIEXPORT void ui_window_size(UiObject *obj, int width, int height); + char* ui_openfiledialog(UiObject *obj); char* ui_savefiledialog(UiObject *obj);
--- a/ui/winui/pch.h Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/pch.h Tue Jan 30 13:10:16 2024 +0100 @@ -15,6 +15,7 @@ #include <winrt/Windows.Foundation.Collections.h> #include <winrt/Windows.ApplicationModel.Activation.h> #include <winrt/Microsoft.UI.Composition.h> +#include <winrt/Microsoft.UI.Windowing.h> #include <winrt/Microsoft.UI.Xaml.h> #include <winrt/Microsoft.UI.Xaml.Controls.h> #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h> @@ -35,5 +36,4 @@ #include <winrt/Windows.ApplicationModel.h> #include <winrt\Microsoft.UI.Dispatching.h> - #include <winrt/Windows.Storage.Streams.h>
--- a/ui/winui/table.cpp Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/table.cpp Tue Jan 30 13:10:16 2024 +0100 @@ -410,12 +410,17 @@ // depending on the type, we create different cell controls UiModelType type = model->types[col]; switch (type) { + case UI_STRING_FREE: case UI_STRING: { TextBlock cell = TextBlock(); cell.Padding(cellpadding); cell.VerticalAlignment(VerticalAlignment::Stretch); - textblock_set_str(cell, (char*)getvalue(elm, model_col)); + char *val = (char*)getvalue(elm, model_col); + textblock_set_str(cell, val); cellBorder.Child(cell); + if (type == UI_STRING_FREE && val) { + free(val); + } break; } @@ -438,6 +443,7 @@ } break; } + case UI_ICON_TEXT_FREE: case UI_ICON_TEXT: { StackPanel cellPanel = StackPanel(); cellPanel.Spacing(2); @@ -455,6 +461,9 @@ textblock_set_str(cell, str); cellPanel.Children().Append(cell); cellBorder.Child(cellPanel); + if (type == UI_ICON_TEXT_FREE && str) { + free(str); + } break; } }
--- a/ui/winui/window.cpp Tue Jan 30 12:10:41 2024 +0100 +++ b/ui/winui/window.cpp Tue Jan 30 13:10:16 2024 +0100 @@ -175,3 +175,13 @@ return obj; } + +void ui_window_size(UiObject *obj, int width, int height) { + UIWINDOW win = obj->wobj; + if (win) { + winrt::Windows::Graphics::SizeInt32 wsize; + wsize.Width = width; + wsize.Height = height; + win->window.AppWindow().Resize(wsize); + } +}