Enable dark mode for previewer and cleanup UI.

This commit is contained in:
Bebo-Maker
2022-03-17 19:35:46 +01:00
parent 0946607154
commit 846679007f
10 changed files with 104 additions and 53 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggest
#Style - Modifier preferences
#when this rule is set to a list of modifiers, prefer the specified ordering.
csharp_preferred_modifier_order = public,private,internal,static,override,readonly,virtual:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent
#Style - Pattern matching
+46
View File
@@ -0,0 +1,46 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Platform;
using Avalonia.Styling;
namespace QuestPDF.Previewer
{
internal class FluentWindow : Window, IStyleable
{
Type IStyleable.StyleKey => typeof(Window);
public FluentWindow()
{
ExtendClientAreaToDecorationsHint = true;
ExtendClientAreaTitleBarHeightHint = -1;
TransparencyLevelHint = WindowTransparencyLevel.AcrylicBlur;
this.GetObservable(WindowStateProperty)
.Subscribe(x =>
{
PseudoClasses.Set(":maximized", x == WindowState.Maximized);
PseudoClasses.Set(":fullscreen", x == WindowState.FullScreen);
});
this.GetObservable(IsExtendedIntoWindowDecorationsProperty)
.Subscribe(x =>
{
if (!x)
{
SystemDecorations = SystemDecorations.Full;
TransparencyLevelHint = WindowTransparencyLevel.Blur;
}
});
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ExtendClientAreaChromeHints =
ExtendClientAreaChromeHints.PreferSystemChrome |
ExtendClientAreaChromeHints.OSXThickTitleBar;
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+1 -1
View File
@@ -2,6 +2,6 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Styles>
<FluentTheme />
<FluentTheme Mode="Dark"/>
</Application.Styles>
</Application>
+2 -17
View File
@@ -1,5 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using QuestPDF.Infrastructure;
@@ -8,8 +7,6 @@ namespace QuestPDF.Previewer
{
internal class PreviewerApp : Application
{
private PreviewerView? _preview;
public IDocument? Document { get; init; }
public override void Initialize()
@@ -21,24 +18,12 @@ namespace QuestPDF.Previewer
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
HotReloadManager.Register(HandleDocumentHotReload);
_preview = new PreviewerView()
desktop.MainWindow = new PreviewerWindow()
{
Document = Document,
};
desktop.MainWindow = new Window()
{
Title = "QuestPDF Document Preview",
Content = _preview,
Document = Document
};
}
base.OnFrameworkInitializationCompleted();
}
private void HandleDocumentHotReload()
{
_preview?.InvalidatePreview();
}
}
}
+8 -2
View File
@@ -79,9 +79,15 @@ namespace QuestPDF.Previewer
private void DrawException(DrawingContext context, Exception ex)
{
var parentBounds = Parent?.Bounds ?? Bounds;
var exceptionMsg = string.Join("\n", ex.GetType(), ex.Message);
var fmtText = new FormattedText($"Exception occured:\n{exceptionMsg}", Typeface.Default, 25, TextAlignment.Left, TextWrapping.Wrap, new Avalonia.Size(Parent.Bounds.Width / 2, Parent.Bounds.Height / 2));
var center = new Point((Parent.Bounds.Width - fmtText.Bounds.Width) / 2, (Parent.Bounds.Height - fmtText.Bounds.Height) / 2);
var fmtText = new FormattedText($"Exception occured:\n{exceptionMsg}",
Typeface.Default, 25, TextAlignment.Left, TextWrapping.Wrap,
new Avalonia.Size(parentBounds.Width / 2, parentBounds.Height / 2));
var center = new Point((parentBounds.Width - fmtText.Bounds.Width) / 2, (parentBounds.Height - fmtText.Bounds.Height) / 2);
context.DrawText(Brushes.Black, center, fmtText);
}
}
-17
View File
@@ -1,17 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
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:previewer="clr-namespace:QuestPDF.Previewer"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="QuestPDF.Previewer.PreviewerView">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer Background="LightGray">
<previewer:PreviewerControl x:Name="PreviewerSurface" Margin="25" />
</ScrollViewer>
</Grid>
</UserControl>
+30
View File
@@ -0,0 +1,30 @@
<FluentWindow xmlns="https://github.com/avaloniaui"
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:previewer="clr-namespace:QuestPDF.Previewer"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="QuestPDF.Previewer.PreviewerWindow"
WindowStartupLocation="CenterScreen"
Icon="/Images/Logo.png"
UseLayoutRounding="True"
Background="{x:Null}"
Title="QuestPDF Document Preview">
<FluentWindow.Styles>
<Style Selector="TitleBar:fullscreen">
<Setter Property="Background" Value="#7F000000" />
</Style>
</FluentWindow.Styles>
<Panel>
<ExperimentalAcrylicBorder IsHitTestVisible="False">
<ExperimentalAcrylicBorder.Material>
<ExperimentalAcrylicMaterial TintColor="Black" MaterialOpacity="0.75" TintOpacity="1" />
</ExperimentalAcrylicBorder.Material>
</ExperimentalAcrylicBorder>
<ScrollViewer Margin="0,40,0,0">
<previewer:PreviewerControl x:Name="PreviewerSurface" Margin="25" />
</ScrollViewer>
</Panel>
</FluentWindow>
@@ -5,12 +5,12 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Previewer
{
internal class PreviewerView : UserControl
internal class PreviewerWindow : FluentWindow
{
private readonly PreviewerControl _previewHost;
public static readonly StyledProperty<IDocument?> DocumentProperty =
AvaloniaProperty.Register<PreviewerControl, IDocument?>(nameof(Document));
AvaloniaProperty.Register<PreviewerWindow, IDocument?>(nameof(Document));
public IDocument? Document
{
@@ -18,15 +18,14 @@ namespace QuestPDF.Previewer
set => SetValue(DocumentProperty, value);
}
public PreviewerView()
public PreviewerWindow()
{
InitializeComponent();
_previewHost = this.FindControl<PreviewerControl>("PreviewerSurface");
DocumentProperty
.Changed
.Subscribe(v => _previewHost.Document = v.NewValue.Value);
DocumentProperty.Changed.Subscribe(v => _previewHost.Document = v.NewValue.Value);
HotReloadManager.Register(InvalidatePreview);
}
private void InitializeComponent()
+11 -9
View File
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@@ -6,15 +6,17 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Images\Logo.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.12" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.12" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.12" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="0.10.12" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.12" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.10.12" />
<PackageReference Include="Avalonia.Xaml.Interactivity" Version="0.10.12" />
<PackageReference Include="ReactiveUI" Version="17.1.17" />
<PackageReference Include="Avalonia" Version="0.10.13" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.13" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.13" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="0.10.13" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.13" />
<PackageReference Include="ReactiveUI" Version="17.1.50" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>