# HG changeset patch # User Olaf Wintermann # Date 1695411165 -7200 # Node ID 3ce2eb11913bbd2230afdc64b7039a4f555caaf9 # Parent 6cf690e042bd7b3cbdc4b35e7a7b43e101a78e82 create WinUI wrapper classes for usage in UiObject and widget creation functions diff -r 6cf690e042bd -r 3ce2eb11913b ui/ui/toolkit.h --- a/ui/ui/toolkit.h Mon May 29 12:48:42 2023 +0200 +++ b/ui/ui/toolkit.h Fri Sep 22 21:32:45 2023 +0200 @@ -70,16 +70,39 @@ #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 +class UiWindow { +public: + winrt::Microsoft::UI::Xaml::Window window { nullptr }; + + UiWindow(winrt::Microsoft::UI::Xaml::Window& win); +}; + +class UiWidget { +public: + winrt::Microsoft::UI::Xaml::UIElement uielement; + + UiWidget(winrt::Microsoft::UI::Xaml::UIElement& elm); +}; + +#define UIWIDGET UiWidget* +#define UIWINDOW UiWindow* #define UIMENU void* +/* +// winrt::Microsoft::UI::Xaml::UIElement +#define UIWIDGET void* +// winrt::Microsoft::UI::Xaml::Window +#define UIWINDOW void* +#define UIMENU void* +*/ + #else #define UIWIDGET void* #define UIWINDOW void* diff -r 6cf690e042bd -r 3ce2eb11913b ui/winui/toolkit.cpp --- a/ui/winui/toolkit.cpp Mon May 29 12:48:42 2023 +0200 +++ b/ui/winui/toolkit.cpp Fri Sep 22 21:32:45 2023 +0200 @@ -87,6 +87,11 @@ XamlControlsXamlMetaDataProvider provider; }; +UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {}; + +UiWidget::UiWidget(winrt::Microsoft::UI::Xaml::UIElement& elm) : uielement(elm) {} + + void ui_init(const char* appname, int argc, char** argv) { @@ -117,11 +122,16 @@ Application::Start([](auto&&) {make(); }); } +class UiWin { +public: + Window window; +}; + void ui_show(UiObject* obj) { if (obj->wobj) { - obj->wobj.Activate(); + obj->wobj->window.Activate(); } else { - // ZODO + // TODO } } diff -r 6cf690e042bd -r 3ce2eb11913b ui/winui/window.cpp --- a/ui/winui/window.cpp Mon May 29 12:48:42 2023 +0200 +++ b/ui/winui/window.cpp Fri Sep 22 21:32:45 2023 +0200 @@ -52,9 +52,7 @@ using namespace Microsoft::UI::Xaml::XamlTypeInfo; using namespace Microsoft::UI::Xaml::Markup; using namespace Windows::UI::Xaml::Interop; - - - +using namespace winrt::Windows::Foundation; UiObject* ui_window(const char* title, void* window_data) { CxMempool* mp = cxBasicMempoolCreate(256); @@ -63,9 +61,14 @@ obj->ctx = uic_context(obj, mp->allocator); obj->window = window_data; - obj->wobj = Window(); + Window window = Window(); + Grid grid = Grid(); - obj->wobj.Content(grid); + window.Content(grid); + + obj->wobj = new UiWindow(window); + + window.Closed([&](IInspectable const& sender, WindowEventArgs) { delete obj->wobj; } ); obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX); @@ -87,6 +90,9 @@ obj->window = window_data; + + //wptr2->Activate(); + //obj->wobj = wptr2; return obj; diff -r 6cf690e042bd -r 3ce2eb11913b ui/winui/winui.vcxproj --- a/ui/winui/winui.vcxproj Mon May 29 12:48:42 2023 +0200 +++ b/ui/winui/winui.vcxproj Fri Sep 22 21:32:45 2023 +0200 @@ -119,6 +119,7 @@ NotUsing + toolkit.h Console