ui/winui/container.cpp

changeset 614
a6e70dead6bd
parent 613
dac25dd922a2
equal deleted inserted replaced
613:dac25dd922a2 614:a6e70dead6bd
160 } 160 }
161 161
162 162
163 // --------------------- UiGridContainer --------------------- 163 // --------------------- UiGridContainer ---------------------
164 164
165 UIWIDGET ui_grid_create(UiObject* obj, UiContainerArgs args) { 165 UIWIDGET ui_grid_create(UiObject* obj, UiContainerArgs *args) {
166 UiObject* current = uic_current_obj(obj); 166 UiObject* current = uic_current_obj(obj);
167 UI_APPLY_LAYOUT1(current, args); 167 UI_APPLY_LAYOUT2(current, args);
168 168
169 Grid grid = Grid(); 169 Grid grid = Grid();
170 current->container->Add(grid, true); 170 current->container->Add(grid, true);
171 171
172 UIElement elm = grid; 172 UIElement elm = grid;
173 UiWidget* widget = new UiWidget(elm); 173 UiWidget* widget = new UiWidget(elm);
174 ui_context_add_widget_destructor(current->ctx, widget); 174 ui_context_add_widget_destructor(current->ctx, widget);
175 175
176 UiObject* newobj = uic_object_new(obj, widget); 176 UiObject* newobj = uic_object_new(obj, widget);
177 newobj->container = new UiGridContainer(grid, args.margin, args.columnspacing, args.rowspacing); 177 newobj->container = new UiGridContainer(grid, args->margin, args->columnspacing, args->rowspacing);
178 ui_context_add_container_destructor(current->ctx, newobj->container); 178 ui_context_add_container_destructor(current->ctx, newobj->container);
179 uic_obj_add(obj, newobj); 179 uic_obj_add(obj, newobj);
180 180
181 return widget; 181 return widget;
182 } 182 }
302 ui_reset_layout(layout); 302 ui_reset_layout(layout);
303 } 303 }
304 304
305 // --------------------- UI Frame --------------------- 305 // --------------------- UI Frame ---------------------
306 306
307 UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs args) { 307 UIWIDGET ui_frame_create(UiObject* obj, UiFrameArgs *args) {
308 // create a grid for the frame, that contains the label and a sub-frame 308 // create a grid for the frame, that contains the label and a sub-frame
309 Grid frame = Grid(); 309 Grid frame = Grid();
310 310
311 GridLength gl; 311 GridLength gl;
312 gl.GridUnitType = GridUnitType::Star; 312 gl.GridUnitType = GridUnitType::Star;
319 RowDefinition rowdefFrame = RowDefinition(); 319 RowDefinition rowdefFrame = RowDefinition();
320 rowdefFrame.Height(gl); 320 rowdefFrame.Height(gl);
321 321
322 // label 322 // label
323 int row = 0; 323 int row = 0;
324 if (args.label) { 324 if (args->label) {
325 RowDefinition rowdefLabel = RowDefinition(); 325 RowDefinition rowdefLabel = RowDefinition();
326 gl.GridUnitType = GridUnitType::Auto; 326 gl.GridUnitType = GridUnitType::Auto;
327 gl.Value = 0; 327 gl.Value = 0;
328 rowdefLabel.Height(gl); 328 rowdefLabel.Height(gl);
329 frame.RowDefinitions().Append(rowdefLabel); 329 frame.RowDefinitions().Append(rowdefLabel);
330 330
331 TextBlock label = TextBlock(); 331 TextBlock label = TextBlock();
332 wchar_t* wlabel = str2wstr(args.label, nullptr); 332 wchar_t* wlabel = str2wstr(args->label, nullptr);
333 winrt::hstring hstr(wlabel); 333 winrt::hstring hstr(wlabel);
334 label.Text(hstr); 334 label.Text(hstr);
335 free(wlabel); 335 free(wlabel);
336 336
337 frame.SetRow(label, row++); 337 frame.SetRow(label, row++);
358 Thickness padding = { 10, 10, 10, 10 }; 358 Thickness padding = { 10, 10, 10, 10 };
359 workarea.Padding(padding); 359 workarea.Padding(padding);
360 360
361 // add frame to the parent container 361 // add frame to the parent container
362 UiObject* current = uic_current_obj(obj); 362 UiObject* current = uic_current_obj(obj);
363 UI_APPLY_LAYOUT1(current, args); 363 UI_APPLY_LAYOUT2(current, args);
364 current->container->Add(frame, true); 364 current->container->Add(frame, true);
365 365
366 UIElement elm = frame; 366 UIElement elm = frame;
367 UiWidget* widget = new UiWidget(elm); 367 UiWidget* widget = new UiWidget(elm);
368 ui_context_add_widget_destructor(current->ctx, widget); 368 ui_context_add_widget_destructor(current->ctx, widget);
369 369
370 // sub container 370 // sub container
371 UiContainer* ctn = nullptr; 371 UiContainer* ctn = nullptr;
372 switch (args.subcontainer) { 372 switch (args->subcontainer) {
373 default: 373 default:
374 case UI_CONTAINER_VBOX: { 374 case UI_CONTAINER_VBOX: {
375 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); 375 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_VBOX, args->margin, args->spacing);
376 break; 376 break;
377 } 377 }
378 case UI_CONTAINER_HBOX: { 378 case UI_CONTAINER_HBOX: {
379 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); 379 ctn = new UiBoxContainer(workarea, UI_BOX_CONTAINER_HBOX, args->margin, args->spacing);
380 break; 380 break;
381 } 381 }
382 case UI_CONTAINER_GRID: { 382 case UI_CONTAINER_GRID: {
383 ctn = new UiGridContainer(workarea, args.margin, args.columnspacing, args.rowspacing); 383 ctn = new UiGridContainer(workarea, args->margin, args->columnspacing, args->rowspacing);
384 break; 384 break;
385 } 385 }
386 } 386 }
387 ui_context_add_container_destructor(current->ctx, ctn); 387 ui_context_add_container_destructor(current->ctx, ctn);
388 388
393 return widget; 393 return widget;
394 } 394 }
395 395
396 // --------------------- UI Expander --------------------- 396 // --------------------- UI Expander ---------------------
397 397
398 UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs args) { 398 UIWIDGET ui_expander_create(UiObject* obj, UiFrameArgs *args) {
399 Expander expander = Expander(); 399 Expander expander = Expander();
400 if (args.label) { 400 if (args->label) {
401 wchar_t* wlabel = str2wstr(args.label, nullptr); 401 wchar_t* wlabel = str2wstr(args->label, nullptr);
402 expander.Header(box_value(wlabel)); 402 expander.Header(box_value(wlabel));
403 free(wlabel); 403 free(wlabel);
404 } 404 }
405 expander.IsExpanded(args.isexpanded); 405 expander.IsExpanded(args->isexpanded);
406 406
407 // add frame to the parent container 407 // add frame to the parent container
408 UiObject* current = uic_current_obj(obj); 408 UiObject* current = uic_current_obj(obj);
409 UI_APPLY_LAYOUT1(current, args); 409 UI_APPLY_LAYOUT2(current, args);
410 current->container->Add(expander, true); 410 current->container->Add(expander, true);
411 411
412 UIElement elm = expander; 412 UIElement elm = expander;
413 UiWidget* widget = new UiWidget(elm); 413 UiWidget* widget = new UiWidget(elm);
414 ui_context_add_widget_destructor(current->ctx, widget); 414 ui_context_add_widget_destructor(current->ctx, widget);
415 415
416 Grid content = Grid(); 416 Grid content = Grid();
417 expander.Content(content); 417 expander.Content(content);
418 418
419 UiContainer* ctn = nullptr; 419 UiContainer* ctn = nullptr;
420 switch (args.subcontainer) { 420 switch (args->subcontainer) {
421 default: 421 default:
422 case UI_CONTAINER_VBOX: { 422 case UI_CONTAINER_VBOX: {
423 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); 423 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args->margin, args->spacing);
424 break; 424 break;
425 } 425 }
426 case UI_CONTAINER_HBOX: { 426 case UI_CONTAINER_HBOX: {
427 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); 427 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args->margin, args->spacing);
428 break; 428 break;
429 } 429 }
430 case UI_CONTAINER_GRID: { 430 case UI_CONTAINER_GRID: {
431 ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing); 431 ctn = new UiGridContainer(content, args->margin, args->columnspacing, args->rowspacing);
432 break; 432 break;
433 } 433 }
434 } 434 }
435 ui_context_add_container_destructor(current->ctx, ctn); 435 ui_context_add_container_destructor(current->ctx, ctn);
436 436
441 return widget; 441 return widget;
442 } 442 }
443 443
444 // --------------------- UI ScrolledWindow --------------------- 444 // --------------------- UI ScrolledWindow ---------------------
445 445
446 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { 446 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs *args) {
447 ScrollViewer scrollW = ScrollViewer(); 447 ScrollViewer scrollW = ScrollViewer();
448 448
449 // add frame to the parent container 449 // add frame to the parent container
450 UiObject* current = uic_current_obj(obj); 450 UiObject* current = uic_current_obj(obj);
451 UI_APPLY_LAYOUT1(current, args); 451 UI_APPLY_LAYOUT2(current, args);
452 current->container->Add(scrollW, true); 452 current->container->Add(scrollW, true);
453 453
454 UIElement elm = scrollW; 454 UIElement elm = scrollW;
455 UiWidget* widget = new UiWidget(elm); 455 UiWidget* widget = new UiWidget(elm);
456 ui_context_add_widget_destructor(current->ctx, widget); 456 ui_context_add_widget_destructor(current->ctx, widget);
458 // create child container 458 // create child container
459 Grid content = Grid(); 459 Grid content = Grid();
460 scrollW.Content(content); 460 scrollW.Content(content);
461 461
462 UiContainer* ctn = nullptr; 462 UiContainer* ctn = nullptr;
463 switch (args.subcontainer) { 463 switch (args->subcontainer) {
464 default: 464 default:
465 case UI_CONTAINER_VBOX: { 465 case UI_CONTAINER_VBOX: {
466 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args.margin, args.spacing); 466 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_VBOX, args->margin, args->spacing);
467 break; 467 break;
468 } 468 }
469 case UI_CONTAINER_HBOX: { 469 case UI_CONTAINER_HBOX: {
470 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args.margin, args.spacing); 470 ctn = new UiBoxContainer(content, UI_BOX_CONTAINER_HBOX, args->margin, args->spacing);
471 break; 471 break;
472 } 472 }
473 case UI_CONTAINER_GRID: { 473 case UI_CONTAINER_GRID: {
474 ctn = new UiGridContainer(content, args.margin, args.columnspacing, args.rowspacing); 474 ctn = new UiGridContainer(content, args->margin, args->columnspacing, args->rowspacing);
475 break; 475 break;
476 } 476 }
477 } 477 }
478 ui_context_add_container_destructor(current->ctx, ctn); 478 ui_context_add_container_destructor(current->ctx, ctn);
479 479
519 UiObject* newobj = uic_object_new(current, widget); 519 UiObject* newobj = uic_object_new(current, widget);
520 newobj->container = ctn; 520 newobj->container = ctn;
521 return newobj; 521 return newobj;
522 } 522 }
523 523
524 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { 524 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs *args) {
525 Pivot pivot = Pivot(); 525 Pivot pivot = Pivot();
526 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); 526 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args);
527 527
528 return tabview; 528 return tabview;
529 } 529 }
530 530
531 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { 531 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs *args) {
532 this->current = obj; 532 this->current = obj;
533 this->pivot = pivot; 533 this->pivot = pivot;
534 this->subcontainer = args.subcontainer; 534 this->subcontainer = args->subcontainer;
535 this->margin = args.margin; 535 this->margin = args->margin;
536 this->spacing = args.spacing; 536 this->spacing = args->spacing;
537 this->columnspacing = args.columnspacing; 537 this->columnspacing = args->columnspacing;
538 this->rowspacing = args.rowspacing; 538 this->rowspacing = args->rowspacing;
539 } 539 }
540 540
541 UiObject* UiPivotTabView::AddTab(const char* label, int index) { 541 UiObject* UiPivotTabView::AddTab(const char* label, int index) {
542 TextBlock text = TextBlock(); 542 TextBlock text = TextBlock();
543 wchar_t* wlabel = str2wstr(label, nullptr); 543 wchar_t* wlabel = str2wstr(label, nullptr);
567 FrameworkElement UiPivotTabView::GetFrameworkElement() { 567 FrameworkElement UiPivotTabView::GetFrameworkElement() {
568 return pivot; 568 return pivot;
569 } 569 }
570 570
571 571
572 static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) { 572 static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs *args) {
573 Grid container = Grid(); 573 Grid container = Grid();
574 container.HorizontalAlignment(HorizontalAlignment::Stretch); 574 container.HorizontalAlignment(HorizontalAlignment::Stretch);
575 container.VerticalAlignment(VerticalAlignment::Stretch); 575 container.VerticalAlignment(VerticalAlignment::Stretch);
576 UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args); 576 UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args);
577 return tabview; 577 return tabview;
578 } 578 }
579 579
580 UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) { 580 UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs *args) {
581 this->current = obj; 581 this->current = obj;
582 this->container = container; 582 this->container = container;
583 this->subcontainer = args.subcontainer; 583 this->subcontainer = args->subcontainer;
584 this->margin = args.margin; 584 this->margin = args->margin;
585 this->spacing = args.spacing; 585 this->spacing = args->spacing;
586 this->columnspacing = args.columnspacing; 586 this->columnspacing = args->columnspacing;
587 this->rowspacing = args.rowspacing; 587 this->rowspacing = args->rowspacing;
588 this->currentIndex = -1; 588 this->currentIndex = -1;
589 589
590 GridLength gl; 590 GridLength gl;
591 gl.GridUnitType = GridUnitType::Star; 591 gl.GridUnitType = GridUnitType::Star;
592 gl.Value = 1; 592 gl.Value = 1;
637 FrameworkElement UiInvisibleTabView::GetFrameworkElement() { 637 FrameworkElement UiInvisibleTabView::GetFrameworkElement() {
638 return container; 638 return container;
639 } 639 }
640 640
641 641
642 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { 642 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs *args) {
643 TabView tabview = TabView(); 643 TabView tabview = TabView();
644 tabview.IsAddTabButtonVisible(false); 644 tabview.IsAddTabButtonVisible(false);
645 //tabview.CanDragTabs(false); 645 //tabview.CanDragTabs(false);
646 //tabview.CanReorderTabs(false); 646 //tabview.CanReorderTabs(false);
647 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); 647 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args);
648 648
649 return uitabview; 649 return uitabview;
650 } 650 }
651 651
652 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { 652 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs *args) {
653 this->current = obj; 653 this->current = obj;
654 this->tabview = tabview; 654 this->tabview = tabview;
655 this->subcontainer = args.subcontainer; 655 this->subcontainer = args->subcontainer;
656 this->margin = args.margin; 656 this->margin = args->margin;
657 this->spacing = args.spacing; 657 this->spacing = args->spacing;
658 this->columnspacing = args.columnspacing; 658 this->columnspacing = args->columnspacing;
659 this->rowspacing = args.rowspacing; 659 this->rowspacing = args->rowspacing;
660 } 660 }
661 661
662 UiObject* UiMainTabView::AddTab(const char* label, int index) { 662 UiObject* UiMainTabView::AddTab(const char* label, int index) {
663 TextBlock text = TextBlock(); 663 TextBlock text = TextBlock();
664 wchar_t* wlabel = str2wstr(label, nullptr); 664 wchar_t* wlabel = str2wstr(label, nullptr);
690 FrameworkElement UiMainTabView::GetFrameworkElement() { 690 FrameworkElement UiMainTabView::GetFrameworkElement() {
691 return tabview; 691 return tabview;
692 } 692 }
693 693
694 694
695 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { 695 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs *args, UiTabViewType type) {
696 NavigationView navigationview = NavigationView(); 696 NavigationView navigationview = NavigationView();
697 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); 697 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type);
698 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); 698 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed);
699 navigationview.IsSettingsVisible(false); 699 navigationview.IsSettingsVisible(false);
700 700
701 return tabview; 701 return tabview;
702 } 702 }
703 703
704 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { 704 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs *args, UiTabViewType type) {
705 this->current = obj; 705 this->current = obj;
706 this->navigationview = navigationview; 706 this->navigationview = navigationview;
707 this->type = type; 707 this->type = type;
708 this->margin = args.margin; 708 this->margin = args->margin;
709 this->spacing = args.spacing; 709 this->spacing = args->spacing;
710 this->columnspacing = args.columnspacing; 710 this->columnspacing = args->columnspacing;
711 this->rowspacing = args.rowspacing; 711 this->rowspacing = args->rowspacing;
712 712
713 if (type == UI_TABVIEW_NAVIGATION_TOP) { 713 if (type == UI_TABVIEW_NAVIGATION_TOP) {
714 navigationview.PaneDisplayMode(NavigationViewPaneDisplayMode::Top); 714 navigationview.PaneDisplayMode(NavigationViewPaneDisplayMode::Top);
715 } 715 }
716 716
772 static void ui_tabview_set(UiInteger *i, int64_t value) { 772 static void ui_tabview_set(UiInteger *i, int64_t value) {
773 UiTabView *tabview = (UiTabView*)i->obj; 773 UiTabView *tabview = (UiTabView*)i->obj;
774 tabview->Select(value); 774 tabview->Select(value);
775 } 775 }
776 776
777 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { 777 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs *args) {
778 UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview; 778 UiTabViewType type = args->tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args->tabview;
779 UiTabView* tabview = nullptr; 779 UiTabView* tabview = nullptr;
780 switch (type) { 780 switch (type) {
781 default: { 781 default: {
782 tabview = tabview_pivot_create(obj, args); 782 tabview = tabview_pivot_create(obj, args);
783 break; 783 break;
805 } 805 }
806 UiTabViewContainer* ctn = new UiTabViewContainer(tabview); 806 UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
807 807
808 // add frame to the parent container 808 // add frame to the parent container
809 UiObject* current = uic_current_obj(obj); 809 UiObject* current = uic_current_obj(obj);
810 UI_APPLY_LAYOUT1(current, args); 810 UI_APPLY_LAYOUT2(current, args);
811 current->container->Add(tabview->GetFrameworkElement(), true); 811 current->container->Add(tabview->GetFrameworkElement(), true);
812 812
813 UIElement elm = tabview->GetFrameworkElement(); 813 UIElement elm = tabview->GetFrameworkElement();
814 UiWidget* widget = new UiWidget(elm); 814 UiWidget* widget = new UiWidget(elm);
815 ui_context_add_widget_destructor(current->ctx, widget); 815 ui_context_add_widget_destructor(current->ctx, widget);
816 widget->data1 = tabview; 816 widget->data1 = tabview;
817 817
818 // TODO: add tabview destructor 818 // TODO: add tabview destructor
819 819
820 // bind variable 820 // bind variable
821 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); 821 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
822 if (var) { 822 if (var) {
823 UiInteger *i = (UiInteger*)var->value; 823 UiInteger *i = (UiInteger*)var->value;
824 i->obj = tabview; 824 i->obj = tabview;
825 i->get = ui_tabview_get; 825 i->get = ui_tabview_get;
826 i->set = ui_tabview_set; 826 i->set = ui_tabview_set;

mercurial