Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabView fixes #6632

Merged
merged 2 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,31 @@ void TabView::OnItemsPresenterSizeChanged(const winrt::IInspectable& sender, con
// Presenter size didn't change because of item being removed, so update manually
UpdateScrollViewerDecreaseAndIncreaseButtonsViewState();
UpdateTabWidths();
// Make sure that the selected tab is fully in view and not cut off
BringSelectedTabIntoView();
}
}

void TabView::BringSelectedTabIntoView()
{
if(SelectedItem())
{
auto tvi = SelectedItem().try_as<winrt::TabViewItem>();
if (!tvi)
{
tvi = ContainerFromItem(SelectedItem()).try_as<winrt::TabViewItem>();
}
winrt::get_self<TabViewItem>(tvi)->StartBringTabIntoView();
}
}

void TabView::OnItemsChanged(winrt::IInspectable const& item)
{
if(m_isDragging)
{
return;
}

if (auto args = item.as<winrt::IVectorChangedEventArgs>())
{
m_tabItemsChangedEventSource(*this, args);
Expand Down Expand Up @@ -762,8 +782,6 @@ void TabView::OnItemsChanged(winrt::IInspectable const& item)

void TabView::OnListViewSelectionChanged(const winrt::IInspectable& sender, const winrt::SelectionChangedEventArgs& args)
{


if (auto&& listView = m_listView.get())
{
SelectedIndex(listView.SelectedIndex());
Expand Down Expand Up @@ -832,6 +850,13 @@ void TabView::OnListViewDragItemsCompleted(const winrt::IInspectable& sender, co
{
m_isDragging = false;

// Selection change was disabled during drag, update SelectedIndex now
if (auto&& listView = m_listView.get())
{
SelectedIndex(listView.SelectedIndex());
SelectedItem(listView.SelectedItem());
}

auto item = args.Items().GetAt(0);
auto tab = FindTabViewItemFromDragItem(item);
auto myArgs = winrt::make_self<TabViewTabDragCompletedEventArgs>(args, item, tab);
Expand Down
1 change: 1 addition & 0 deletions dev/TabView/TabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class TabView :

bool RequestCloseCurrentTab();
bool SelectNextTab(int increment);
void BringSelectedTabIntoView();

void UpdateSelectedItem();
void UpdateSelectedIndex();
Expand Down
11 changes: 10 additions & 1 deletion dev/TabView/TabViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "SharedHelpers.h"

static constexpr auto c_overlayCornerRadiusKey = L"OverlayCornerRadius"sv;
static constexpr int c_targetRectWidthIncrement = 2;

TabViewItem::TabViewItem()
{
Expand Down Expand Up @@ -151,7 +152,7 @@ void TabViewItem::OnIsSelectedPropertyChanged(const winrt::DependencyObject& sen
if (IsSelected())
{
SetValue(winrt::Canvas::ZIndexProperty(), box_value(20));
StartBringIntoView();
StartBringTabIntoView();
}
else
{
Expand Down Expand Up @@ -501,3 +502,11 @@ void TabViewItem::OnIconSourceChanged()
winrt::VisualStateManager::GoToState(*this, L"NoIcon"sv, false);
}
}

void TabViewItem::StartBringTabIntoView()
{
// we need to set the TargetRect to be slightly wider than the TabViewItem size in order to avoid cutting off the end of the Tab
winrt::BringIntoViewOptions options;
options.TargetRect(winrt::Rect{ 0, 0, DesiredSize().Width + c_targetRectWidthIncrement, DesiredSize().Height});
StartBringIntoView(options);
}
2 changes: 2 additions & 0 deletions dev/TabView/TabViewItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TabViewItem :
winrt::TabView GetParentTabView();
void SetParentTabView(winrt::TabView const& tabView);

void StartBringTabIntoView();

private:
tracker_ref<winrt::Button> m_closeButton{ this };
tracker_ref<winrt::ToolTip> m_toolTip{ this };
Expand Down