ui/winui/window.cpp

branch
newapi
changeset 184
8c9b4b28aaa9
parent 183
3ce2eb11913b
child 187
24ce2c326d85
--- a/ui/winui/window.cpp	Fri Sep 22 21:32:45 2023 +0200
+++ b/ui/winui/window.cpp	Sat Sep 23 15:41:23 2023 +0200
@@ -39,6 +39,7 @@
 
 #include "appmenu.h"
 #include "container.h"
+#include "util.h"
 
 #include "../common/context.h"
 
@@ -54,6 +55,9 @@
 using namespace Windows::UI::Xaml::Interop;
 using namespace winrt::Windows::Foundation;
 
+UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {}
+
+
 UiObject* ui_window(const char* title, void* window_data) {
 	CxMempool* mp = cxBasicMempoolCreate(256);
 	UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject));
@@ -62,13 +66,22 @@
 	obj->window = window_data;
 
 	Window window = Window();
+	if (title) {
+		wchar_t *wtitle = str2wstr(title, nullptr);
+		window.Title(wtitle);
+		free(wtitle);
+	}
 
 	Grid grid = Grid();
 	window.Content(grid);
 
 	obj->wobj = new UiWindow(window);
+	
 
-	window.Closed([&](IInspectable const& sender, WindowEventArgs) { delete obj->wobj; } );
+	window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
+		// TODO: destroy UiObject*, context, ...
+		delete obj->wobj;
+	});
 
 	obj->container = new UiBoxContainer(grid, UI_CONTAINER_VBOX);
 
@@ -79,21 +92,7 @@
 		obj->container->Add(mb, false);
 	}
 
-	Button b1 = Button();
-	Button b2 = Button();
-
-	b1.Content(box_value(L"Button 1"));
-	b2.Content(box_value(L"Button 2"));
-
-	obj->container->Add(b1, false);
-	obj->container->Add(b2, false);
-
-
 	obj->window = window_data;
 
-	//wptr2->Activate();
-	//obj->wobj = wptr2;
-	
-
 	return obj;
 }

mercurial