ui/winui/container.cpp

branch
newapi
changeset 195
0f2e69873875
parent 194
e2281ace0769
child 198
f2332d0d3318
equal deleted inserted replaced
194:e2281ace0769 195:0f2e69873875
70 70
71 return widget; 71 return widget;
72 } 72 }
73 73
74 UIWIDGET ui_vbox_create(UiObject* obj, UiContainerArgs args) { 74 UIWIDGET ui_vbox_create(UiObject* obj, UiContainerArgs args) {
75 return ui_box(obj, args, UI_CONTAINER_VBOX); 75 return ui_box(obj, args, UI_BOX_CONTAINER_VBOX);
76 } 76 }
77 77
78 UIWIDGET ui_hbox_create(UiObject* obj, UiContainerArgs args) { 78 UIWIDGET ui_hbox_create(UiObject* obj, UiContainerArgs args) {
79 return ui_box(obj, args, UI_CONTAINER_HBOX); 79 return ui_box(obj, args, UI_BOX_CONTAINER_HBOX);
80 } 80 }
81 81
82 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) { 82 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing) {
83 this->grid = grid; 83 this->grid = grid;
84 this->type = type; 84 this->type = type;
92 gl.Value = 1; 92 gl.Value = 1;
93 gl.GridUnitType = GridUnitType::Star; 93 gl.GridUnitType = GridUnitType::Star;
94 94
95 // hbox needs one row def, vbox needs one col def 95 // hbox needs one row def, vbox needs one col def
96 // all other col/row defs are created when elements are added 96 // all other col/row defs are created when elements are added
97 if (type == UI_CONTAINER_HBOX) { 97 if (type == UI_BOX_CONTAINER_HBOX) {
98 boxRowDef = RowDefinition(); 98 boxRowDef = RowDefinition();
99 boxRowDef.Height(gl); 99 boxRowDef.Height(gl);
100 grid.RowDefinitions().Append(boxRowDef); 100 grid.RowDefinitions().Append(boxRowDef);
101 } else { 101 } else {
102 boxColDef = ColumnDefinition(); 102 boxColDef = ColumnDefinition();
300 current->container->Add(frame, true); 300 current->container->Add(frame, true);
301 301
302 UIElement elm = frame; 302 UIElement elm = frame;
303 UiWidget* widget = new UiWidget(elm); 303 UiWidget* widget = new UiWidget(elm);
304 304
305 // sub container
306 UiContainer* ctn = nullptr;
307 switch (args.subcontainer) {
308 default:
309 case UI_CONTAINER_VBOX: {
310 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
311 break;
312 }
313 case UI_CONTAINER_HBOX: {
314 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing);
315 break;
316 }
317 case UI_CONTAINER_GRID: {
318 ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing);
319 break;
320 }
321 }
322
305 UiObject* newobj = uic_object_new(obj, widget); 323 UiObject* newobj = uic_object_new(obj, widget);
306 newobj->container = new UiBoxContainer(workarea, UI_CONTAINER_VBOX, 0, 0); 324 newobj->container = ctn;
307 uic_obj_add(obj, newobj); 325 uic_obj_add(obj, newobj);
308 326
309 return widget; 327 return widget;
310 } 328 }
311 329
330 // --------------------- UI Expander ---------------------
331
332 UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args) {
333 Expander expander = Expander();
334 if (args.label) {
335 wchar_t* wlabel = str2wstr(args.label, nullptr);
336 expander.Header(box_value(wlabel));
337 free(wlabel);
338 }
339 expander.IsExpanded(args.isexpanded);
340
341 // add frame to the parent container
342 UiObject* current = uic_current_obj(obj);
343 UI_APPLY_LAYOUT1(current, args);
344 current->container->Add(expander, true);
345
346 UIElement elm = expander;
347 UiWidget* widget = new UiWidget(elm);
348
349 Grid content = Grid();
350 expander.Content(content);
351
352 UiContainer* ctn = nullptr;
353 switch (args.subcontainer) {
354 default:
355 case UI_CONTAINER_VBOX: {
356 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
357 break;
358 }
359 case UI_CONTAINER_HBOX: {
360 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing);
361 break;
362 }
363 case UI_CONTAINER_GRID: {
364 ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing);
365 break;
366 }
367 }
368
369 UiObject* newobj = uic_object_new(obj, widget);
370 newobj->container = ctn;
371 uic_obj_add(obj, newobj);
372
373 return widget;
374 }
375
312 // --------------------- UI ScrolledWindow --------------------- 376 // --------------------- UI ScrolledWindow ---------------------
313 377
314 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiContainerArgs args) { 378 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
315 ScrollViewer scrollW = ScrollViewer(); 379 ScrollViewer scrollW = ScrollViewer();
316 380
317 // add frame to the parent container 381 // add frame to the parent container
318 UiObject* current = uic_current_obj(obj); 382 UiObject* current = uic_current_obj(obj);
319 UI_APPLY_LAYOUT1(current, args); 383 UI_APPLY_LAYOUT1(current, args);
320 current->container->Add(scrollW, true); 384 current->container->Add(scrollW, true);
321 385
322 UIElement elm = scrollW; 386 UIElement elm = scrollW;
323 UiWidget* widget = new UiWidget(elm); 387 UiWidget* widget = new UiWidget(elm);
324 388
325 // create a vbox as child container 389 // create child container
326 Grid vbox = Grid(); 390 Grid content = Grid();
327 scrollW.Content(vbox); 391 scrollW.Content(content);
392
393 UiContainer* ctn = nullptr;
394 switch (args.subcontainer) {
395 default:
396 case UI_CONTAINER_VBOX: {
397 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
398 break;
399 }
400 case UI_CONTAINER_HBOX: {
401 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing);
402 break;
403 }
404 case UI_CONTAINER_GRID: {
405 ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing);
406 break;
407 }
408 }
328 409
329 UiObject* newobj = uic_object_new(obj, widget); 410 UiObject* newobj = uic_object_new(obj, widget);
330 newobj->container = new UiBoxContainer(vbox, UI_CONTAINER_VBOX, args.margin, args.spacing); 411 newobj->container = ctn;
331 uic_obj_add(obj, newobj); 412 uic_obj_add(obj, newobj);
332 413
333 return widget; 414 return widget;
334 } 415 }
335 416

mercurial