56 using namespace winrt::Windows::Storage::Pickers; |
56 using namespace winrt::Windows::Storage::Pickers; |
57 |
57 |
58 UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {} |
58 UiWindow::UiWindow(winrt::Microsoft::UI::Xaml::Window& win) : window(win) {} |
59 |
59 |
60 UiObject* ui_window(const char* title, void* window_data) { |
60 UiObject* ui_window(const char* title, void* window_data) { |
61 CxMempool* mp = cxBasicMempoolCreate(256); |
61 UiObject* obj = ui_simple_window(title, window_data); |
62 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
|
63 |
|
64 obj->ctx = uic_context(obj, mp); |
|
65 obj->window = window_data; |
|
66 |
|
67 Window window = Window(); |
|
68 //Window window = make<winui::implementation::MainWindow>(); |
|
69 |
|
70 winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" }; |
|
71 Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested); |
|
72 |
|
73 window.ExtendsContentIntoTitleBar(true); |
|
74 |
|
75 Grid grid = Grid(); |
|
76 window.Content(grid); |
|
77 |
|
78 StackPanel titleBar = StackPanel(); |
|
79 Thickness titleBarPadding = { 10, 5, 5, 10 }; |
|
80 titleBar.Padding(titleBarPadding); |
|
81 titleBar.Orientation(Orientation::Horizontal); |
|
82 TextBlock titleLabel = TextBlock(); |
|
83 titleBar.Children().Append(titleLabel); |
|
84 |
|
85 if (title) { |
|
86 wchar_t* wtitle = str2wstr(title, nullptr); |
|
87 window.Title(wtitle); |
|
88 titleLabel.Text(hstring(wtitle)); |
|
89 free(wtitle); |
|
90 } |
|
91 |
|
92 window.SetTitleBar(titleBar); |
|
93 |
|
94 obj->wobj = new UiWindow(window); |
|
95 ui_context_add_window_destructor(obj->ctx, obj->wobj); |
|
96 |
|
97 window.Closed([obj](IInspectable const& sender, WindowEventArgs) { |
|
98 cxMempoolDestroy(obj->ctx->mp); |
|
99 }); |
|
100 |
|
101 obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0); |
|
102 |
|
103 titleBar.VerticalAlignment(VerticalAlignment::Top); |
|
104 obj->container->Add(titleBar, false); |
|
105 |
62 |
106 if (uic_get_menu_list()) { |
63 if (uic_get_menu_list()) { |
107 // create/add menubar |
64 // create/add menubar |
108 MenuBar mb = ui_create_menubar(obj); |
65 MenuBar mb = ui_create_menubar(obj); |
109 mb.VerticalAlignment(VerticalAlignment::Top); |
66 mb.VerticalAlignment(VerticalAlignment::Top); |
171 |
128 |
172 toolbar_grid.VerticalAlignment(VerticalAlignment::Top); |
129 toolbar_grid.VerticalAlignment(VerticalAlignment::Top); |
173 obj->container->Add(toolbar_grid, false); |
130 obj->container->Add(toolbar_grid, false); |
174 } |
131 } |
175 |
132 |
|
133 return obj; |
|
134 } |
|
135 |
|
136 UIEXPORT UiObject* ui_simple_window(const char *title, void *window_data) { |
|
137 CxMempool* mp = cxBasicMempoolCreate(256); |
|
138 UiObject* obj = (UiObject*)cxCalloc(mp->allocator, 1, sizeof(UiObject)); |
|
139 |
|
140 obj->ctx = uic_context(obj, mp); |
|
141 obj->window = window_data; |
|
142 |
|
143 Window window = Window(); |
|
144 //Window window = make<winui::implementation::MainWindow>(); |
|
145 |
|
146 winrt::Windows::Foundation::Uri resourceLocator{ L"ms-appx:///MainWindow.xaml" }; |
|
147 Application::LoadComponent(window, resourceLocator, ComponentResourceLocation::Nested); |
|
148 |
|
149 window.ExtendsContentIntoTitleBar(true); |
|
150 |
|
151 Grid grid = Grid(); |
|
152 window.Content(grid); |
|
153 |
|
154 StackPanel titleBar = StackPanel(); |
|
155 Thickness titleBarPadding = { 10, 5, 5, 10 }; |
|
156 titleBar.Padding(titleBarPadding); |
|
157 titleBar.Orientation(Orientation::Horizontal); |
|
158 TextBlock titleLabel = TextBlock(); |
|
159 titleBar.Children().Append(titleLabel); |
|
160 |
|
161 if (title) { |
|
162 wchar_t* wtitle = str2wstr(title, nullptr); |
|
163 window.Title(wtitle); |
|
164 titleLabel.Text(hstring(wtitle)); |
|
165 free(wtitle); |
|
166 } |
|
167 |
|
168 window.SetTitleBar(titleBar); |
|
169 |
|
170 obj->wobj = new UiWindow(window); |
|
171 ui_context_add_window_destructor(obj->ctx, obj->wobj); |
|
172 |
|
173 window.Closed([obj](IInspectable const& sender, WindowEventArgs) { |
|
174 cxMempoolDestroy(obj->ctx->mp); |
|
175 }); |
|
176 |
|
177 obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0); |
|
178 |
|
179 titleBar.VerticalAlignment(VerticalAlignment::Top); |
|
180 obj->container->Add(titleBar, false); |
|
181 |
176 obj->window = window_data; |
182 obj->window = window_data; |
177 |
183 |
178 return obj; |
184 return obj; |
179 } |
185 } |
180 |
186 |