c373ebcd8d
## 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
99 lines
4 KiB
C++
99 lines
4 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
//
|
|
// MinMaxCloseControl.xaml.cpp
|
|
// Implementation of the MinMaxCloseControl class
|
|
//
|
|
|
|
#include "pch.h"
|
|
|
|
#include "MinMaxCloseControl.h"
|
|
|
|
#include "MinMaxCloseControl.g.cpp"
|
|
using namespace winrt::Windows::UI::Xaml;
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
MinMaxCloseControl::MinMaxCloseControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
// These event handlers simply forward each buttons click events up to the
|
|
// events we've exposed.
|
|
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
|
|
RoutedEventArgs const& e)
|
|
{
|
|
_minimizeClickHandlers(*this, e);
|
|
}
|
|
|
|
void MinMaxCloseControl::_MaximizeClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
|
|
RoutedEventArgs const& e)
|
|
{
|
|
_maximizeClickHandlers(*this, e);
|
|
}
|
|
void MinMaxCloseControl::_CloseClick(winrt::Windows::Foundation::IInspectable const& /*sender*/,
|
|
RoutedEventArgs const& e)
|
|
{
|
|
_closeClickHandlers(*this, e);
|
|
}
|
|
|
|
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:
|
|
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
|
|
|
|
MinimizeButton().Height(maximizedHeight);
|
|
MaximizeButton().Height(maximizedHeight);
|
|
CloseButton().Height(maximizedHeight);
|
|
break;
|
|
|
|
case WindowVisualState::WindowVisualStateNormal:
|
|
case WindowVisualState::WindowVisualStateIconified:
|
|
default:
|
|
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
|
|
|
|
MinimizeButton().Height(windowedHeight);
|
|
MaximizeButton().Height(windowedHeight);
|
|
CloseButton().Height(windowedHeight);
|
|
break;
|
|
}
|
|
}
|
|
|
|
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
|
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
|
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
|
|
|
|
}
|