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 |
235 coldef.Width(gl); |
235 coldef.Width(gl); |
236 grid.ColumnDefinitions().Append(coldef); |
236 grid.ColumnDefinitions().Append(coldef); |
237 cols++; |
237 cols++; |
238 } else if(hexpand) { |
238 } else if(hexpand) { |
239 // adjust column |
239 // adjust column |
240 gl.GridUnitType = GridUnitType::Star; |
240 if (layout.colspan == 0) { |
241 gl.Value = 1; |
241 gl.GridUnitType = GridUnitType::Star; |
242 grid.ColumnDefinitions().GetAt(x).Width(gl); |
242 gl.Value = 1; |
|
243 grid.ColumnDefinitions().GetAt(x).Width(gl); |
|
244 } else { |
|
245 int adjust_col = x; |
|
246 bool adjust = true; |
|
247 for (int i = 0; i < layout.colspan; i++) { |
|
248 if (grid.ColumnDefinitions().Size() == x + i) { |
|
249 break; |
|
250 } |
|
251 adjust_col = x + i; |
|
252 GridLength w = grid.ColumnDefinitions().GetAt(adjust_col).Width(); |
|
253 if (w.GridUnitType == GridUnitType::Star) { |
|
254 adjust = false; |
|
255 break; |
|
256 } |
|
257 } |
|
258 |
|
259 if (adjust) { |
|
260 gl.GridUnitType = GridUnitType::Star; |
|
261 gl.Value = 1; |
|
262 grid.ColumnDefinitions().GetAt(adjust_col).Width(gl); |
|
263 } |
|
264 } |
243 } |
265 } |
244 |
266 |
245 // add control |
267 // add control |
246 if (hfill) { |
268 if (hfill) { |
247 control.HorizontalAlignment(HorizontalAlignment::Stretch); |
269 control.HorizontalAlignment(HorizontalAlignment::Stretch); |
483 UiObject* newobj = uic_object_new(current, widget); |
505 UiObject* newobj = uic_object_new(current, widget); |
484 newobj->container = ctn; |
506 newobj->container = ctn; |
485 return newobj; |
507 return newobj; |
486 } |
508 } |
487 |
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 |
488 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { |
517 UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { |
489 this->current = obj; |
518 this->current = obj; |
490 this->pivot = pivot; |
519 this->pivot = pivot; |
|
520 this->subcontainer = args.subcontainer; |
491 this->margin = args.margin; |
521 this->margin = args.margin; |
492 this->spacing = args.spacing; |
522 this->spacing = args.spacing; |
493 this->columnspacing = args.columnspacing; |
523 this->columnspacing = args.columnspacing; |
494 this->rowspacing = args.rowspacing; |
524 this->rowspacing = args.rowspacing; |
495 } |
525 } |
514 |
544 |
515 void UiPivotTabView::Remove(int index) { |
545 void UiPivotTabView::Remove(int index) { |
516 pivot.Items().RemoveAt(index); |
546 pivot.Items().RemoveAt(index); |
517 } |
547 } |
518 |
548 |
|
549 void UiPivotTabView::Select(int index) { |
|
550 |
|
551 } |
|
552 |
519 FrameworkElement UiPivotTabView::GetFrameworkElement() { |
553 FrameworkElement UiPivotTabView::GetFrameworkElement() { |
520 return pivot; |
554 return pivot; |
521 } |
555 } |
522 |
556 |
523 static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { |
557 |
524 Pivot pivot = Pivot(); |
558 static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) { |
525 UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); |
559 Grid container = Grid(); |
526 |
560 container.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
561 container.VerticalAlignment(VerticalAlignment::Stretch); |
|
562 UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args); |
527 return tabview; |
563 return tabview; |
|
564 } |
|
565 |
|
566 UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) { |
|
567 this->current = obj; |
|
568 this->container = container; |
|
569 this->subcontainer = args.subcontainer; |
|
570 this->margin = args.margin; |
|
571 this->spacing = args.spacing; |
|
572 this->columnspacing = args.columnspacing; |
|
573 this->rowspacing = args.rowspacing; |
|
574 this->currentIndex = -1; |
|
575 |
|
576 GridLength gl; |
|
577 gl.GridUnitType = GridUnitType::Star; |
|
578 gl.Value = 1; |
|
579 |
|
580 ColumnDefinition coldef = ColumnDefinition(); |
|
581 coldef.Width(gl); |
|
582 container.ColumnDefinitions().Append(coldef); |
|
583 |
|
584 RowDefinition rowdef = RowDefinition(); |
|
585 rowdef.Height(gl); |
|
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 } |
|
604 |
|
605 // sub container |
|
606 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); |
|
607 } |
|
608 |
|
609 void UiInvisibleTabView::Remove(int index) { |
|
610 |
|
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 |
|
627 |
|
628 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { |
|
629 TabView tabview = TabView(); |
|
630 tabview.IsAddTabButtonVisible(false); |
|
631 //tabview.CanDragTabs(false); |
|
632 //tabview.CanReorderTabs(false); |
|
633 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); |
|
634 |
|
635 return uitabview; |
528 } |
636 } |
529 |
637 |
530 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { |
638 UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { |
531 this->current = obj; |
639 this->current = obj; |
532 this->tabview = tabview; |
640 this->tabview = tabview; |
|
641 this->subcontainer = args.subcontainer; |
533 this->margin = args.margin; |
642 this->margin = args.margin; |
534 this->spacing = args.spacing; |
643 this->spacing = args.spacing; |
535 this->columnspacing = args.columnspacing; |
644 this->columnspacing = args.columnspacing; |
536 this->rowspacing = args.rowspacing; |
645 this->rowspacing = args.rowspacing; |
537 } |
646 } |
558 |
667 |
559 void UiMainTabView::Remove(int index) { |
668 void UiMainTabView::Remove(int index) { |
560 this->tabview.TabItems().RemoveAt(index); |
669 this->tabview.TabItems().RemoveAt(index); |
561 } |
670 } |
562 |
671 |
|
672 void UiMainTabView::Select(int index) { |
|
673 |
|
674 } |
|
675 |
563 FrameworkElement UiMainTabView::GetFrameworkElement() { |
676 FrameworkElement UiMainTabView::GetFrameworkElement() { |
564 return tabview; |
677 return tabview; |
565 } |
678 } |
566 |
679 |
567 static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { |
680 |
568 TabView tabview = TabView(); |
681 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { |
569 tabview.IsAddTabButtonVisible(false); |
682 NavigationView navigationview = NavigationView(); |
570 //tabview.CanDragTabs(false); |
683 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); |
571 //tabview.CanReorderTabs(false); |
684 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); |
572 UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); |
685 navigationview.IsSettingsVisible(false); |
573 |
686 |
574 return uitabview; |
687 return tabview; |
575 } |
688 } |
576 |
689 |
577 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { |
690 UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { |
578 this->current = obj; |
691 this->current = obj; |
579 this->navigationview = navigationview; |
692 this->navigationview = navigationview; |
617 void UiNavigationTabView::Remove(int index) { |
730 void UiNavigationTabView::Remove(int index) { |
618 navigationview.MenuItems().RemoveAt(index); |
731 navigationview.MenuItems().RemoveAt(index); |
619 pages.erase(pages.begin() + index); |
732 pages.erase(pages.begin() + index); |
620 } |
733 } |
621 |
734 |
|
735 void UiNavigationTabView::Select(int index) { |
|
736 |
|
737 } |
|
738 |
622 FrameworkElement UiNavigationTabView::GetFrameworkElement() { |
739 FrameworkElement UiNavigationTabView::GetFrameworkElement() { |
623 return navigationview; |
740 return navigationview; |
624 } |
741 } |
625 |
742 |
626 void UiNavigationTabView::SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args) { |
743 void UiNavigationTabView::SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args) { |
632 break; |
749 break; |
633 } |
750 } |
634 } |
751 } |
635 } |
752 } |
636 |
753 |
637 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { |
754 static int64_t ui_tabview_get(UiInteger *i) { |
638 NavigationView navigationview = NavigationView(); |
755 return 0; |
639 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); |
756 } |
640 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); |
757 |
641 navigationview.IsSettingsVisible(false); |
758 static void ui_tabview_set(UiInteger *i, int64_t value) { |
642 |
759 UiTabView *tabview = (UiTabView*)i->obj; |
643 return tabview; |
760 tabview->Select(value); |
644 } |
761 } |
645 |
762 |
646 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { |
763 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { |
647 UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview; |
764 UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview; |
648 UiTabView* tabview = nullptr; |
765 UiTabView* tabview = nullptr; |
677 |
798 |
678 UIElement elm = tabview->GetFrameworkElement(); |
799 UIElement elm = tabview->GetFrameworkElement(); |
679 UiWidget* widget = new UiWidget(elm); |
800 UiWidget* widget = new UiWidget(elm); |
680 ui_context_add_widget_destructor(current->ctx, widget); |
801 ui_context_add_widget_destructor(current->ctx, widget); |
681 widget->data1 = tabview; |
802 widget->data1 = tabview; |
|
803 |
|
804 // TODO: add tabview destructor |
|
805 |
|
806 // bind variable |
|
807 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
|
808 if (var) { |
|
809 UiInteger *i = (UiInteger*)var->value; |
|
810 i->obj = tabview; |
|
811 i->get = ui_tabview_get; |
|
812 i->set = ui_tabview_set; |
|
813 } |
682 |
814 |
683 UiObject* newobj = uic_object_new(obj, widget); |
815 UiObject* newobj = uic_object_new(obj, widget); |
684 newobj->container = ctn; |
816 newobj->container = ctn; |
685 uic_obj_add(obj, newobj); |
817 uic_obj_add(obj, newobj); |
686 |
818 |
761 void ui_layout_vexpand(UiObject* obj, UiBool expand) { |
893 void ui_layout_vexpand(UiObject* obj, UiBool expand) { |
762 UiContainer* ct = uic_get_current_container(obj); |
894 UiContainer* ct = uic_get_current_container(obj); |
763 ct->layout.vexpand = expand; |
895 ct->layout.vexpand = expand; |
764 } |
896 } |
765 |
897 |
|
898 void ui_layout_hfill(UiObject* obj, UiBool fill) { |
|
899 UiContainer* ct = uic_get_current_container(obj); |
|
900 ct->layout.hfill = fill; |
|
901 } |
|
902 |
|
903 void ui_layout_vfill(UiObject* obj, UiBool fill) { |
|
904 UiContainer* ct = uic_get_current_container(obj); |
|
905 ct->layout.vfill = fill; |
|
906 } |
|
907 |
766 void ui_layout_width(UiObject* obj, int width) { |
908 void ui_layout_width(UiObject* obj, int width) { |
767 UiContainer* ct = uic_get_current_container(obj); |
909 UiContainer* ct = uic_get_current_container(obj); |
768 ct->layout.width = width; |
910 ct->layout.width = width; |
769 } |
911 } |
770 |
912 |