Skip to content

Commit 6c25248

Browse files
zadjii-msftDHowett
authored andcommitted
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 (cherry picked from commit c373ebc)
1 parent b592d5b commit 6c25248

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
@@ -61,13 +61,26 @@ the MIT License. See LICENSE in the project root for license information. -->
6161
<x:String x:Key="CaptionButtonPath"></x:String>
6262
<x:String x:Key="CaptionButtonPathWindowMaximized"></x:String>
6363

64+
<!-- "CaptionButtonHeightWindowed" and
65+
"CaptionButtonHeightMaximized" define the size we should use
66+
for the caption buttons height for the windowed and maximized
67+
states, respectively.
68+
69+
32 was chosen for the Maximized height to match the height of
70+
the TabRowControl. This way, when the window is maximized, the
71+
tabs will be flush with the top of the window. See GH#2541 for
72+
details.-->
73+
<x:Double x:Key="CaptionButtonHeightWindowed">36.0</x:Double>
74+
<x:Double x:Key="CaptionButtonHeightMaximized">32.0</x:Double>
75+
6476
<Style x:Key="CaptionButton" TargetType="Button">
6577
<Setter Property="BorderThickness" Value="0"/>
6678
<Setter Property="Background" Value="{ThemeResource CaptionButtonBackground}" />
6779
<Setter Property="IsTabStop" Value="False" />
6880
<Setter Property="Template">
6981
<Setter.Value>
7082
<ControlTemplate TargetType="Button">
83+
7184
<Border x:Name="ButtonBaseElement"
7285
Background="{TemplateBinding Background}"
7386
BackgroundSizing="{TemplateBinding BackgroundSizing}"
@@ -136,6 +149,7 @@ the MIT License. See LICENSE in the project root for license information. -->
136149
StrokeEndLineCap="Square"
137150
StrokeStartLineCap="Square" />
138151
</Border>
152+
139153
</ControlTemplate>
140154
</Setter.Value>
141155
</Setter>
@@ -144,7 +158,7 @@ the MIT License. See LICENSE in the project root for license information. -->
144158
</ResourceDictionary>
145159
</StackPanel.Resources>
146160

147-
<Button Height="36.0" MinWidth="46.0" Width="46.0"
161+
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
148162
x:Name="MinimizeButton"
149163
x:Uid="WindowMinimizeButton"
150164
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="MaximizeButton"
161175
x:Uid="WindowMaximizeButton"
162176
Style="{StaticResource CaptionButton}"
@@ -169,7 +183,7 @@ the MIT License. See LICENSE in the project root for license information. -->
169183
</ResourceDictionary>
170184
</Button.Resources>
171185
</Button>
172-
<Button Height="36.0" MinWidth="46.0" Width="46.0"
186+
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
173187
x:Name="CloseButton"
174188
x:Uid="WindowCloseButton"
175189
Style="{StaticResource CaptionButton}"

0 commit comments

Comments
 (0)