Skip to content

Commit

Permalink
Improvements to the tab renamer box (microsoft#8589)
Browse files Browse the repository at this point in the history
Basically, just impose a height on both the renamer box and the overall
tab header control. However, to ensure that the text in the tab renamer
box does not get clipped by its own border, we also need to set its font
size, which is slightly smaller than it was before but it _is_ the same
as the text block that it is trying to rename so I'd say its more
consistent now.

We also improve the tab renamer box so that it scrolls as more text is
added instead of getting truncated (when the tabWidthMode is anything
other than titleLength). When the tabWidthMode _is_ set to titleLength,
the renamer box can increase in length much more (see GIFs below).

Closes microsoft#8519
  • Loading branch information
PankajBhojwani authored and mpela81 committed Jan 28, 2021
1 parent b5d7341 commit d8e5876
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TabHeaderControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace winrt::TerminalApp::implementation
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(bool, IsPaneZoomed, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(double, RenamerMaxWidth, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(bool, IsProgressRingActive, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(bool, IsProgressRingIndeterminate, _PropertyChangedHandlers);
OBSERVABLE_GETSET_PROPERTY(uint32_t, ProgressValue, _PropertyChangedHandlers);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TabHeaderControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TerminalApp
{
String Title { get; set; };
Boolean IsPaneZoomed { get; set; };
Double RenamerMaxWidth { get; set; };
Boolean IsProgressRingActive { get; set; };
Boolean IsProgressRingIndeterminate { get; set; };
UInt32 ProgressValue { get; set; };
Expand Down
26 changes: 23 additions & 3 deletions src/cascadia/TerminalApp/TabHeaderControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,25 @@ the MIT License. See LICENSE in the project root for license information. -->
xmlns:mux="using:Microsoft.UI.Xaml.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
mc:Ignorable="d"
MinHeight="16">

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,1</Thickness>
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,1</Thickness>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,1</Thickness>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</UserControl.Resources>

<StackPanel x:Name="HeaderStackPanel"
Orientation="Horizontal">
<mux:ProgressRing x:Name="HeaderProgressRing"
Expand Down Expand Up @@ -39,8 +56,11 @@ the MIT License. See LICENSE in the project root for license information. -->
Visibility="Collapsed"
MinHeight="0"
Padding="4,0,4,0"
Margin="0,-8,0,-8"
MaxLength="1024"
LostFocus="RenameBoxLostFocusHandler"/>
LostFocus="RenameBoxLostFocusHandler"
Height="16"
FontSize="12"
IsSpellCheckEnabled="False"
MaxWidth="{x:Bind RenamerMaxWidth, Mode=OneWay}"/>
</StackPanel>
</UserControl>
26 changes: 26 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace winrt::TerminalApp::implementation
tab->SetTabText(title);
}
});

_UpdateHeaderControlMaxWidth();

// Use our header control as the TabViewItem's header
TabViewItem().Header(_headerControl);
}
Expand All @@ -75,6 +78,26 @@ namespace winrt::TerminalApp::implementation
_RecalculateAndApplyTabColor();
}

winrt::fire_and_forget TerminalTab::_UpdateHeaderControlMaxWidth()
{
auto weakThis{ get_weak() };

co_await winrt::resume_foreground(TabViewItem().Dispatcher());

if (auto tab{ weakThis.get() })
{
const auto settings{ winrt::TerminalApp::implementation::AppLogic::CurrentAppSettings() };
if (settings.GlobalSettings().TabWidthMode() == winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::SizeToContent)
{
tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthTitleLength);
}
else
{
tab->_headerControl.RenamerMaxWidth(HeaderRenameBoxWidthDefault);
}
}
}

void TerminalTab::_SetToolTip(const winrt::hstring& tabTitle)
{
WUX::Controls::ToolTip toolTip{};
Expand Down Expand Up @@ -169,6 +192,9 @@ namespace winrt::TerminalApp::implementation
void TerminalTab::UpdateSettings(const winrt::TerminalApp::TerminalSettings& settings, const GUID& profile)
{
_rootPane->UpdateSettings(settings, profile);

// The tabWidthMode may have changed, update the header control accordingly
_UpdateHeaderControlMaxWidth();
}

// Method Description:
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "TabBase.h"
#include "TerminalTab.g.h"

static constexpr double HeaderRenameBoxWidthDefault{ 165 };
static constexpr double HeaderRenameBoxWidthTitleLength{ std::numeric_limits<double>::infinity() };

// fwdecl unittest classes
namespace TerminalAppLocalTests
{
Expand Down Expand Up @@ -102,6 +105,7 @@ namespace winrt::TerminalApp::implementation

void _MakeTabViewItem();

winrt::fire_and_forget _UpdateHeaderControlMaxWidth();
void _SetToolTip(const winrt::hstring& tabTitle);

void _CreateContextMenu() override;
Expand Down

0 comments on commit d8e5876

Please sign in to comment.