ui/winui/container.cpp

branch
newapi
changeset 198
f2332d0d3318
parent 195
0f2e69873875
child 199
84e0a24bab4a
equal deleted inserted replaced
197:8a82ebe23822 198:f2332d0d3318
303 UiWidget* widget = new UiWidget(elm); 303 UiWidget* widget = new UiWidget(elm);
304 304
305 // sub container 305 // sub container
306 UiContainer* ctn = nullptr; 306 UiContainer* ctn = nullptr;
307 switch (args.subcontainer) { 307 switch (args.subcontainer) {
308 default: 308 default:
309 case UI_CONTAINER_VBOX: { 309 case UI_CONTAINER_VBOX: {
310 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); 310 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing);
311 break; 311 break;
312 } 312 }
313 case UI_CONTAINER_HBOX: { 313 case UI_CONTAINER_HBOX: {
314 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); 314 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing);
315 break; 315 break;
316 } 316 }
317 case UI_CONTAINER_GRID: { 317 case UI_CONTAINER_GRID: {
318 ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing); 318 ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing);
319 break; 319 break;
320 } 320 }
321 } 321 }
322 322
323 UiObject* newobj = uic_object_new(obj, widget); 323 UiObject* newobj = uic_object_new(obj, widget);
324 newobj->container = ctn; 324 newobj->container = ctn;
325 uic_obj_add(obj, newobj); 325 uic_obj_add(obj, newobj);
412 uic_obj_add(obj, newobj); 412 uic_obj_add(obj, newobj);
413 413
414 return widget; 414 return widget;
415 } 415 }
416 416
417 // --------------------- UI TabView ---------------------
418
419 UiTabViewContainer::UiTabViewContainer(UiTabView* tabview) {
420 this->tabview = tabview;
421 }
422
423 void UiTabViewContainer::Add(FrameworkElement control, UiBool fill) {
424 // noop
425 }
426
427 static UiObject* create_subcontainer_obj(UiObject* current, Grid subcontainer, UiSubContainerType type, int margin, int spacing, int columnspacing, int rowspacing) {
428 UiContainer* ctn = nullptr;
429 switch (type) {
430 default:
431 case UI_CONTAINER_VBOX: {
432 ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_VBOX, margin, spacing);
433 break;
434 }
435 case UI_CONTAINER_HBOX: {
436 ctn = new UiBoxContainer(subcontainer, UI_BOX_CONTAINER_HBOX, margin, spacing);
437 break;
438 }
439 case UI_CONTAINER_GRID: {
440 ctn = new UiGridContainer(subcontainer, margin, columnspacing, rowspacing);
441 break;
442 }
443 }
444
445 UIElement elm = subcontainer;
446 UiWidget* widget = new UiWidget(elm);
447 UiObject* newobj = uic_object_new(current, widget);
448 newobj->container = ctn;
449 return newobj;
450 }
451
452 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) {
453 this->current = obj;
454 this->pivot = pivot;
455 this->margin = args.margin;
456 this->spacing = args.spacing;
457 this->columnspacing = args.columnspacing;
458 this->rowspacing = args.rowspacing;
459 }
460
461 UiObject* UiPivotTabView::AddTab(const char* label) {
462 TextBlock text = TextBlock();
463 wchar_t* wlabel = str2wstr(label, nullptr);
464 winrt::hstring hstr(wlabel);
465 text.Text(hstr);
466 free(wlabel);
467
468 PivotItem item = PivotItem();
469 item.Header(text);
470
471 // sub container
472 Grid subcontainer = Grid();
473 item.Content(subcontainer);
474 pivot.Items().Append(item);
475
476 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
477 }
478
479 FrameworkElement UiPivotTabView::GetFrameworkElement() {
480 return pivot;
481 }
482
483 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) {
484 Pivot pivot = Pivot();
485 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args);
486
487 return tabview;
488 }
489
490 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
491 UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview;
492 UiTabView *tabview = tabview_pivot_create(obj, args);
493 UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
494
495 // add frame to the parent container
496 UiObject* current = uic_current_obj(obj);
497 UI_APPLY_LAYOUT1(current, args);
498 current->container->Add(tabview->GetFrameworkElement(), true);
499
500 UIElement elm = tabview->GetFrameworkElement();
501 UiWidget* widget = new UiWidget(elm);
502 widget->data1 = tabview;
503
504 UiObject* newobj = uic_object_new(obj, widget);
505 newobj->container = ctn;
506 uic_obj_add(obj, newobj);
507
508 return widget;
509 }
510
511 void ui_tab_create(UiObject* obj, const char* title) {
512 UiObject* current = uic_current_obj(obj);
513 UiTabView* tabview = (UiTabView*)current->widget->data1;
514 UiObject* newobj = tabview->AddTab(title);
515 uic_obj_add(current, newobj);
516 }
417 517
418 /* 518 /*
419 * -------------------- Layout Functions -------------------- 519 * -------------------- Layout Functions --------------------
420 * 520 *
421 * functions for setting layout attributes for the current container 521 * functions for setting layout attributes for the current container

mercurial