1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2023 Olaf Wintermann. All rights reserved. |
4 * Copyright 2023 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. |
10 * notice, this list of conditions and the following disclaimer. |
11 * |
11 * |
12 * 2. Redistributions in binary form must reproduce the above copyright |
12 * 2. Redistributions in binary form must reproduce the above copyright |
13 * notice, this list of conditions and the following disclaimer in the |
13 * notice, this list of conditions and the following disclaimer in the |
14 * documentation and/or other materials provided with the distribution. |
14 * documentation and/or other materials provided with the distribution. |
15 * |
15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include "pch.h" |
29 #include "pch.h" |
30 |
30 |
31 #include "container.h" |
31 #include "container.h" |
32 |
32 |
458 UiObject* newobj = uic_object_new(current, widget); |
505 UiObject* newobj = uic_object_new(current, widget); |
459 newobj->container = ctn; |
506 newobj->container = ctn; |
460 return newobj; |
507 return newobj; |
461 } |
508 } |
462 |
509 |
|
510 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { |
|
511 Pivot pivot = Pivot(); |
|
512 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); |
|
513 |
|
514 return tabview; |
|
515 } |
|
516 |
463 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { |
517 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { |
464 this->current = obj; |
518 this->current = obj; |
465 this->pivot = pivot; |
519 this->pivot = pivot; |
|
520 this->subcontainer = args.subcontainer; |
466 this->margin = args.margin; |
521 this->margin = args.margin; |
467 this->spacing = args.spacing; |
522 this->spacing = args.spacing; |
468 this->columnspacing = args.columnspacing; |
523 this->columnspacing = args.columnspacing; |
469 this->rowspacing = args.rowspacing; |
524 this->rowspacing = args.rowspacing; |
470 } |
525 } |
471 |
526 |
472 UiObject* UiPivotTabView::AddTab(const char* label) { |
527 UiObject* UiPivotTabView::AddTab(const char* label, int index) { |
473 TextBlock text = TextBlock(); |
528 TextBlock text = TextBlock(); |
474 wchar_t* wlabel = str2wstr(label, nullptr); |
529 wchar_t* wlabel = str2wstr(label, nullptr); |
475 winrt::hstring hstr(wlabel); |
530 winrt::hstring hstr(wlabel); |
476 text.Text(hstr); |
531 text.Text(hstr); |
477 free(wlabel); |
532 free(wlabel); |
485 pivot.Items().Append(item); |
540 pivot.Items().Append(item); |
486 |
541 |
487 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
542 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
488 } |
543 } |
489 |
544 |
|
545 void UiPivotTabView::Remove(int index) { |
|
546 pivot.Items().RemoveAt(index); |
|
547 } |
|
548 |
|
549 void UiPivotTabView::Select(int index) { |
|
550 |
|
551 } |
|
552 |
490 FrameworkElement UiPivotTabView::GetFrameworkElement() { |
553 FrameworkElement UiPivotTabView::GetFrameworkElement() { |
491 return pivot; |
554 return pivot; |
492 } |
555 } |
493 |
556 |
494 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { |
557 |
495 Pivot pivot = Pivot(); |
558 static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) { |
496 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); |
559 Grid container = Grid(); |
497 |
560 container.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
561 container.VerticalAlignment(VerticalAlignment::Stretch); |
|
562 UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args); |
498 return tabview; |
563 return tabview; |
499 } |
564 } |
500 |
565 |
501 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { |
566 UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) { |
502 this->current = obj; |
567 this->current = obj; |
503 this->tabview = tabview; |
568 this->container = container; |
|
569 this->subcontainer = args.subcontainer; |
504 this->margin = args.margin; |
570 this->margin = args.margin; |
505 this->spacing = args.spacing; |
571 this->spacing = args.spacing; |
506 this->columnspacing = args.columnspacing; |
572 this->columnspacing = args.columnspacing; |
507 this->rowspacing = args.rowspacing; |
573 this->rowspacing = args.rowspacing; |
508 } |
574 this->currentIndex = -1; |
509 |
575 |
510 UiObject* UiMainTabView::AddTab(const char* label) { |
576 GridLength gl; |
511 TextBlock text = TextBlock(); |
577 gl.GridUnitType = GridUnitType::Star; |
512 wchar_t* wlabel = str2wstr(label, nullptr); |
578 gl.Value = 1; |
513 winrt::hstring hstr(wlabel); |
579 |
514 text.Text(hstr); |
580 ColumnDefinition coldef = ColumnDefinition(); |
515 free(wlabel); |
581 coldef.Width(gl); |
516 |
582 container.ColumnDefinitions().Append(coldef); |
517 TabViewItem item = TabViewItem(); |
583 |
518 item.Header(text); |
584 RowDefinition rowdef = RowDefinition(); |
519 item.CanDrag(false); |
585 rowdef.Height(gl); |
520 item.IsClosable(false); |
586 container.RowDefinitions().Append(rowdef); |
|
587 } |
|
588 |
|
589 UiObject* UiInvisibleTabView::AddTab(const char* label, int index) { |
|
590 Grid subcontainer = Grid(); |
|
591 subcontainer.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
592 subcontainer.VerticalAlignment(VerticalAlignment::Stretch); |
|
593 |
|
594 if (pages.size() == 0) { |
|
595 container.Children().Append(subcontainer); |
|
596 currentIndex = 0; |
|
597 } |
|
598 |
|
599 if (index < 0) { |
|
600 pages.push_back(subcontainer); |
|
601 } else { |
|
602 pages.insert(pages.begin() + index, subcontainer); |
|
603 } |
521 |
604 |
522 // sub container |
605 // sub container |
523 Grid subcontainer = Grid(); |
|
524 item.Content(subcontainer); |
|
525 tabview.TabItems().Append(item); |
|
526 |
|
527 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
606 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
528 } |
607 } |
529 |
608 |
530 FrameworkElement UiMainTabView::GetFrameworkElement() { |
609 void UiInvisibleTabView::Remove(int index) { |
531 return tabview; |
610 |
532 } |
611 } |
|
612 |
|
613 void UiInvisibleTabView::Select(int index) { |
|
614 if (index >= 0 && index < pages.size()) { |
|
615 if (currentIndex != -1) { |
|
616 container.Children().RemoveAt(0); |
|
617 } |
|
618 |
|
619 container.Children().Append(pages.at(index)); |
|
620 } |
|
621 } |
|
622 |
|
623 FrameworkElement UiInvisibleTabView::GetFrameworkElement() { |
|
624 return container; |
|
625 } |
|
626 |
533 |
627 |
534 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { |
628 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { |
535 TabView tabview = TabView(); |
629 TabView tabview = TabView(); |
536 tabview.IsAddTabButtonVisible(false); |
630 tabview.IsAddTabButtonVisible(false); |
537 //tabview.CanDragTabs(false); |
631 //tabview.CanDragTabs(false); |
538 //tabview.CanReorderTabs(false); |
632 //tabview.CanReorderTabs(false); |
539 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); |
633 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); |
540 |
634 |
541 return uitabview; |
635 return uitabview; |
|
636 } |
|
637 |
|
638 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { |
|
639 this->current = obj; |
|
640 this->tabview = tabview; |
|
641 this->subcontainer = args.subcontainer; |
|
642 this->margin = args.margin; |
|
643 this->spacing = args.spacing; |
|
644 this->columnspacing = args.columnspacing; |
|
645 this->rowspacing = args.rowspacing; |
|
646 } |
|
647 |
|
648 UiObject* UiMainTabView::AddTab(const char* label, int index) { |
|
649 TextBlock text = TextBlock(); |
|
650 wchar_t* wlabel = str2wstr(label, nullptr); |
|
651 winrt::hstring hstr(wlabel); |
|
652 text.Text(hstr); |
|
653 free(wlabel); |
|
654 |
|
655 TabViewItem item = TabViewItem(); |
|
656 item.Header(text); |
|
657 item.CanDrag(false); |
|
658 item.IsClosable(false); |
|
659 |
|
660 // sub container |
|
661 Grid subcontainer = Grid(); |
|
662 item.Content(subcontainer); |
|
663 tabview.TabItems().Append(item); |
|
664 |
|
665 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
|
666 } |
|
667 |
|
668 void UiMainTabView::Remove(int index) { |
|
669 this->tabview.TabItems().RemoveAt(index); |
|
670 } |
|
671 |
|
672 void UiMainTabView::Select(int index) { |
|
673 |
|
674 } |
|
675 |
|
676 FrameworkElement UiMainTabView::GetFrameworkElement() { |
|
677 return tabview; |
|
678 } |
|
679 |
|
680 |
|
681 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { |
|
682 NavigationView navigationview = NavigationView(); |
|
683 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); |
|
684 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); |
|
685 navigationview.IsSettingsVisible(false); |
|
686 |
|
687 return tabview; |
542 } |
688 } |
543 |
689 |
544 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { |
690 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { |
545 this->current = obj; |
691 this->current = obj; |
546 this->navigationview = navigationview; |
692 this->navigationview = navigationview; |
654 UiTabView* tabview = (UiTabView*)current->widget->data1; |
824 UiTabView* tabview = (UiTabView*)current->widget->data1; |
655 UiObject* newobj = tabview->AddTab(title); |
825 UiObject* newobj = tabview->AddTab(title); |
656 uic_obj_add(current, newobj); |
826 uic_obj_add(current, newobj); |
657 } |
827 } |
658 |
828 |
|
829 UIEXPORT void ui_tabview_select(UIWIDGET tabview, int tab) { |
|
830 UiTabView* t = (UiTabView*)tabview->data1; |
|
831 t->Select(tab); |
|
832 } |
|
833 |
|
834 UIEXPORT void ui_tabview_remove(UIWIDGET tabview, int tab) { |
|
835 UiTabView* t = (UiTabView*)tabview->data1; |
|
836 t->Remove(tab); |
|
837 } |
|
838 |
|
839 UIEXPORT UiObject* ui_tabview_add(UIWIDGET tabview, const char *name, int tab_index) { |
|
840 UiTabView* t = (UiTabView*)tabview->data1; |
|
841 UiObject* newobj = t->AddTab(name, tab_index); |
|
842 return newobj; |
|
843 } |
|
844 |
|
845 |
|
846 |
|
847 // --------------------- UI Headerbar --------------------- |
|
848 |
|
849 // TODO: replace placeholder implementation |
|
850 |
|
851 UIEXPORT UIWIDGET ui_headerbar_create(UiObject *obj, UiHeaderbarArgs args) { |
|
852 UiContainerArgs boxargs = { }; |
|
853 boxargs.fill = UI_OFF; |
|
854 return ui_hbox_create(obj, boxargs); |
|
855 } |
|
856 |
|
857 UIEXPORT void ui_headerbar_start_create(UiObject *obj) { |
|
858 UiContainerArgs boxargs = { }; |
|
859 boxargs.fill = UI_OFF; |
|
860 ui_hbox_create(obj, boxargs); |
|
861 } |
|
862 |
|
863 UIEXPORT void ui_headerbar_center_create(UiObject *obj) { |
|
864 UiContainerArgs boxargs = { }; |
|
865 boxargs.fill = UI_OFF; |
|
866 ui_hbox_create(obj, boxargs); |
|
867 } |
|
868 |
|
869 UIEXPORT void ui_headerbar_end_create(UiObject *obj) { |
|
870 UiContainerArgs boxargs = { }; |
|
871 boxargs.fill = UI_OFF; |
|
872 ui_hbox_create(obj, boxargs); |
|
873 } |
|
874 |
|
875 |
659 /* |
876 /* |
660 * -------------------- Layout Functions -------------------- |
877 * -------------------- Layout Functions -------------------- |
661 * |
878 * |
662 * functions for setting layout attributes for the current container |
879 * functions for setting layout attributes for the current container |
663 * |
880 * |
664 */ |
881 */ |
665 |
882 |
666 void ui_layout_fill(UiObject* obj, UiBool fill) { |
883 void ui_layout_fill(UiObject* obj, UiBool fill) { |
667 UiContainer* ct = uic_get_current_container(obj); |
884 UiContainer* ct = uic_get_current_container(obj); |
668 ct->layout.fill = ui_bool2lb(fill); |
885 ct->layout.fill = ui_bool2lb(fill); |
669 } |
886 } |
676 void ui_layout_vexpand(UiObject* obj, UiBool expand) { |
893 void ui_layout_vexpand(UiObject* obj, UiBool expand) { |
677 UiContainer* ct = uic_get_current_container(obj); |
894 UiContainer* ct = uic_get_current_container(obj); |
678 ct->layout.vexpand = expand; |
895 ct->layout.vexpand = expand; |
679 } |
896 } |
680 |
897 |
681 void ui_layout_hfill(UiObject *obj, UiBool fill) { |
898 void ui_layout_hfill(UiObject* obj, UiBool fill) { |
682 UiContainer *ct = uic_get_current_container(obj); |
899 UiContainer* ct = uic_get_current_container(obj); |
683 ct->layout.hfill = fill; |
900 ct->layout.hfill = fill; |
684 } |
901 } |
685 |
902 |
686 void ui_layout_vfill(UiObject *obj, UiBool fill) { |
903 void ui_layout_vfill(UiObject* obj, UiBool fill) { |
687 UiContainer *ct = uic_get_current_container(obj); |
904 UiContainer* ct = uic_get_current_container(obj); |
688 ct->layout.vfill = fill; |
905 ct->layout.vfill = fill; |
689 } |
906 } |
690 |
907 |
691 void ui_layout_width(UiObject* obj, int width) { |
908 void ui_layout_width(UiObject* obj, int width) { |
692 UiContainer* ct = uic_get_current_container(obj); |
909 UiContainer* ct = uic_get_current_container(obj); |
693 ct->layout.width = width; |
910 ct->layout.width = width; |