# HG changeset patch # User Olaf Wintermann # Date 1685349443 -7200 # Node ID c52d88ea020b2de47228c7cbe1ed57da1759dcf2 # Parent f34953bf4ac7f2f25819215a60cd04121c558180 redefine UIWIDGET, remove widget abstraction class (WinUI) diff -r f34953bf4ac7 -r c52d88ea020b ui/ui/toolkit.h --- a/ui/ui/toolkit.h Tue May 23 14:19:06 2023 +0200 +++ b/ui/ui/toolkit.h Mon May 29 10:37:23 2023 +0200 @@ -68,10 +68,27 @@ #endif #elif UI_WINUI + +#ifdef __cplusplus +#include +#undef GetCurrentTime +#include +#include +#include + +#define UIWIDGET winrt::Microsoft::UI::Xaml::UIElement +#define UIWINDOW winrt::Microsoft::UI::Xaml::Window +#define UIMENU void* + +#else #define UIWIDGET void* +#define UIWINDOW void* #define UIMENU void* #endif + +#endif + #ifndef TRUE #define TRUE 1 #endif @@ -137,6 +154,13 @@ * native widget */ UIWIDGET widget; + +#ifdef UI_WINUI + /* + * native window object + */ + UIWINDOW wobj; +#endif /* * user window data diff -r f34953bf4ac7 -r c52d88ea020b ui/winui/toolkit.cpp --- a/ui/winui/toolkit.cpp Tue May 23 14:19:06 2023 +0200 +++ b/ui/winui/toolkit.cpp Mon May 29 10:37:23 2023 +0200 @@ -97,14 +97,6 @@ return application_name; } -UiContext* ui_global_context(void) { - return NULL; -} - -void ui_context_closefunc(UiContext* ctx, ui_callback fnc, void* udata) { - -} - void ui_onstartup(ui_callback f, void* userdata) { startup_func = f; startup_data = userdata; @@ -126,8 +118,11 @@ } void ui_show(UiObject* obj) { - UiWidget* w = (UiWidget*)obj->widget; - w->show(); + if (obj->wobj) { + obj->wobj.Activate(); + } else { + // ZODO + } } void ui_close(UiObject* obj) { diff -r f34953bf4ac7 -r c52d88ea020b ui/winui/toolkit.h --- a/ui/winui/toolkit.h Tue May 23 14:19:06 2023 +0200 +++ b/ui/winui/toolkit.h Mon May 29 10:37:23 2023 +0200 @@ -31,8 +31,3 @@ #define UIEXPORT extern "C" __declspec(dllexport) #include "../ui/toolkit.h" - -class UiWidget { -public: - virtual void show() {}; -}; \ No newline at end of file diff -r f34953bf4ac7 -r c52d88ea020b ui/winui/window.cpp --- a/ui/winui/window.cpp Tue May 23 14:19:06 2023 +0200 +++ b/ui/winui/window.cpp Mon May 29 10:37:23 2023 +0200 @@ -39,8 +39,12 @@ #include "appmenu.h" +#include "../common/context.h" + #include +#include + using namespace winrt; using namespace Microsoft::UI::Xaml; using namespace Microsoft::UI::Xaml::Controls; @@ -49,34 +53,26 @@ using namespace Windows::UI::Xaml::Interop; -class UiWindow : UiWidget { -public: - UiWindow(const char* title, UiObject *obj) { - window = Window(); + + +UiObject* ui_window(const char* title, void* window_data) { + CxMempool* mp = cxBasicMempoolCreate(256); + UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); + + obj->ctx = uic_context(obj, mp->allocator); + obj->window = window_data; - grid = Grid(); - window.Content(grid); + obj->wobj = Window(); + Grid grid = Grid(); + obj->wobj.Content(grid); - if (uic_get_menu_list()) { - MenuBar mb = ui_create_menubar(obj); - mb.VerticalAlignment(VerticalAlignment::Top); - grid.Children().Append(mb); - } + if (uic_get_menu_list()) { + MenuBar mb = ui_create_menubar(obj); + mb.VerticalAlignment(VerticalAlignment::Top); + grid.Children().Append(mb); } - virtual void show() { - window.Activate(); - } - - Window window{ nullptr }; - Grid grid; -}; - -UiObject* ui_window(const char* title, void* window_data) { - UiObject* obj = (UiObject*)malloc(sizeof(UiObject)); - - UiWindow* window = new UiWindow(title, obj); - obj->widget = window; + obj->window = window_data; return obj; }