From d8e587638e57081d0d217f0fdbea26be4620f71c Mon Sep 17 00:00:00 2001 From: PankajBhojwani Date: Thu, 7 Jan 2021 18:30:05 -0800 Subject: [PATCH] Improvements to the tab renamer box (#8589) 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 #8519 --- src/cascadia/TerminalApp/TabHeaderControl.h | 1 + src/cascadia/TerminalApp/TabHeaderControl.idl | 1 + .../TerminalApp/TabHeaderControl.xaml | 26 ++++++++++++++++--- src/cascadia/TerminalApp/TerminalTab.cpp | 26 +++++++++++++++++++ src/cascadia/TerminalApp/TerminalTab.h | 4 +++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 39744b2bcb0a..41c81fb783d3 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -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); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index 0fc8fc2da3ee..808b72067c4a 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -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; }; diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index 65e8b5ee7b96..ba8350d3b123 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -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"> + + + + + 0,0,0,1 + + + 0,0,0,1 + + + 0,0,0,1 + + + + + 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}"/> diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 3777f0ab19ee..8e7252c4e41d 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -50,6 +50,9 @@ namespace winrt::TerminalApp::implementation tab->SetTabText(title); } }); + + _UpdateHeaderControlMaxWidth(); + // Use our header control as the TabViewItem's header TabViewItem().Header(_headerControl); } @@ -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{}; @@ -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: diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index 1ae7ad2e6dd9..62783d5160e4 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -7,6 +7,9 @@ #include "TabBase.h" #include "TerminalTab.g.h" +static constexpr double HeaderRenameBoxWidthDefault{ 165 }; +static constexpr double HeaderRenameBoxWidthTitleLength{ std::numeric_limits::infinity() }; + // fwdecl unittest classes namespace TerminalAppLocalTests { @@ -102,6 +105,7 @@ namespace winrt::TerminalApp::implementation void _MakeTabViewItem(); + winrt::fire_and_forget _UpdateHeaderControlMaxWidth(); void _SetToolTip(const winrt::hstring& tabTitle); void _CreateContextMenu() override;