Skip to content

Commit

Permalink
Get rid of the padding above the tab row when maximized (#5881)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
zadjii-msft authored and DHowett committed Jun 24, 2020
1 parent b592d5b commit 6c25248
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
42 changes: 40 additions & 2 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,53 @@ namespace winrt::TerminalApp::implementation

void MinMaxCloseControl::SetWindowVisualState(WindowVisualState visualState)
{
// Look up the heights we should use for the caption buttons from our
// XAML resources. "CaptionButtonHeightWindowed" and
// "CaptionButtonHeightMaximized" define the size we should use for the
// caption buttons height for the windowed and maximized states,
// respectively.
//
// use C++11 magic statics to make sure we only do this once.
static auto heights = [this]() {
const auto res = Resources();
const auto windowedHeightKey = winrt::box_value(L"CaptionButtonHeightWindowed");
const auto maximizedHeightKey = winrt::box_value(L"CaptionButtonHeightMaximized");

auto windowedHeight = 0.0;
auto maximizedHeight = 0.0;
if (res.HasKey(windowedHeightKey))
{
const auto valFromResources = res.Lookup(windowedHeightKey);
windowedHeight = winrt::unbox_value_or<double>(valFromResources, 0.0);
}
if (res.HasKey(maximizedHeightKey))
{
const auto valFromResources = res.Lookup(maximizedHeightKey);
maximizedHeight = winrt::unbox_value_or<double>(valFromResources, 0.0);
}
return std::tuple<double, double>{ windowedHeight, maximizedHeight };
}();
static const auto windowedHeight = std::get<0>(heights);
static const auto maximizedHeight = std::get<1>(heights);

switch (visualState)
{
case WindowVisualState::WindowVisualStateMaximized:
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);

MinimizeButton().Height(maximizedHeight);
MaximizeButton().Height(maximizedHeight);
CloseButton().Height(maximizedHeight);
break;

case WindowVisualState::WindowVisualStateNormal:
case WindowVisualState::WindowVisualStateIconified:
default:
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);

MinimizeButton().Height(windowedHeight);
MaximizeButton().Height(windowedHeight);
CloseButton().Height(windowedHeight);
break;
}
}
Expand Down
20 changes: 17 additions & 3 deletions src/cascadia/TerminalApp/MinMaxCloseControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,26 @@ the MIT License. See LICENSE in the project root for license information. -->
<x:String x:Key="CaptionButtonPath"></x:String>
<x:String x:Key="CaptionButtonPathWindowMaximized"></x:String>

<!-- "CaptionButtonHeightWindowed" and
"CaptionButtonHeightMaximized" define the size we should use
for the caption buttons height for the windowed and maximized
states, respectively.
32 was chosen for the Maximized height to match the height of
the TabRowControl. This way, when the window is maximized, the
tabs will be flush with the top of the window. See GH#2541 for
details.-->
<x:Double x:Key="CaptionButtonHeightWindowed">36.0</x:Double>
<x:Double x:Key="CaptionButtonHeightMaximized">32.0</x:Double>

<Style x:Key="CaptionButton" TargetType="Button">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="{ThemeResource CaptionButtonBackground}" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">

<Border x:Name="ButtonBaseElement"
Background="{TemplateBinding Background}"
BackgroundSizing="{TemplateBinding BackgroundSizing}"
Expand Down Expand Up @@ -136,6 +149,7 @@ the MIT License. See LICENSE in the project root for license information. -->
StrokeEndLineCap="Square"
StrokeStartLineCap="Square" />
</Border>

</ControlTemplate>
</Setter.Value>
</Setter>
Expand All @@ -144,7 +158,7 @@ the MIT License. See LICENSE in the project root for license information. -->
</ResourceDictionary>
</StackPanel.Resources>

<Button Height="36.0" MinWidth="46.0" Width="46.0"
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
x:Name="MinimizeButton"
x:Uid="WindowMinimizeButton"
Style="{StaticResource CaptionButton}"
Expand All @@ -156,7 +170,7 @@ the MIT License. See LICENSE in the project root for license information. -->
</ResourceDictionary>
</Button.Resources>
</Button>
<Button Height="36.0" MinWidth="46.0" Width="46.0"
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
x:Name="MaximizeButton"
x:Uid="WindowMaximizeButton"
Style="{StaticResource CaptionButton}"
Expand All @@ -169,7 +183,7 @@ the MIT License. See LICENSE in the project root for license information. -->
</ResourceDictionary>
</Button.Resources>
</Button>
<Button Height="36.0" MinWidth="46.0" Width="46.0"
<Button Height="{StaticResource CaptionButtonHeightWindowed}" MinWidth="46.0" Width="46.0"
x:Name="CloseButton"
x:Uid="WindowCloseButton"
Style="{StaticResource CaptionButton}"
Expand Down

0 comments on commit 6c25248

Please sign in to comment.