add function for creating windows without menu/toolbar (WinUI3) newapi

Tue, 06 Feb 2024 10:09:10 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 06 Feb 2024 10:09:10 +0100
branch
newapi
changeset 244
33c0a3797a0d
parent 243
9f66c31a27ed
child 245
06e655d15b17

add function for creating windows without menu/toolbar (WinUI3)

ui/ui/window.h file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- a/ui/ui/window.h	Thu Feb 01 19:45:17 2024 +0100
+++ b/ui/ui/window.h	Tue Feb 06 10:09:10 2024 +0100
@@ -40,7 +40,7 @@
 #define UI_FILEDIALOG_SELECT_FOLDER       2
 
 UIEXPORT UiObject* ui_window(const char *title, void *window_data);
-UIEXPORT UiObject* ui_simplewindow(char *title, void *window_data);
+UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data);
 
 UIEXPORT void ui_window_size(UiObject *obj, int width, int height);
 
--- a/ui/winui/window.cpp	Thu Feb 01 19:45:17 2024 +0100
+++ b/ui/winui/window.cpp	Tue Feb 06 10:09:10 2024 +0100
@@ -58,50 +58,7 @@
 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));
-
-	obj->ctx = uic_context(obj, mp);
-	obj->window = window_data;
-
-	Window window = Window();
-	//Window window = make<winui::implementation::MainWindow>();
-
-	winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" };
-	Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested);
-
-	window.ExtendsContentIntoTitleBar(true);
-
-	Grid grid = Grid();
-	window.Content(grid);
-
-	StackPanel titleBar = StackPanel();
-	Thickness titleBarPadding = { 10, 5, 5, 10 };
-	titleBar.Padding(titleBarPadding);
-	titleBar.Orientation(Orientation::Horizontal);
-	TextBlock titleLabel = TextBlock();
-	titleBar.Children().Append(titleLabel);
-
-	if (title) {
-		wchar_t* wtitle = str2wstr(title, nullptr);
-		window.Title(wtitle);
-		titleLabel.Text(hstring(wtitle));
-		free(wtitle);
-	}
-
-	window.SetTitleBar(titleBar);
-
-	obj->wobj = new UiWindow(window);
-	ui_context_add_window_destructor(obj->ctx, obj->wobj);
-
-	window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
-		cxMempoolDestroy(obj->ctx->mp);
-	});
-
-	obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);
-
-	titleBar.VerticalAlignment(VerticalAlignment::Top);
-	obj->container->Add(titleBar, false);
+	UiObject* obj = ui_simple_window(title, window_data);
 
 	if (uic_get_menu_list()) {
 		// create/add menubar
@@ -173,6 +130,55 @@
 		obj->container->Add(toolbar_grid, false);
 	}
 
+	return obj;
+}
+
+UIEXPORT UiObject* ui_simple_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);
+	obj->window = window_data;
+
+	Window window = Window();
+	//Window window = make<winui::implementation::MainWindow>();
+
+	winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" };
+	Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested);
+
+	window.ExtendsContentIntoTitleBar(true);
+
+	Grid grid = Grid();
+	window.Content(grid);
+
+	StackPanel titleBar = StackPanel();
+	Thickness titleBarPadding = { 10, 5, 5, 10 };
+	titleBar.Padding(titleBarPadding);
+	titleBar.Orientation(Orientation::Horizontal);
+	TextBlock titleLabel = TextBlock();
+	titleBar.Children().Append(titleLabel);
+
+	if (title) {
+		wchar_t* wtitle = str2wstr(title, nullptr);
+		window.Title(wtitle);
+		titleLabel.Text(hstring(wtitle));
+		free(wtitle);
+	}
+
+	window.SetTitleBar(titleBar);
+
+	obj->wobj = new UiWindow(window);
+	ui_context_add_window_destructor(obj->ctx, obj->wobj);
+
+	window.Closed([obj](IInspectable const& sender, WindowEventArgs) {
+		cxMempoolDestroy(obj->ctx->mp);
+		});
+
+	obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);
+
+	titleBar.VerticalAlignment(VerticalAlignment::Top);
+	obj->container->Add(titleBar, false);
+
 	obj->window = window_data;
 
 	return obj;

mercurial