ui/winui/container.cpp

changeset 76
641dcc79e0ef
parent 75
73c8a3780c72
equal deleted inserted replaced
75:73c8a3780c72 76:641dcc79e0ef
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
120 } 120 }
121 else { 121 else {
122 gl.Value = 0; 122 gl.Value = 0;
123 gl.GridUnitType = GridUnitType::Auto; 123 gl.GridUnitType = GridUnitType::Auto;
124 } 124 }
125 125
126 control.HorizontalAlignment(HorizontalAlignment::Stretch); 126 control.HorizontalAlignment(HorizontalAlignment::Stretch);
127 control.VerticalAlignment(VerticalAlignment::Stretch); 127 control.VerticalAlignment(VerticalAlignment::Stretch);
128 128
129 if (type == UI_CONTAINER_HBOX) { 129 if (type == UI_CONTAINER_HBOX) {
130 ColumnDefinition coldef = ColumnDefinition(); 130 ColumnDefinition coldef = ColumnDefinition();
177 } 177 }
178 178
179 void UiGridContainer::Add(FrameworkElement control, UiBool fill) { 179 void UiGridContainer::Add(FrameworkElement control, UiBool fill) {
180 GridLength gl; 180 GridLength gl;
181 181
182 int hexpand = FALSE; 182 bool hexpand = false;
183 int vexpand = FALSE; 183 bool vexpand = false;
184 bool hfill = false;
185 bool vfill = false;
186 if(layout.fill != UI_LAYOUT_UNDEFINED) {
187 fill = ui_lb2bool(layout.fill);
188 }
184 if (layout.hexpand != UI_LAYOUT_UNDEFINED) { 189 if (layout.hexpand != UI_LAYOUT_UNDEFINED) {
185 hexpand = layout.hexpand; 190 hexpand = layout.hexpand;
191 hfill = true;
186 } 192 }
187 if (layout.vexpand != UI_LAYOUT_UNDEFINED) { 193 if (layout.vexpand != UI_LAYOUT_UNDEFINED) {
188 vexpand = layout.vexpand; 194 vexpand = layout.vexpand;
195 vfill = true;
196 }
197 if (fill) {
198 hfill = true;
199 vfill = true;
189 } 200 }
190 201
191 // create new RowDefinition for the new line 202 // create new RowDefinition for the new line
192 if (layout.newline || y == -1) { 203 if (layout.newline || y == -1) {
193 x = 0; 204 x = 0;
201 gl.GridUnitType = GridUnitType::Auto; 212 gl.GridUnitType = GridUnitType::Auto;
202 gl.Value = 0; 213 gl.Value = 0;
203 } 214 }
204 rowdef.Height(gl); 215 rowdef.Height(gl);
205 grid.RowDefinitions().Append(rowdef); 216 grid.RowDefinitions().Append(rowdef);
217 } else if (vexpand) {
218 // adjust row
219 gl.GridUnitType = GridUnitType::Star;
220 gl.Value = 1;
221 grid.RowDefinitions().GetAt(y).Height(gl);
206 } 222 }
207 223
208 // create new columndefinition, if a new column is added 224 // create new columndefinition, if a new column is added
209 if (x == cols) { 225 if (x == cols) {
210 if (hexpand) { 226 if (hexpand) {
217 } 233 }
218 ColumnDefinition coldef = ColumnDefinition(); 234 ColumnDefinition coldef = ColumnDefinition();
219 coldef.Width(gl); 235 coldef.Width(gl);
220 grid.ColumnDefinitions().Append(coldef); 236 grid.ColumnDefinitions().Append(coldef);
221 cols++; 237 cols++;
238 } else if(hexpand) {
239 // adjust column
240 if (layout.colspan == 0) {
241 gl.GridUnitType = GridUnitType::Star;
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 }
222 } 265 }
223 266
224 // add control 267 // add control
225 control.HorizontalAlignment(HorizontalAlignment::Stretch); 268 if (hfill) {
226 control.VerticalAlignment(VerticalAlignment::Stretch); 269 control.HorizontalAlignment(HorizontalAlignment::Stretch);
270 }
271 if (vfill) {
272 control.VerticalAlignment(VerticalAlignment::Stretch);
273 }
227 274
228 if (layout.colspan > 0) { 275 if (layout.colspan > 0) {
229 grid.SetColumnSpan(control, layout.colspan); 276 grid.SetColumnSpan(control, layout.colspan);
230 } 277 }
231 if (layout.rowspan > 0) { 278 if (layout.rowspan > 0) {
275 322
276 frame.SetRow(label, row++); 323 frame.SetRow(label, row++);
277 frame.SetColumn(label, 0); 324 frame.SetColumn(label, 0);
278 frame.Children().Append(label); 325 frame.Children().Append(label);
279 } 326 }
280 327
281 // workarea frame 328 // workarea frame
282 frame.RowDefinitions().Append(rowdefFrame); 329 frame.RowDefinitions().Append(rowdefFrame);
283 330
284 Grid workarea = Grid(); 331 Grid workarea = Grid();
285 frame.SetRow(workarea, row); 332 frame.SetRow(workarea, row);
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;
555 } 701 }
556 702
557 navigationview.SelectionChanged({ this, &UiNavigationTabView::SelectionChanged }); 703 navigationview.SelectionChanged({ this, &UiNavigationTabView::SelectionChanged });
558 } 704 }
559 705
560 UiObject* UiNavigationTabView::AddTab(const char* label) { 706 UiObject* UiNavigationTabView::AddTab(const char* label, int index1) {
561 TextBlock text = TextBlock(); 707 TextBlock text = TextBlock();
562 wchar_t* wlabel = str2wstr(label, nullptr); 708 wchar_t* wlabel = str2wstr(label, nullptr);
563 winrt::hstring hstr(wlabel); 709 winrt::hstring hstr(wlabel);
564 text.Text(hstr); 710 text.Text(hstr);
565 free(wlabel); 711 free(wlabel);
577 navigationview.MenuItems().Append(item); 723 navigationview.MenuItems().Append(item);
578 auto page = std::tuple<NavigationViewItem, FrameworkElement>{ item, subcontainer }; 724 auto page = std::tuple<NavigationViewItem, FrameworkElement>{ item, subcontainer };
579 pages.push_back(page); 725 pages.push_back(page);
580 726
581 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); 727 return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing);
728 }
729
730 void UiNavigationTabView::Remove(int index) {
731 navigationview.MenuItems().RemoveAt(index);
732 pages.erase(pages.begin() + index);
733 }
734
735 void UiNavigationTabView::Select(int index) {
736
582 } 737 }
583 738
584 FrameworkElement UiNavigationTabView::GetFrameworkElement() { 739 FrameworkElement UiNavigationTabView::GetFrameworkElement() {
585 return navigationview; 740 return navigationview;
586 } 741 }
594 break; 749 break;
595 } 750 }
596 } 751 }
597 } 752 }
598 753
599 static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { 754 static int64_t ui_tabview_get(UiInteger *i) {
600 NavigationView navigationview = NavigationView(); 755 return 0;
601 UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); 756 }
602 navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); 757
603 navigationview.IsSettingsVisible(false); 758 static void ui_tabview_set(UiInteger *i, int64_t value) {
604 759 UiTabView *tabview = (UiTabView*)i->obj;
605 return tabview; 760 tabview->Select(value);
606 } 761 }
607 762
608 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { 763 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
609 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;
610 UiTabView* tabview = nullptr; 765 UiTabView* tabview = nullptr;
627 } 782 }
628 case UI_TABVIEW_NAVIGATION_TOP2: { 783 case UI_TABVIEW_NAVIGATION_TOP2: {
629 tabview = tabview_pivot_create(obj, args); 784 tabview = tabview_pivot_create(obj, args);
630 break; 785 break;
631 } 786 }
787 case UI_TABVIEW_INVISIBLE: {
788 tabview = tabview_invisible_create(obj, args);
789 break;
790 }
632 } 791 }
633 UiTabViewContainer* ctn = new UiTabViewContainer(tabview); 792 UiTabViewContainer* ctn = new UiTabViewContainer(tabview);
634 793
635 // add frame to the parent container 794 // add frame to the parent container
636 UiObject* current = uic_current_obj(obj); 795 UiObject* current = uic_current_obj(obj);
639 798
640 UIElement elm = tabview->GetFrameworkElement(); 799 UIElement elm = tabview->GetFrameworkElement();
641 UiWidget* widget = new UiWidget(elm); 800 UiWidget* widget = new UiWidget(elm);
642 ui_context_add_widget_destructor(current->ctx, widget); 801 ui_context_add_widget_destructor(current->ctx, widget);
643 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 }
644 814
645 UiObject* newobj = uic_object_new(obj, widget); 815 UiObject* newobj = uic_object_new(obj, widget);
646 newobj->container = ctn; 816 newobj->container = ctn;
647 uic_obj_add(obj, newobj); 817 uic_obj_add(obj, newobj);
648 818
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;

mercurial