Skip to content

Commit c373ebc

Browse files
authored
Get rid of the padding above the tab row when maximized (#5881)
## Summary of the Pull Request When we maximize the window, shrink the caption buttons (the min, max, close buttons) down to 32px tall, to be the same height as the `TabRowControl`. This way, the tabs will be flush with the top of the display. ## PR Checklist * [x] Closes #2541 * [x] I work here * [ ] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments I tried for a couple hours this morning to do this as a `VisualState`. First I tried doing it as one on the TabRow, which I had very little success with. Then, I eventually realized that the TabRow wasn't even responsible for the padding there, it was being created by the fact that the caption buttons were too tall. Again, I tried to use the existing `VisualState`s they have defined for this, but I couldn't figure out how to do that. I think the visual state solution would be _cleaner_, so if someone knows how to do that instead, please let me know. ## Validation Steps Performed * Maximized/restored the Terminal on my display with the taskbar on the bottom * Maximized/restored the Terminal on my display with the taskbar on the top
1 parent a472d21 commit c373ebc

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

src/cascadia/TerminalApp/MinMaxCloseControl.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,53 @@ namespace winrt::TerminalApp::implementation
4040

4141
void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
4242
{
43+
// Look up the heights we should use for the caption buttons from our
44+
// XAML resources. "CaptionButtonHeightWindowed" and
45+
// "CaptionButtonHeightMaximized" define the size we should use for the
46+
// caption buttons height for the windowed and maximized states,
47+
// respectively.
48+
//
49+
// use C++11 magic statics to make sure we only do this once.
50+
static auto heights = [this]() {
51+
const auto res = Resources();
52+
const auto windowedHeightKey = winrt::box_value(L"CaptionButtonHeightWindowed");
53+
const auto maximizedHeightKey = winrt::box_value(L"CaptionButtonHeightMaximized");
54+
55+
auto windowedHeight = 0.0;
56+
auto maximizedHeight = 0.0;
57+
if (res.HasKey(windowedHeightKey))
58+
{
59+
const auto valFromResources = res.Lookup(windowedHeightKey);
60+
windowedHeight = winrt::unbox_value_or<double>(valFromResources, 0.0);
61+
}
62+
if (res.HasKey(maximizedHeightKey))
63+
{
64+
const auto valFromResources = res.Lookup(maximizedHeightKey);
65+
maximizedHeight = winrt::unbox_value_or<double>(valFromResources, 0.0);
66+
}
67+
return std::tuple<double, double>{ windowedHeight, maximizedHeight };
68+
}();
69+
static const auto windowedHeight = std::get<0>(heights);
70+
static const auto maximizedHeight = std::get<1>(heights);
71+
4372
switch (visualState)
4473
{
4574
case WindowVisualState::WindowVisualStateMaximized:
46-
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
75+
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
76+
77+
MinimizeButton().Height(maximizedHeight);
78+
MaximizeButton().Height(maximizedHeight);
79+
CloseButton().Height(maximizedHeight);
4780
break;
81+
4882
case WindowVisualState::WindowVisualStateNormal:
4983
case WindowVisualState::WindowVisualStateIconified:
5084
default:
51-
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
85+
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
86+
87+
MinimizeButton().Height(windowedHeight);
88+
MaximizeButton().Height(windowedHeight);
89+
CloseButton().Height(windowedHeight);
5290
break;
5391
}
5492
}

src/cascadia/TerminalApp/MinMaxCloseControl.xaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,26 @@ the MIT License. See LICENSE in the project root for license information. -->
6262
<x:String x:Key="CaptionButtonPath"></x:String>
6363
<x:String x:Key="CaptionButtonPathWindowMaximized"></x:String>
6464

65+
<!-- "CaptionButtonHeightWindowed" and
66+
"CaptionButtonHeightMaximized" define the size we should use
67+
for the caption buttons height for the windowed and maximized
68+
states, respectively.
69+
70+
32 was chosen for the Maximized height to match the height of
71+
the TabRowControl. This way, when the window is maximized, the
72+
tabs will be flush with the top of the window. See GH#2541 for
73+
details.-->
74+
<x:Double x:Key="CaptionButtonHeightWindowed">36.0</x:Double>
75+
<x:Double x:Key="CaptionButtonHeightMaximized">32.0</x:Double>
76+
6577
<Style x:Key="CaptionButton" TargetType="Button">
6678
<Setter Property="BorderThickness" Value="0"/>
6779
<Setter Property="Background" Value="{ThemeResource CaptionButtonBackground}" />
6880
<Setter Property="IsTabStop" Value="False" />
6981
<Setter Property="Template">
7082
<Setter.Value>
7183
<ControlTemplate TargetType="Button">
84+
7285
<Border x:Name="ButtonBaseElement"
7386
Background="{TemplateBinding Background}"
7487
BackgroundSizing="{TemplateBinding BackgroundSizing}"
@@ -123,6 +136,7 @@ the MIT License. See LICENSE in the project root for license information. -->
123136
StrokeEndLineCap="Square"
124137
StrokeStartLineCap="Square" />
125138
</Border>
139+
126140
</ControlTemplate>
127141
</Setter.Value>
128142
</Setter>
@@ -131,7 +145,7 @@ the MIT License. See LICENSE in the project root for license information. -->
131145
</ResourceDictionary>
132146
</StackPanel.Resources>
133147

134-
<Button Height="36.0" MinWidth="46.0" Width="46.0"
148+
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
135149
x:Name="MinimizeButton"
136150
x:Uid="WindowMinimizeButton"
137151
Style="{StaticResource CaptionButton}"
@@ -143,7 +157,7 @@ the MIT License. See LICENSE in the project root for license information. -->
143157
</ResourceDictionary>
144158
</Button.Resources>
145159
</Button>
146-
<Button Height="36.0" MinWidth="46.0" Width="46.0"
160+
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
147161
x:Name="MaximizeButton"
148162
x:Uid="WindowMaximizeButton"
149163
Style="{StaticResource CaptionButton}"
@@ -156,7 +170,7 @@ the MIT License. See LICENSE in the project root for license information. -->
156170
</ResourceDictionary>
157171
</Button.Resources>
158172
</Button>
159-
<Button Height="36.0" MinWidth="46.0" Width="46.0"
173+
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
160174
x:Name="CloseButton"
161175
x:Uid="WindowCloseButton"
162176
Style="{StaticResource CaptionButton}"

0 commit comments

Comments
 (0)