# HG changeset patch # User Olaf Wintermann # Date 1696335505 -7200 # Node ID 84e0a24bab4aea70c011d1b852c6e126e0a08a47 # Parent f2332d0d33180d18c41908d6c6d53c7cae090aa5 add main tabview based on WinUI TabView diff -r f2332d0d3318 -r 84e0a24bab4a ui/winui/container.cpp --- a/ui/winui/container.cpp Tue Oct 03 12:36:57 2023 +0200 +++ b/ui/winui/container.cpp Tue Oct 03 14:18:25 2023 +0200 @@ -487,9 +487,52 @@ return tabview; } +UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { + this->current = obj; + this->tabview = tabview; + this->margin = args.margin; + this->spacing = args.spacing; + this->columnspacing = args.columnspacing; + this->rowspacing = args.rowspacing; +} + +UiObject* UiMainTabView::AddTab(const char* label) { + TextBlock text = TextBlock(); + wchar_t* wlabel = str2wstr(label, nullptr); + winrt::hstring hstr(wlabel); + text.Text(hstr); + free(wlabel); + + TabViewItem item = TabViewItem(); + item.Header(text); + item.CanDrag(false); + item.IsClosable(false); + + // sub container + Grid subcontainer = Grid(); + item.Content(subcontainer); + tabview.TabItems().Append(item); + + return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); +} + +FrameworkElement UiMainTabView::GetFrameworkElement() { + return tabview; +} + +static UiTabView* tabview_doc_create(UiObject* obj, UiTabViewArgs args) { + TabView tabview = TabView(); + tabview.IsAddTabButtonVisible(false); + tabview.CanDragTabs(false); + tabview.CanReorderTabs(false); + UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); + + return uitabview; +} + UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { UiTabViewType type = args.tabview == UI_TABVIEW_DEFAULT ? UI_TABVIEW_NAVIGATION_TOP2 : args.tabview; - UiTabView *tabview = tabview_pivot_create(obj, args); + UiTabView *tabview = tabview_doc_create(obj, args); UiTabViewContainer* ctn = new UiTabViewContainer(tabview); // add frame to the parent container diff -r f2332d0d3318 -r 84e0a24bab4a ui/winui/container.h --- a/ui/winui/container.h Tue Oct 03 12:36:57 2023 +0200 +++ b/ui/winui/container.h Tue Oct 03 14:18:25 2023 +0200 @@ -109,7 +109,11 @@ struct UiTabView { UiObject* current; - int close = 0; + UiSubContainerType subcontainer; + int margin; + int spacing; + int columnspacing; + int rowspacing; virtual UiObject* AddTab(const char* label) = 0; @@ -126,14 +130,18 @@ struct UiPivotTabView : UiTabView { Pivot pivot; - UiSubContainerType subcontainer; - int margin; - int spacing; - int columnspacing; - int rowspacing; UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args); UiObject* AddTab(const char* label); FrameworkElement GetFrameworkElement(); }; + +struct UiMainTabView : UiTabView { + TabView tabview; + + UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args); + + UiObject* AddTab(const char* label); + FrameworkElement GetFrameworkElement(); +};