Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions src/SwitchifyPc.App/Chrome/SwitchifyTitleBar.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<UserControl x:Class="SwitchifyPc.App.Chrome.SwitchifyTitleBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
Height="44"
Background="#D32F2F"
Foreground="White"
shell:WindowChrome.IsHitTestVisibleInChrome="True"
MouseLeftButtonDown="TitleBar_MouseLeftButtonDown">
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

<Style x:Key="CaptionButton" TargetType="Button">
<Setter Property="Width" Value="44" />
<Setter Property="Height" Value="44" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="shell:WindowChrome.IsHitTestVisibleInChrome" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Root" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="False" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Root" Property="Background" Value="#B3261E" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Root" Property="Background" Value="#8F1D18" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Root" Property="Opacity" Value="0.45" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="CloseCaptionButton" TargetType="Button" BasedOn="{StaticResource CaptionButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="Root" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="False" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Root" Property="Background" Value="#C42B1C" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Root" Property="Background" Value="#8F1D18" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Root" Property="Opacity" Value="0.45" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<StackPanel Margin="14,0,10,0"
Orientation="Horizontal"
VerticalAlignment="Center">
<Image Width="18"
Height="18"
Source="../Assets/icon.ico" />
<TextBlock x:Name="TitleTextBlock"
Margin="10,0,0,0"
VerticalAlignment="Center"
Text="{Binding TitleText, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextTrimming="CharacterEllipsis"
FontSize="13"
FontWeight="SemiBold"
Foreground="White" />
</StackPanel>

<StackPanel Grid.Column="1"
Orientation="Horizontal">
<Button x:Name="MinimizeButton"
Content="-"
Style="{StaticResource CaptionButton}"
AutomationProperties.Name="Minimize"
Visibility="{Binding ShowMinimizeButton, RelativeSource={RelativeSource AncestorType=UserControl}, Converter={StaticResource BooleanToVisibilityConverter}}"
Click="MinimizeButton_Click" />
<Button x:Name="CloseButton"
Content="x"
Style="{StaticResource CloseCaptionButton}"
AutomationProperties.Name="Close"
Click="CloseButton_Click" />
</StackPanel>
</Grid>
</UserControl>
88 changes: 88 additions & 0 deletions src/SwitchifyPc.App/Chrome/SwitchifyTitleBar.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using WpfButton = System.Windows.Controls.Button;
using WpfUserControl = System.Windows.Controls.UserControl;

namespace SwitchifyPc.App.Chrome;

public partial class SwitchifyTitleBar : WpfUserControl
{
public static readonly DependencyProperty TitleTextProperty = DependencyProperty.Register(
nameof(TitleText),
typeof(string),
typeof(SwitchifyTitleBar),
new PropertyMetadata(string.Empty));

public static readonly DependencyProperty ShowMinimizeButtonProperty = DependencyProperty.Register(
nameof(ShowMinimizeButton),
typeof(bool),
typeof(SwitchifyTitleBar),
new PropertyMetadata(true));

public SwitchifyTitleBar()
{
InitializeComponent();
}

public string TitleText
{
get => (string)GetValue(TitleTextProperty);
set => SetValue(TitleTextProperty, value);
}

public bool ShowMinimizeButton
{
get => (bool)GetValue(ShowMinimizeButtonProperty);
set => SetValue(ShowMinimizeButtonProperty, value);
}

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount != 1 || IsInsideButton(e.OriginalSource as DependencyObject))
{
return;
}

Window? window = Window.GetWindow(this);
if (window is null) return;

try
{
window.DragMove();
}
catch (InvalidOperationException)
{
}
}

private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
Window? window = Window.GetWindow(this);
if (window is not null)
{
window.WindowState = WindowState.Minimized;
}
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Window.GetWindow(this)?.Close();
}

private static bool IsInsideButton(DependencyObject? source)
{
while (source is not null)
{
if (source is WpfButton)
{
return true;
}

source = VisualTreeHelper.GetParent(source);
}

return false;
}
}
34 changes: 30 additions & 4 deletions src/SwitchifyPc.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="clr-namespace:SwitchifyPc.Core.Ui;assembly=SwitchifyPc.Core"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
xmlns:chrome="clr-namespace:SwitchifyPc.App.Chrome"
mc:Ignorable="d"
Title="Switchify PC"
MinHeight="520"
Expand All @@ -12,9 +14,18 @@
Width="920"
Icon="Assets/icon.ico"
FontFamily="Segoe UI"
Background="#F5F4F7"
Background="#D32F2F"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
d:DataContext="{d:DesignInstance Type=ui:MainWindowViewModel, IsDesignTimeCreatable=True}">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome CaptionHeight="44"
CornerRadius="0"
GlassFrameThickness="0"
ResizeBorderThickness="6"
UseAeroCaptionButtons="False" />
</shell:WindowChrome.WindowChrome>

<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

Expand Down Expand Up @@ -213,8 +224,21 @@
</Style>
</Window.Resources>

<Grid Background="#F5F4F7" Margin="24">
<Border HorizontalAlignment="Stretch"
<Grid Background="#D32F2F">
<Grid.RowDefinitions>
<RowDefinition Height="44" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<chrome:SwitchifyTitleBar Grid.Row="0"
TitleText="Switchify PC"
ShowMinimizeButton="True" />

<Grid Grid.Row="1" Background="#D32F2F">
<Border Margin="0,96,0,0"
Background="#F5F4F7" />
<Grid Margin="24">
<Border HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{StaticResource MainCard}">
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
Expand Down Expand Up @@ -497,6 +521,8 @@
</Expander>
</StackPanel>
</ScrollViewer>
</Border>
</Border>
</Grid>
</Grid>
</Grid>
</Window>
32 changes: 27 additions & 5 deletions src/SwitchifyPc.App/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="clr-namespace:SwitchifyPc.Core.Ui;assembly=SwitchifyPc.Core"
xmlns:shell="clr-namespace:System.Windows.Shell;assembly=PresentationFramework"
xmlns:chrome="clr-namespace:SwitchifyPc.App.Chrome"
mc:Ignorable="d"
Title="Switchify PC settings"
MinHeight="560"
Expand All @@ -13,9 +15,18 @@
ResizeMode="NoResize"
Icon="Assets/icon.ico"
FontFamily="Segoe UI"
Background="#F5F4F7"
Background="#D32F2F"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
d:DataContext="{d:DesignInstance Type=ui:SettingsViewModel, IsDesignTimeCreatable=True}">
<shell:WindowChrome.WindowChrome>
<shell:WindowChrome CaptionHeight="44"
CornerRadius="0"
GlassFrameThickness="0"
ResizeBorderThickness="6"
UseAeroCaptionButtons="False" />
</shell:WindowChrome.WindowChrome>

<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

Expand Down Expand Up @@ -235,23 +246,34 @@
</Style>
</Window.Resources>

<Grid Background="#F5F4F7" Margin="24">
<Grid Background="#D32F2F">
<Grid.RowDefinitions>
<RowDefinition Height="44" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<StackPanel>
<chrome:SwitchifyTitleBar Grid.Row="0"
TitleText="Switchify PC settings"
ShowMinimizeButton="True" />

<Border Grid.Row="1"
Grid.RowSpan="2"
Margin="0,80,0,0"
Background="#F5F4F7" />

<StackPanel Grid.Row="1" Margin="24,24,24,0">
<TextBlock Text="Settings"
FontSize="18"
FontWeight="Bold"
Foreground="{StaticResource Text}" />
Foreground="White" />
<TextBlock Margin="0,4,0,18"
Text="Tune how Switchify starts, connects, and controls this PC."
Foreground="#FDE8E8"
Style="{StaticResource MutedText}" />
</StackPanel>

<Grid Grid.Row="1">
<Grid Grid.Row="2" Margin="24,0,24,24">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="24" />
Expand Down
1 change: 1 addition & 0 deletions src/SwitchifyPc.Tests/ButtonStyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace SwitchifyPc.Tests;

[Collection(WpfTestCollection.Name)]
public sealed class ButtonStyleTests
{
[Fact]
Expand Down
Loading