Skip to content

Commit

Permalink
Fix to sizing issue when TabView is aligned left. (#1744)
Browse files Browse the repository at this point in the history
Fix to sizing issue when TabView is aligned left. Added test.
  • Loading branch information
teaP authored and jevansaks committed Dec 11, 2019
1 parent 99e9caa commit 7f352d8
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
32 changes: 32 additions & 0 deletions dev/TabView/InteractionTests/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,38 @@ public void CloseButtonDoesNotShowWhenVisibilityIsToggled()
}
}

[TestMethod]
public void SizingTest()
{
using (var setup = new TestSetupHelper("TabView Tests"))
{
Button sizingPageButton = FindElement.ByName<Button>("TabViewSizingPageButton");
sizingPageButton.InvokeAndWait();
Wait.ForMilliseconds(200);
ElementCache.Refresh();

Button setSmallWidthButton = FindElement.ByName<Button>("SetSmallWidth");
setSmallWidthButton.InvokeAndWait();

Button getWidthsButton = FindElement.ByName<Button>("GetWidthsButton");
getWidthsButton.InvokeAndWait();

TextBlock widthEqualText = FindElement.ByName<TextBlock>("WidthEqualText");
TextBlock widthSizeToContentText = FindElement.ByName<TextBlock>("WidthSizeToContentText");

Verify.AreEqual("400", widthEqualText.DocumentText);
Verify.AreEqual("400", widthSizeToContentText.DocumentText);

Button setLargeWidthButton = FindElement.ByName<Button>("SetLargeWidth");
setLargeWidthButton.InvokeAndWait();

getWidthsButton.InvokeAndWait();

Verify.AreEqual("700", widthEqualText.DocumentText);
Verify.AreEqual("700", widthSizeToContentText.DocumentText);
}
}

public void PressButtonAndVerifyText(String buttonName, String textBlockName, String expectedText)
{
Button button = FindElement.ByName<Button>(buttonName);
Expand Down
13 changes: 6 additions & 7 deletions dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ TabView::TabView()
SetDefaultStyleKey(this);

Loaded({ this, &TabView::OnLoaded });
SizeChanged({ this, &TabView::OnSizeChanged });

// KeyboardAccelerator is only available on RS3+
if (SharedHelpers::IsRS3OrHigher())
Expand Down Expand Up @@ -311,11 +310,6 @@ void TabView::OnScrollViewerLoaded(const winrt::IInspectable&, const winrt::Rout
UpdateTabWidths();
}

void TabView::OnSizeChanged(const winrt::IInspectable&, const winrt::SizeChangedEventArgs&)
{
UpdateTabWidths();
}

void TabView::OnItemsPresenterSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args)
{
UpdateTabWidths();
Expand Down Expand Up @@ -534,7 +528,12 @@ void TabView::OnScrollIncreaseClick(const winrt::IInspectable&, const winrt::Rou

winrt::Size TabView::MeasureOverride(winrt::Size const& availableSize)
{
previousAvailableSize = availableSize;
if (previousAvailableSize.Width != availableSize.Width)
{
previousAvailableSize = availableSize;
UpdateTabWidths();
}

return __super::MeasureOverride(availableSize);
}

Expand Down
1 change: 0 additions & 1 deletion dev/TabView/TabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class TabView :
void OnAddButtonClick(const winrt::IInspectable& sender, const winrt::RoutedEventArgs& args);
void OnScrollDecreaseClick(const winrt::IInspectable& sender, const winrt::RoutedEventArgs& args);
void OnScrollIncreaseClick(const winrt::IInspectable& sender, const winrt::RoutedEventArgs& args);
void OnSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args);
void OnItemsPresenterSizeChanged(const winrt::IInspectable& sender, const winrt::SizeChangedEventArgs& args);

void OnListViewLoaded(const winrt::IInspectable& sender, const winrt::RoutedEventArgs& args);
Expand Down
80 changes: 78 additions & 2 deletions dev/TabView/TestUI/TabViewSizingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid x:Name="LayoutRoot" >

<StackPanel Margin="50" Background="Silver">
<StackPanel Orientation="Horizontal">
<Button x:Name="SetSmallWidth" AutomationProperties.Name="SetSmallWidth" Content="Small Width" Click="SetSmallWidth_Click" Margin="0,0,12,0"/>
<Button x:Name="SetLargeWidth" AutomationProperties.Name="SetLargeWidth" Content="Large Width" Click="SetLargeWidth_Click" Margin="0,0,12,0"/>
<Button x:Name="GetWidthsButton" AutomationProperties.Name="GetWidthsButton" Content="Get Widths" Click="GetWidthsButton_Click" Margin="0,0,12,0"/>
<TextBlock x:Name="WidthEqualText" AutomationProperties.Name="WidthEqualText" Margin="0,0,12,0"/>
<TextBlock x:Name="WidthSizeToContentText" AutomationProperties.Name="WidthSizeToContentText"/>
</StackPanel>

<StackPanel Margin="50" Background="Silver" >
<TextBlock Text="SizeToContent, Auto Column Width" />
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -128,6 +136,74 @@
</controls:TabView>
</Grid>

<TextBlock Text="HorizonalAlignment = Left, Equal tab widths" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:TabView x:Name="TabViewEqual" AutomationProperties.Name="TabViewEqual" HorizontalAlignment="Left" TabWidthMode="Equal" TabCloseRequested="Tabs_TabCloseRequested" AddTabButtonClick="Tabview_AddTabButtonClick" >
<controls:TabView.TabItems>
<controls:TabViewItem Header="Tab A">
<TextBlock>TabA</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab B">
<TextBlock>TabB</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab C">
<TextBlock>TabC</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab D">
<TextBlock>TabD</TextBlock>
</controls:TabViewItem>
</controls:TabView.TabItems>
<controls:TabView.TabStripFooter>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Middle" Margin="6,3,6,0" VerticalAlignment="Center"/>
<TextBlock Grid.Column="2" Text="Right" Margin="6,3,6,0" VerticalAlignment="Center"/>
</Grid>
</controls:TabView.TabStripFooter>
</controls:TabView>
</Grid>

<TextBlock Text="HorizonalAlignment = Left, SizeToContent tabs" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:TabView x:Name="TabViewSizeToContent" AutomationProperties.Name="TabViewSizeToContent" HorizontalAlignment="Left" TabWidthMode="SizeToContent" TabCloseRequested="Tabs_TabCloseRequested" AddTabButtonClick="Tabview_AddTabButtonClick" >
<controls:TabView.TabItems>
<controls:TabViewItem Header="Tab A Long Name">
<TextBlock>TabA</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab B Even Longer Name">
<TextBlock>TabB</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab C Super Super Long Name">
<TextBlock>TabC</TextBlock>
</controls:TabViewItem>
<controls:TabViewItem Header="Tab D Reasonably Long Too">
<TextBlock>TabD</TextBlock>
</controls:TabViewItem>
</controls:TabView.TabItems>
<controls:TabView.TabStripFooter>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Middle" Margin="6,3,6,0" VerticalAlignment="Center"/>
<TextBlock Grid.Column="2" Text="Right" Margin="6,3,6,0" VerticalAlignment="Center"/>
</Grid>
</controls:TabView.TabStripFooter>
</controls:TabView>
</Grid>

</StackPanel>

</Grid>
Expand Down
16 changes: 16 additions & 0 deletions dev/TabView/TestUI/TabViewSizingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ public TabViewSizingPage()

int _newTabNumber = 1;

private void SetSmallWidth_Click(object sender, object args)
{
LayoutRoot.Width = 500;
}

private void SetLargeWidth_Click(object sender, object args)
{
LayoutRoot.Width = 800;
}

private void GetWidthsButton_Click(object sender, object args)
{
WidthEqualText.Text = TabViewEqual.ActualWidth.ToString();
WidthSizeToContentText.Text = TabViewSizeToContent.ActualWidth.ToString();
}

private void Tabview_AddTabButtonClick(TabView sender, object args)
{
TabViewItem item = new TabViewItem();
Expand Down

0 comments on commit 7f352d8

Please sign in to comment.