restructure project for part 2

This commit is contained in:
TheXamlGuy
2024-01-27 10:55:53 +00:00
parent a322893166
commit 48925b89ff
96 changed files with 383 additions and 351 deletions
@@ -0,0 +1,56 @@
using Microsoft.UI.Xaml;
namespace Hyperbar.Controls.Windows;
public class DesktopBar :
DependencyObject
{
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(nameof(Content),
typeof(object), typeof(DesktopBar),
new PropertyMetadata(null));
public static readonly DependencyProperty PlacementProperty =
DependencyProperty.Register(nameof(Placement),
typeof(DesktopBarPlacemenet), typeof(DesktopBar),
new PropertyMetadata(DesktopBarPlacemenet.Left, OnPlacementPropertyChanged));
private readonly DesktopBarHost host;
private readonly DesktopBarPresenter presenter;
public DesktopBar()
{
presenter = new DesktopBarPresenter
{
Parent = this
};
host = new DesktopBarHost(presenter);
host.Activate();
}
public object Content
{
get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}
public DesktopBarPlacemenet Placement
{
get => (DesktopBarPlacemenet)GetValue(PlacementProperty);
set => SetValue(PlacementProperty, value);
}
private static void OnPlacementPropertyChanged(DependencyObject dependencyObject,
DependencyPropertyChangedEventArgs args)
{
if (dependencyObject is DesktopBar sender)
{
sender.OnPlacementPropertyChanged();
}
}
private void OnPlacementPropertyChanged() => UpdatePlacement();
private void UpdatePlacement() => host.UpdatePlacement(Placement);
}
@@ -0,0 +1,80 @@
using Microsoft.UI.Xaml;
using Windows.Foundation;
using Microsoft.UI.Xaml.Media;
using Hyperbar.Interop.Windows;
using Hyperbar.UI.Windows;
namespace Hyperbar.Controls.Windows;
internal class DesktopBarHost : Window
{
private readonly DesktopBarPresenter presenter;
private readonly WindowSnapping windowSnapping;
private DesktopBarPlacemenet placement;
public DesktopBarHost(DesktopBarPresenter presenter)
{
this.SetOpacity(0);
this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible);
this.SetStyle(ExtendedWindowStyle.NoActivate);
this.MoveAndResize(0, 0, 0, 0);
this.SetTopMost(true);
this.SetIsAvailableInSwitchers(false);
SystemBackdrop = new MicaBackdrop();
windowSnapping = WindowSnapping.Create(this.GetHandle());
this.presenter = presenter;
presenter.Loaded += OnLoaded;
Content = presenter;
Closed += OnClosed;
}
internal void UpdatePlacement(DesktopBarPlacemenet placement)
{
this.placement = placement;
UpdatePlacement();
}
internal void UpdatePlacement()
{
presenter.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
double size = Math.Min(presenter.DesiredSize.Height, presenter.DesiredSize.Width);
switch (placement)
{
case DesktopBarPlacemenet.Left:
windowSnapping.Snap(WindowSnappingPlacement.Left, (int)size);
break;
case DesktopBarPlacemenet.Top:
windowSnapping.Snap(WindowSnappingPlacement.Top, (int)size);
break;
case DesktopBarPlacemenet.Right:
windowSnapping.Snap(WindowSnappingPlacement.Right, (int)size);
break;
case DesktopBarPlacemenet.Bottom:
windowSnapping.Snap(WindowSnappingPlacement.Bottom, (int)size);
break;
default:
break;
}
presenter.UpdatePlacementState(placement);
}
private void OnClosed(object sender, WindowEventArgs args)
{
windowSnapping.Dispose();
}
private void OnLoaded(object sender,
RoutedEventArgs args)
{
UpdatePlacement();
this.SetOpacity(255);
}
}
@@ -0,0 +1,9 @@
namespace Hyperbar.Controls.Windows;
public enum DesktopBarPlacemenet
{
Left,
Top,
Right,
Bottom
}
@@ -0,0 +1,40 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
namespace Hyperbar.Controls.Windows;
public class DesktopBarPresenter :
ContentControl
{
public static readonly DependencyProperty TemplateSettingsProperty =
DependencyProperty.Register(nameof(TemplateSettings),
typeof(DesktopBarPresenterTemplateSettings), typeof(DesktopBarPresenter),
new PropertyMetadata(null));
internal new DesktopBar? Parent;
public DesktopBarPresenter()
{
DefaultStyleKey = typeof(DesktopBarPresenter);
TemplateSettings = new DesktopBarPresenterTemplateSettings();
}
protected override void OnApplyTemplate()
{
SetBinding(ContentProperty, new Binding
{
Source = Parent,
Mode = BindingMode.TwoWay,
Path = new PropertyPath(nameof(Parent.Content)),
});
}
public DesktopBarPresenterTemplateSettings TemplateSettings
{
get => (DesktopBarPresenterTemplateSettings)GetValue(TemplateSettingsProperty);
set => SetValue(TemplateSettingsProperty, value);
}
internal void UpdatePlacementState(DesktopBarPlacemenet placement) => VisualStateManager.GoToState(this, $"{placement}Placement", true);
}
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Hyperbar.Controls.Windows">
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<StaticResource x:Key="DesktopBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
<StaticResource x:Key="DesktopBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
<StaticResource x:Key="DesktopBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<StaticResource x:Key="DesktopBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
<StaticResource x:Key="DesktopBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
<StaticResource x:Key="DesktopBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<Thickness x:Key="DesktopBarPresenterBorderThemeThickness">0</Thickness>
<Style TargetType="controls:DesktopBarPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{ThemeResource DesktopBarPresenterForeground}" />
<Setter Property="BorderBrush" Value="{ThemeResource DesktopBarPresenterBorderBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource DesktopBarPresenterBorderThemeThickness}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:DesktopBarPresenter">
<Border x:Name="Container" Background="Transparent">
<Border
x:Name="BackgroundElement"
MinWidth="48"
MinHeight="48"
Background="{TemplateBinding Background}"
BackgroundSizing="OuterBorderEdge"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
FlowDirection="{TemplateBinding FlowDirection}">
<ContentControl
Height="40"
Margin="4"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}" />
</Border>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="PlacementStates">
<VisualState x:Name="DefaultPlacement" />
<VisualState x:Name="BottomPlacement" />
<VisualState x:Name="TopPlacement" />
<VisualState x:Name="LeftPlacement" />
<VisualState x:Name="RightPlacement" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -0,0 +1,50 @@
using Microsoft.UI.Xaml;
namespace Hyperbar.Controls.Windows;
public class DesktopBarPresenterTemplateSettings : DependencyObject
{
public static readonly DependencyProperty HeightProperty =
DependencyProperty.Register(nameof(Height),
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
new PropertyMetadata(0d));
public static readonly DependencyProperty NegativeHeightProperty =
DependencyProperty.Register(nameof(NegativeHeight),
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
new PropertyMetadata(0d));
public static readonly DependencyProperty NegativeWidthProperty =
DependencyProperty.Register(nameof(NegativeWidth),
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
new PropertyMetadata(0d));
public static readonly DependencyProperty WidthProperty =
DependencyProperty.Register(nameof(Width),
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
new PropertyMetadata(0d));
public double Height
{
get => (double)GetValue(HeightProperty);
set => SetValue(HeightProperty, value);
}
public double NegativeHeight
{
get => (double)GetValue(NegativeHeightProperty);
set => SetValue(NegativeHeightProperty, value);
}
public double NegativeWidth
{
get => (double)GetValue(NegativeWidthProperty);
set => SetValue(NegativeWidthProperty, value);
}
public double Width
{
get => (double)GetValue(WidthProperty);
set => SetValue(WidthProperty, value);
}
}
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.EndsWith('-windows10.0.19041.0'))">
<None Include="bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).pri" Pack="true" PackagePath="lib/$(TargetFramework.TrimEnd('.0'))/" />
</ItemGroup>
<ItemGroup>
<None Remove="bin/Debug/net8.0-windows10.0.19041.0/Hyperbar.Controls.Windows.pri" />
<None Remove="bin/Debug/net8.0-windows10.0.19041.0/Hyperbar.Windows.Controls.pri" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Interop.Windows\Hyperbar.Interop.Windows.csproj" />
<ProjectReference Include="..\Hyperbar.UI.Windows\Hyperbar.UI.Windows.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Hyperbar.Controls.Windows/DesktopBar/DesktopBarPresenter.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>