ui/winui/container.cpp

branch
newapi
changeset 193
74c688cc1839
parent 190
70fd1b24e395
child 194
e2281ace0769
equal deleted inserted replaced
192:bcacd00ea955 193:74c688cc1839
29 #include "container.h" 29 #include "container.h"
30 30
31 #include "../common/context.h" 31 #include "../common/context.h"
32 #include "../common/object.h" 32 #include "../common/object.h"
33 33
34 #include "util.h"
35
36 #include <winrt/Windows.UI.Xaml.Media.h>
37 #include <winrt/Microsoft.UI.Xaml.Media.h>
38
34 39
35 void ui_container_begin_close(UiObject* obj) { 40 void ui_container_begin_close(UiObject* obj) {
36 UiContainer* ct = uic_get_current_container(obj); 41 UiContainer* ct = uic_get_current_container(obj);
37 ct->close = 1; 42 ct->close = 1;
38 } 43 }
75 } 80 }
76 81
77 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) { 82 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) {
78 this->grid = grid; 83 this->grid = grid;
79 this->type = type; 84 this->type = type;
85
86 Thickness t = { (double)margin, (double)margin, (double)margin, (double)margin };
87 grid.Margin(t);
88 grid.ColumnSpacing((double)spacing);
89 grid.RowSpacing((double)spacing);
80 90
81 GridLength gl; 91 GridLength gl;
82 gl.Value = 1; 92 gl.Value = 1;
83 gl.GridUnitType = GridUnitType::Star; 93 gl.GridUnitType = GridUnitType::Star;
84 94
226 x++; 236 x++;
227 237
228 ui_reset_layout(layout); 238 ui_reset_layout(layout);
229 } 239 }
230 240
241 // --------------------- UiFrameContainer ---------------------
242
243 UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args) {
244 // create a grid for the frame, that contains the label and a sub-frame
245 Grid frame = Grid();
246
247 GridLength gl;
248 gl.GridUnitType = GridUnitType::Star;
249 gl.Value = 1;
250
251 ColumnDefinition coldef = ColumnDefinition();
252 coldef.Width(gl);
253 frame.ColumnDefinitions().Append(coldef);
254
255 RowDefinition rowdefFrame = RowDefinition();
256 rowdefFrame.Height(gl);
257
258 // label
259 int row = 0;
260 if (args.label) {
261 RowDefinition rowdefLabel = RowDefinition();
262 gl.GridUnitType = GridUnitType::Auto;
263 gl.Value = 0;
264 rowdefLabel.Height(gl);
265 frame.RowDefinitions().Append(rowdefLabel);
266
267 TextBlock label = TextBlock();
268 wchar_t* wlabel = str2wstr(args.label, nullptr);
269 winrt::hstring hstr(wlabel);
270 label.Text(hstr);
271 free(wlabel);
272
273 frame.SetRow(label, row++);
274 frame.SetColumn(label, 0);
275 frame.Children().Append(label);
276 }
277
278 // workarea frame
279 frame.RowDefinitions().Append(rowdefFrame);
280
281 Grid workarea = Grid();
282 frame.SetRow(workarea, row);
283 frame.SetColumn(workarea, 0);
284 frame.Children().Append(workarea);
285
286 // some styling for the workarea
287 winrt::Microsoft::UI::Xaml::Media::SolidColorBrush brush{ winrt::Microsoft::UI::ColorHelper::FromArgb(150, 150, 150, 150) };
288 workarea.BorderBrush(brush);
289 CornerRadius radius{ 8, 8, 8, 8 };
290 Thickness t = { 1, 1, 1, 1 };
291 workarea.CornerRadius(radius);
292 workarea.BorderThickness(t);
293
294 Thickness padding = { 10, 10, 10, 10 };
295 workarea.Padding(padding);
296
297 // add frame to the parent container
298 UiObject* current = uic_current_obj(obj);
299 UI_APPLY_LAYOUT1(current, args);
300 current->container->Add(frame, true);
301
302 UIElement elm = frame;
303 UiWidget* widget = new UiWidget(elm);
304
305 UiObject* newobj = uic_object_new(obj, widget);
306 newobj->container = new UiBoxContainer(workarea, UI_CONTAINER_VBOX, 0, 0);
307 uic_obj_add(obj, newobj);
308
309 return widget;
310 }
311
312
231 /* 313 /*
232 * -------------------- Layout Functions -------------------- 314 * -------------------- Layout Functions --------------------
233 * 315 *
234 * functions for setting layout attributes for the current container 316 * functions for setting layout attributes for the current container
235 * 317 *

mercurial