Skip to content

Commit

Permalink
Merge pull request #283 from amwx/v2_p5_ThemeDictionaries
Browse files Browse the repository at this point in the history
Migrate to ThemeDictionaries
  • Loading branch information
amwx authored Feb 4, 2023
2 parents e817c5f + cde2098 commit d936eb5
Show file tree
Hide file tree
Showing 143 changed files with 7,730 additions and 8,534 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,4 @@ ASALocalRun/

# BeatPulse healthcheck temp database
healthchecksdb
/FluentAvalonia.UI.Windowing/Win32/Win32Com.Generated.cs
6 changes: 3 additions & 3 deletions FASandbox/FASandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<None Remove=".gitignore" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia" Version="11.0-preview5" />
<PackageReference Include="Avalonia.Desktop" Version="11.0-preview5" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0-preview5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FluentAvalonia\FluentAvalonia.csproj" />
Expand Down
16 changes: 16 additions & 0 deletions FASandbox/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@
x:Class="FASandbox.MainWindow"
Title="FASandbox">

<StackPanel Spacing="50">
<ui:SettingsExpander IconSource="Globe" Header="Test Header" IsExpanded="True"
Description="This is a description for the SettingsExpander"
ActionIconSource="Save" IsClickEnabled="False">
<ui:SettingsExpander.Footer>
<Button Content="FooterButton" />
</ui:SettingsExpander.Footer>

<ui:SettingsExpanderItem Content="Content Here" ActionIconSource="Pin" IsClickEnabled="True" />
<ui:SettingsExpanderItem Content="Content Here">
<ui:SettingsExpanderItem.Footer>
<Button Content="FooterButton" />
</ui:SettingsExpanderItem.Footer>
</ui:SettingsExpanderItem>
</ui:SettingsExpander>
</StackPanel>

</Window>
1 change: 1 addition & 0 deletions FASandbox/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public MainWindow()
this.AttachDevTools();
#endif
DataContext = new MainWindowViewModel();
var b = new Button();
}

private void InitializeComponent()
Expand Down
29 changes: 28 additions & 1 deletion FASandbox/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
namespace FASandbox;
using System;
using System.Diagnostics;
using System.Windows.Input;

namespace FASandbox;

public class MainWindowViewModel
{
public MainWindowViewModel()
{

}

public Command Commands { get; } = new Command();

public void Test(object param)
{
Debug.WriteLine("FIRED");
}
}

public class Command : ICommand
{
public event EventHandler CanExecuteChanged;

public bool CanExecute(object parameter)
{
return true;
}

public void Execute(object parameter)
{
Debug.WriteLine("FIRED");
}
}

2 changes: 1 addition & 1 deletion FluentAvalonia.UI.Windowing/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TaskDialogWindowHost(TaskDialog dialog)
#endif
}

protected override void OnClosing(CancelEventArgs e)
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);

Expand Down
44 changes: 18 additions & 26 deletions FluentAvalonia.UI.Windowing/AppWindow/AppWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Styling;
using Avalonia.VisualTree;
using FluentAvalonia.Interop;
using FluentAvalonia.Styling;
using FluentAvalonia.UI.Controls.Primitives;
using FluentAvalonia.UI.Media;

Expand Down Expand Up @@ -74,10 +74,6 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
// This will set all our TemplateSettings properties
OnTitleBarHeightChanged(_titleBar.Height);

var faTheme = AvaloniaLocator.Current.GetService<FluentAvaloniaTheme>();
_currentAppTheme = faTheme.RequestedTheme;
faTheme.RequestedThemeChanged += OnRequestedThemeChanged;

SetTitleBarColors();
}

Expand All @@ -100,6 +96,10 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
base.Icon = new WindowIcon(change.NewValue as IBitmap);
PseudoClasses.Set(":icon", change.NewValue != null);
}
else if (change.Property == ActualThemeVariantProperty)
{
SetTitleBarColors();
}
}

protected override async void OnOpened(EventArgs e)
Expand Down Expand Up @@ -128,10 +128,7 @@ protected override void OnClosed(EventArgs e)
{
_splashContext?.TryCancel();

base.OnClosed(e);

if (IsWindows && !Design.IsDesignMode)
AvaloniaLocator.Current.GetService<FluentAvaloniaTheme>().RequestedThemeChanged -= OnRequestedThemeChanged;
base.OnClosed(e);
}

internal void OnExtendsContentIntoTitleBarChanged(bool isExtended)
Expand Down Expand Up @@ -220,7 +217,7 @@ bool CheckExclusionList(Point p)
if (_excludeHitTestList[i].TryGetTarget(out var target))
{
// Skip invisible or disconnected controls
if (!target.IsVisible || !((IVisual)target).IsAttachedToVisualTree)
if (!target.IsVisible || !target.IsAttachedToVisualTree())
continue;

// If control was reparented into new window, matrix may be null, catch that case
Expand Down Expand Up @@ -248,7 +245,7 @@ bool CheckExclusionList(Point p)

internal bool ComplexHitTest(Point p)
{
var result = this.InputHitTest(p);
var result = this.InputHitTest(p) as InputElement;

// Special case for TabViewListView during drag operations where blank space
// is inserted and causes HitTest to fail (since nothing focusable is there)
Expand All @@ -263,7 +260,7 @@ internal bool ComplexHitTest(Point p)
if (result.IsHitTestVisible && result.Focusable)
return false;

result = result.VisualParent as IInputElement;
result = result.GetVisualParent() as InputElement;
}

return true;
Expand Down Expand Up @@ -299,24 +296,16 @@ internal void OnWin32WindowStateChanged(WindowState state)
}
}

protected virtual void OnRequestedThemeChanged(FluentAvaloniaTheme sender, RequestedThemeChangedEventArgs args)
{
if (IsWindows)
{
_currentAppTheme = args.NewTheme;
SetTitleBarColors();
}
}

private void SetTitleBarColors()
{
if (_templateRoot == null)
return;

bool foundAccent = _templateRoot.TryFindResource(s_SystemAccentColor, out var sysColor);
Color? accentVariant = null;
var themeVar = ActualThemeVariant;

if (_currentAppTheme == FluentAvaloniaTheme.LightModeString)
if (themeVar == ThemeVariant.Light)
{
if (_templateRoot.TryFindResource(s_SystemAccentColorDark1, out var v))
{
Expand All @@ -332,13 +321,13 @@ private void SetTitleBarColors()
}

Color textColor;
if (_templateRoot.TryFindResource(s_TextFillColorPrimary, out var value))
if (_templateRoot.TryFindResource(s_TextFillColorPrimary, themeVar, out var value))
{
textColor = Unsafe.Unbox<Color>(value);
}
else
{
if (_currentAppTheme == FluentAvaloniaTheme.DarkModeString)
if (ActualThemeVariant == ThemeVariant.Dark)
{
textColor = Colors.White;
}
Expand Down Expand Up @@ -485,9 +474,12 @@ private void InitializeAppWindow()

private async void LoadApp()
{
Presenter.IsVisible = true;
if (Presenter is not ContentPresenter cp)
return;

cp.IsVisible = true;

using var disp = Presenter.SetValue(OpacityProperty, 0d, Avalonia.Data.BindingPriority.Animation);
using var disp = cp.SetValue(OpacityProperty, 0d, Avalonia.Data.BindingPriority.Animation);

var aniSplash = new Animation
{
Expand Down
1 change: 0 additions & 1 deletion FluentAvalonia.UI.Windowing/AppWindow/AppWindow.props.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public IApplicationSplashScreen SplashScreen
private MinMaxCloseControl _captionButtons;
private Panel _defaultTitleBar;
private AppWindowTitleBar _titleBar;
private string _currentAppTheme;
private List<WeakReference<Control>> _excludeHitTestList;
private bool _hideSizeButtons;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.0-preview4" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.0-preview4" />
<PackageReference Include="Avalonia" Version="11.0-preview5" />
<PackageReference Include="Avalonia.Desktop" Version="11.0-preview5" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0-preview5" />

<PackageReference Include="MicroCom.CodeGenerator.MSBuild" Version="0.11.0" />
<PackageReference Include="MicroCom.Runtime" Version="0.11.0" />
Expand Down
9 changes: 5 additions & 4 deletions FluentAvalonia.UI.Windowing/Win32/AppWindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ public override void Show(bool activate, bool isDialog)
{
base.Show(activate, isDialog);

_hasShown = true;

// If Window state is set to FullScreen before the window opens, we get a WM_SIZE event that
// resets the window state and it launches without the window frame but in "normal" mode
// So we defer setting the state to full screen until now so everything works correctly
if (!_hasShown && _isFullScreen)
{
if (_isFullScreen)
{
WindowState = WindowState.FullScreen;
}
_hasShown = true;
}
}

public void SetOwner(AppWindow wnd)
Expand Down
7 changes: 0 additions & 7 deletions FluentAvalonia.UI.Windowing/Win32/Helpers/POINT.cs

This file was deleted.

Loading

0 comments on commit d936eb5

Please sign in to comment.