General improvement of the title bar for Always-On-Top. (#634)

* Make sure TitleBar takes into account the AOT mode change

* remove namespaces in cpp files

* code linting

* use macro for IsAlwaysOnTop and make IsAlwaysOnTop/DisplayNormalAlwaysOnTopOption read-only

* Fix FontWeight
This commit is contained in:
Rudy Huyn 2019-08-23 13:42:00 -07:00 committed by Stephanie Anderl
parent 5b2d976e64
commit eb24c085bc
7 changed files with 57 additions and 58 deletions

View File

@ -23,10 +23,11 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel ^, DateCalcViewModel);
OBSERVABLE_PROPERTY_RW(UnitConverterViewModel ^, ConverterViewModel);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode);
OBSERVABLE_PROPERTY_R(bool, IsAlwaysOnTop);
OBSERVABLE_NAMED_PROPERTY_RW(Platform::String ^, CategoryName);
// Indicates whether calculator is currently in standard mode _and_ supports CompactOverlay _and_ is not in Always-on-Top mode
OBSERVABLE_PROPERTY_RW(bool, DisplayNormalAlwaysOnTopOption);
OBSERVABLE_PROPERTY_R(bool, DisplayNormalAlwaysOnTopOption);
COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand);
COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand);
@ -91,22 +92,6 @@ namespace CalculatorApp
}
}
property bool IsAlwaysOnTop
{
bool get()
{
return m_isAlwaysOnTop;
}
void set(bool value)
{
if (m_isAlwaysOnTop != value)
{
m_isAlwaysOnTop = value;
RaisePropertyChanged(L"IsAlwaysOnTop");
}
}
}
void ToggleAlwaysOnTop(float width, float height);
private:
@ -123,8 +108,6 @@ namespace CalculatorApp
Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup ^> ^ m_categories;
Concurrency::task<void> HandleToggleAlwaysOnTop(float width, float height);
void SetDisplayNormalAlwaysOnTopOption();
bool m_isAlwaysOnTop;
};
}
}

View File

@ -86,8 +86,8 @@
Command="{x:Bind Model.PasteCommand}"/>
</StackPanel>
<local:TitleBar x:Name="CustomTitleBar" Grid.Row="0"
ApplicationViewModel="{x:Bind Model}"/>
<local:TitleBar Grid.Row="0" IsAlwaysOnTopMode="{x:Bind Model.IsAlwaysOnTop, Mode=OneWay}"
AlwaysOnTopClick="TitleBarAlwaysOnTopButtonClick"/>
<Grid Grid.Row="1">
<Border x:Name="CalcHolder">

View File

@ -546,7 +546,13 @@ void MainPage::OnNavItemInvoked(MUXC::NavigationView ^ /*sender*/, _In_ MUXC::Na
NavView->IsPaneOpen = false;
}
void MainPage::AlwaysOnTopButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
void MainPage::TitleBarAlwaysOnTopButtonClick(_In_ Object ^ /*sender*/, _In_ RoutedEventArgs ^ /*e*/)
{
auto bounds = Window::Current->Bounds;
Model->ToggleAlwaysOnTop(bounds.Width, bounds.Height);
}
void MainPage::AlwaysOnTopButtonClick(_In_ Object ^ /*sender*/, _In_ RoutedEventArgs ^ /*e*/)
{
Model->ToggleAlwaysOnTop(0, 0);
}

View File

@ -57,6 +57,7 @@ public
void OnAboutFlyoutOpened(_In_ Platform::Object ^ sender, _In_ Platform::Object ^ e);
void OnAboutFlyoutClosed(_In_ Platform::Object ^ sender, _In_ Platform::Object ^ e);
void AlwaysOnTopButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void TitleBarAlwaysOnTopButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
Microsoft::UI::Xaml::Controls::NavigationViewItemHeader ^ CreateNavViewHeaderFromGroup(CalculatorApp::Common::NavCategoryGroup ^ group);
Microsoft::UI::Xaml::Controls::NavigationViewItem ^ CreateNavViewItemFromCategory(CalculatorApp::Common::NavCategory ^ category);

View File

@ -3,11 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="using:CalculatorApp.Converters"
mc:Ignorable="d">
<UserControl.Resources>
<converters:BooleanToVisibilityNegationConverter x:Key="BooleanToVisibilityNegationConverter"/>
</UserControl.Resources>
<Grid x:Name="LayoutRoot"
Height="32"
HorizontalAlignment="Stretch">
@ -20,10 +16,19 @@
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="AOTStates">
<VisualState x:Name="AOTNormalState"/>
<VisualState x:Name="AOTMiniState">
<VisualState.Setters>
<Setter Target="AppName.Visibility" Value="Collapsed"/>
<Setter Target="ExitAlwaysOnTopButton.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="BackgroundElement"
Background="Transparent"
Height="32">
Height="32"
Background="Transparent">
<TextBlock x:Name="AppName"
x:Uid="AppName"
Margin="12,0,12,0"
@ -32,25 +37,23 @@
Foreground="{ThemeResource TitleBarForegroundBaseHighBrush}"
FontSize="12"
TextAlignment="Left"
TextTrimming="CharacterEllipsis"
Visibility="{x:Bind ApplicationViewModel.IsAlwaysOnTop, Converter={StaticResource BooleanToVisibilityNegationConverter}, Mode=OneWay}"/>
TextTrimming="CharacterEllipsis"/>
</Grid>
<Button x:Name="AoTAlwaysOnTopButton"
<Button x:Name="ExitAlwaysOnTopButton"
x:Uid="ExitAlwaysOnTopButton"
Grid.Row="0"
FontFamily="{StaticResource CalculatorFontFamily}"
Style="{ThemeResource CommandBarFlyoutEllipsisButtonStyle}"
Content="&#xEE47;"
Click="AlwaysOnTopButtonClick"
Width="46"
Height="32"
Height="Auto"
HorizontalAlignment="Left"
HorizontalContentAlignment="Center"
Style="{ThemeResource CommandBarFlyoutEllipsisButtonStyle}"
Background="Transparent"
FontWeight="Thin"
FontFamily="{StaticResource CalculatorFontFamily}"
FontSize="14"
AllowFocusWhenDisabled="False"
Visibility="{x:Bind ApplicationViewModel.IsAlwaysOnTop, Mode=OneWay}"
AutomationProperties.AutomationId="AoTAlwaysOnTopButton"/>
FontWeight="Thin"
x:Load="False"
AutomationProperties.AutomationId="ExitAlwaysOnTopButton"
Click="AlwaysOnTopButton_Click"
Content="&#xEE47;"
Visibility="Collapsed"/>
</Grid>
</UserControl>

View File

@ -22,7 +22,7 @@ using namespace Concurrency;
namespace CalculatorApp
{
DEPENDENCY_PROPERTY_INITIALIZATION(TitleBar, ApplicationViewModel);
DEPENDENCY_PROPERTY_INITIALIZATION(TitleBar, IsAlwaysOnTopMode);
TitleBar::TitleBar()
: m_coreTitleBar(CoreApplication::GetCurrentView()->TitleBar)
@ -82,10 +82,9 @@ namespace CalculatorApp
m_windowActivatedToken.Value = 0;
}
void TitleBar::SetTitleBarVisibility()
{
this->LayoutRoot->Visibility = m_coreTitleBar->IsVisible || ApplicationViewModel->IsAlwaysOnTop ? ::Visibility::Visible : ::Visibility::Collapsed;
this->LayoutRoot->Visibility = m_coreTitleBar->IsVisible || IsAlwaysOnTopMode ? ::Visibility::Visible : ::Visibility::Collapsed;
}
void TitleBar::SetTitleBarPadding()
@ -173,9 +172,14 @@ namespace CalculatorApp
this, e->WindowActivationState == CoreWindowActivationState::Deactivated ? WindowNotFocused->Name : WindowFocused->Name, false);
}
void TitleBar::AlwaysOnTopButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
void TitleBar::OnIsAlwaysOnTopModePropertyChanged(bool /*oldValue*/, bool newValue)
{
auto bounds = Window::Current->Bounds;
ApplicationViewModel->ToggleAlwaysOnTop(bounds.Width, bounds.Height);
SetTitleBarVisibility();
VisualStateManager::GoToState(this, newValue ? "AOTMiniState" : "AOTNormalState", false);
}
void TitleBar::AlwaysOnTopButton_Click(_In_ Object ^ /*sender*/, _In_ RoutedEventArgs ^ e)
{
AlwaysOnTopClick(this, e);
}
}

View File

@ -20,8 +20,9 @@ public
TitleBar();
DEPENDENCY_PROPERTY_OWNER(TitleBar);
DEPENDENCY_PROPERTY(ViewModel::ApplicationViewModel ^, ApplicationViewModel);
DEPENDENCY_PROPERTY_WITH_CALLBACK(bool, IsAlwaysOnTopMode);
event Windows::UI::Xaml::RoutedEventHandler ^ AlwaysOnTopClick;
private:
void OnLoaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void OnUnloaded(_In_ Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
@ -33,6 +34,7 @@ public
void ColorValuesChanged(_In_ Windows::UI::ViewManagement::UISettings ^ sender, _In_ Platform::Object ^ e);
void OnHighContrastChanged(Windows::UI::ViewManagement::AccessibilitySettings ^ sender, Platform::Object ^ args);
void OnWindowActivated(Platform::Object ^ sender, Windows::UI::Core::WindowActivatedEventArgs ^ e);
void OnIsAlwaysOnTopModePropertyChanged(bool oldValue, bool newValue);
Platform::Agile<Windows::ApplicationModel::Core::CoreApplicationViewTitleBar ^> m_coreTitleBar;
Windows::Foundation::EventRegistrationToken m_layoutChangedToken;
@ -42,6 +44,6 @@ public
Windows::Foundation::EventRegistrationToken m_accessibilitySettingsToken;
Windows::UI::ViewManagement::UISettings ^ m_uiSettings;
Windows::UI::ViewManagement::AccessibilitySettings ^ m_accessibilitySettings;
void AlwaysOnTopButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void AlwaysOnTopButton_Click(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
};
}