Simplify title bar (#442)
Fixes #407 (partially) and #441 Description of the changes: Remove TitleBarHelper and all <Border x:Name="CustomTitleBar" /> Let the system defines the draggable region Centralize all events and functions associated to the title bar in a single control TitleBar instead of code splitted between MainPage/TitleBar/HistoryList/Memory. Use the standard title bar when high contrast is activated instead of the custom one. Modify the color of the title when the window doesn't have focus Fix the right padding of the title bar with high contrast How changes were validated: Manually tested with LtR and RtL languages Manually tested with high contrast Tested when History and Memory flyout are opened
This commit is contained in:
committed by
Daniel Belcher
parent
0d31d5a5a2
commit
bd04c92c1c
@@ -1,94 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "TitleBarHelper.h"
|
||||
#include "Converters/BooleanToVisibilityConverter.h"
|
||||
#include "CalcViewModel/ViewState.h"
|
||||
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::Converters;
|
||||
using namespace Platform;
|
||||
using namespace std;
|
||||
using namespace Windows::ApplicationModel::Core;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::UI::Xaml;
|
||||
|
||||
unique_ptr<TitleBarHelper> TitleBarHelper::CreateTitleBarHelperIfNotDocked(FrameworkElement^ customTitleBar)
|
||||
{
|
||||
return (App::GetAppViewState() == ViewState::DockedView)
|
||||
? nullptr
|
||||
: CalculatorApp::Common::TitleBarHelper::CreateTitleBarHelper(customTitleBar);
|
||||
}
|
||||
|
||||
unique_ptr<TitleBarHelper> TitleBarHelper::CreateTitleBarHelper(_In_ FrameworkElement^ customTitleBar)
|
||||
{
|
||||
assert(customTitleBar != nullptr);
|
||||
if (customTitleBar != nullptr)
|
||||
{
|
||||
CoreApplicationViewTitleBar^ coreTitleBar = CoreApplication::GetCurrentView()->TitleBar;
|
||||
assert(coreTitleBar != nullptr);
|
||||
if (coreTitleBar != nullptr)
|
||||
{
|
||||
return make_unique<TitleBarHelper>(coreTitleBar, customTitleBar);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TitleBarHelper::TitleBarHelper(_In_ CoreApplicationViewTitleBar^ coreTitleBar, _In_ FrameworkElement^ customTitleBar) :
|
||||
m_coreTitleBar(coreTitleBar),
|
||||
m_customTitleBar(customTitleBar)
|
||||
{
|
||||
RegisterForLayoutChanged();
|
||||
RegisterForVisibilityChanged();
|
||||
SetCustomTitleBar();
|
||||
}
|
||||
|
||||
TitleBarHelper::~TitleBarHelper()
|
||||
{
|
||||
m_coreTitleBar->LayoutMetricsChanged -= m_layoutChangedToken;
|
||||
m_coreTitleBar->IsVisibleChanged -= m_visibilityChangedToken;
|
||||
}
|
||||
|
||||
void TitleBarHelper::SetTitleBarHeight(double height)
|
||||
{
|
||||
m_customTitleBar->Height = height;
|
||||
}
|
||||
|
||||
void TitleBarHelper::SetTitleBarVisibility(bool isVisible)
|
||||
{
|
||||
m_customTitleBar->Visibility = BooleanToVisibilityConverter::Convert(isVisible);
|
||||
}
|
||||
|
||||
void TitleBarHelper::RegisterForLayoutChanged()
|
||||
{
|
||||
m_layoutChangedToken =
|
||||
m_coreTitleBar->LayoutMetricsChanged += ref new TypedEventHandler<CoreApplicationViewTitleBar^, Object^>(
|
||||
[this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
|
||||
{
|
||||
// Update title bar control size as needed to account for system size changes
|
||||
SetTitleBarHeight(cTitleBar->Height);
|
||||
});
|
||||
}
|
||||
|
||||
void TitleBarHelper::RegisterForVisibilityChanged()
|
||||
{
|
||||
m_visibilityChangedToken =
|
||||
m_coreTitleBar->IsVisibleChanged += ref new TypedEventHandler<CoreApplicationViewTitleBar^, Object^>(
|
||||
[this](CoreApplicationViewTitleBar^ cTitleBar, Object^)
|
||||
{
|
||||
// Update title bar visibility
|
||||
SetTitleBarVisibility(cTitleBar->IsVisible);
|
||||
});
|
||||
}
|
||||
|
||||
void TitleBarHelper::SetCustomTitleBar()
|
||||
{
|
||||
// Set custom XAML Title Bar
|
||||
m_coreTitleBar->ExtendViewIntoTitleBar = true;
|
||||
SetTitleBarHeight(m_coreTitleBar->Height);
|
||||
SetTitleBarVisibility(m_coreTitleBar->IsVisible);
|
||||
Window::Current->SetTitleBar(m_customTitleBar);
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
namespace Common
|
||||
{
|
||||
class TitleBarHelper
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<TitleBarHelper> CreateTitleBarHelperIfNotDocked(
|
||||
_In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
|
||||
|
||||
// Prefer CreateTitleBarHelper over constructing your own instance,
|
||||
// because Create* will nullcheck the parameters.
|
||||
static std::unique_ptr<TitleBarHelper> CreateTitleBarHelper(
|
||||
_In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
|
||||
|
||||
TitleBarHelper(
|
||||
_In_ Windows::ApplicationModel::Core::CoreApplicationViewTitleBar^ coreTitleBar,
|
||||
_In_ Windows::UI::Xaml::FrameworkElement^ customTitleBar);
|
||||
~TitleBarHelper();
|
||||
|
||||
void SetTitleBarHeight(double height);
|
||||
void SetTitleBarVisibility(bool isVisible);
|
||||
|
||||
private:
|
||||
void RegisterForLayoutChanged();
|
||||
void RegisterForVisibilityChanged();
|
||||
void SetCustomTitleBar();
|
||||
|
||||
Platform::Agile<Windows::ApplicationModel::Core::CoreApplicationViewTitleBar^> m_coreTitleBar;
|
||||
Windows::UI::Xaml::FrameworkElement^ m_customTitleBar;
|
||||
Windows::Foundation::EventRegistrationToken m_layoutChangedToken;
|
||||
Windows::Foundation::EventRegistrationToken m_visibilityChangedToken;
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user