Skip to content

Commit

Permalink
Avalonia 11 (#214)
Browse files Browse the repository at this point in the history
The editor has been updated to the latest UI framework version. The new version has many breaking changes, if you think there is some new bug, please report it.
  • Loading branch information
BAndysc authored Mar 9, 2024
1 parent dee881c commit d83de42
Show file tree
Hide file tree
Showing 1,127 changed files with 19,965 additions and 10,866 deletions.
6 changes: 1 addition & 5 deletions AntlrSupport.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- sadly AntlrBuildTools doesn't support non standard paths, so we need to revert obj/ and bin/ paths to the standard
https://github.com/kaby76/Antlr4BuildTasks/issues/14
-->
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)/$(Configuration)</IntermediateOutputPath>

</PropertyGroup>
</Project>
16 changes: 11 additions & 5 deletions Avalonia.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AvaloniaVersion>11.1.999-cibuild0045870-beta</AvaloniaVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Skia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.10.10" />
<PackageReference Include="Projektanker.Icons.Avalonia" Version="5.13.0" />
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="5.13.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.0.10" />
<PackageReference Include="Projektanker.Icons.Avalonia" Version="9.1.1" />
<PackageReference Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="9.1.1" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\Prism.Avalonia\src\Prism.Avalonia\Prism.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
Expand All @@ -17,4 +23,4 @@
<SubType>Designer</SubType>
</AvaloniaResource>
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion AvaloniaEdit
Submodule AvaloniaEdit updated 137 files
22 changes: 22 additions & 0 deletions AvaloniaStyles.Desktop/AvaloniaStyles.Desktop.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<Nullable>enable</Nullable>
<WarningsAsErrors>$(WarningsAsErrors),nullable</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AvaloniaStyles\AvaloniaStyles.csproj" />
</ItemGroup>

<Import Project="..\Module.props" />
<Import Project="..\Avalonia.props" />

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)"/>
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions AvaloniaStyles.Desktop/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Avalonia;

namespace AvaloniaStyles.Desktop;

public class Program
{
static void Main(string[] args)
=> BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

// App configuration, used by the entry point and previewer
static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
4 changes: 4 additions & 0 deletions AvaloniaStyles/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<Application.Styles>
<avaloniaStyles:SystemTheme Mode="LightWindows11" />
</Application.Styles>
<Application.Resources>
<ResourceDictionary>
</ResourceDictionary>
</Application.Resources>
</Application>
20 changes: 7 additions & 13 deletions AvaloniaStyles/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
desktop.MainWindow = new MainWindow();
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = new MainView
{
DataContext = new DemoDataContext()
};
}
base.OnFrameworkInitializationCompleted();
}

static void Main(string[] args)
=> BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);

// App configuration, used by the entry point and previewer
static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.With(new Win32PlatformOptions
{
OverlayPopups = true,
})
.UsePlatformDetect()
.LogToTrace();
}
}
15 changes: 8 additions & 7 deletions AvaloniaStyles/AvaloniaStyles.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifiers>win8-x64;osx-x64;linux-x64;osx-arm64;win-x64</RuntimeIdentifiers>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<WarningsAsErrors>$(WarningsAsErrors),nullable</WarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<OutputPath>..\bin\$(Configuration)\</OutputPath>
<SelfContained>true</SelfContained>
</PropertyGroup>

<Import Project="..\Module.props" />

<Import Project="..\Avalonia.props" />
Expand All @@ -26,6 +24,9 @@
<AvaloniaResource Include="Styles\Assets\Lato\*.ttf" />
<None Remove="Fonts\Symbols.ttf" />
<AvaloniaResource Include="Fonts\Symbols.ttf" />
<AvaloniaResource Remove="Styles\BigSur\**" />
<AvaloniaResource Remove="Styles\Catalina\**" />
<AvaloniaResource Remove="Styles\MacOs\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AvaloniaEdit\src\AvaloniaEdit\AvaloniaEdit.csproj" />
Expand Down
123 changes: 46 additions & 77 deletions AvaloniaStyles/Controls/AccentSolidColorBrush.cs
Original file line number Diff line number Diff line change
@@ -1,86 +1,55 @@
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Metadata;
using AvaloniaStyles.Utils;
using HslColor = AvaloniaStyles.Utils.HslColor;

namespace AvaloniaStyles.Controls;

public class AccentSolidColorBrush : Brush, ISolidColorBrush
public class Accent
{
public static readonly StyledProperty<Color> BaseColorProperty =
AvaloniaProperty.Register<AccentSolidColorBrush, Color>(nameof(BaseColor));

public static readonly StyledProperty<HslDiff> HueProperty =
AvaloniaProperty.Register<AccentSolidColorBrush, HslDiff>(nameof(Hue));

static AccentSolidColorBrush()
{
AffectsRender<AccentSolidColorBrush>(BaseColorProperty);
AffectsRender<AccentSolidColorBrush>(HueProperty);
}

public AccentSolidColorBrush(Color color, double opacity = 1.0)
{
BaseColor = color;
Opacity = opacity;
}

public AccentSolidColorBrush(uint color) : this(Color.FromUInt32(color))
{
}

public AccentSolidColorBrush()
{
Opacity = 1;
}

/// <summary>Gets or sets the color of the brush.</summary>
[Content]
public Color BaseColor
{
get => GetValue(BaseColorProperty);
set => SetValue(BaseColorProperty, value);
}

public HslDiff Hue
{
get => GetValue(HueProperty);
set => SetValue(HueProperty, value);
}

/// <summary>Parses a brush string.</summary>
/// <param name="s">The brush string.</param>
/// <returns>The <see cref="P:Avalonia.Media.SolidColorBrush.Color" />.</returns>
/// <remarks>
/// Whereas <see cref="M:Avalonia.Media.Brush.Parse(System.String)" /> may return an immutable solid color brush,
/// this method always returns a mutable <see cref="T:Avalonia.Media.SolidColorBrush" />.
/// </remarks>
public static AccentSolidColorBrush Parse(string s)
{
ISolidColorBrush solidColorBrush1 = (ISolidColorBrush)Brush.Parse(s);
return !(solidColorBrush1 is AccentSolidColorBrush solidColorBrush2)
? new AccentSolidColorBrush(solidColorBrush1.Color)
: solidColorBrush2;
}

public override string ToString() => Color.ToString();

/// <inheritdoc />
public override IBrush ToImmutable() => new ImmutableSolidColorBrush(this);

public Color Color
{
get
{
var hsl = HslColor.FromRgba(BaseColor).Scale(Hue);
return hsl.ToRgba();
}
set
{
var hsl = HslColor.FromRgba(value);
//Hue = (float)hsl.H;
BaseColor = value;
}
}
public static readonly StyledProperty<Color> BaseColorProperty =
AvaloniaProperty.RegisterAttached<Accent, SolidColorBrush, Color>("BaseColor");

public static readonly StyledProperty<HslDiff> HueProperty =
AvaloniaProperty.RegisterAttached<Accent, SolidColorBrush, HslDiff>("Hue");

static Accent()
{
HueProperty.Changed.AddClassHandler<SolidColorBrush>((brush, e) =>
{
Color baseColor;
if (!brush.IsSet(BaseColorProperty))
{
baseColor = brush.Color;
SetBaseColor(brush, baseColor);
}
else
{
baseColor = brush.GetValue(BaseColorProperty);
}
var hsl = HslColor.FromRgba(baseColor).Scale(e.NewValue as HslDiff);
brush.Color = hsl.ToRgba();
});
}

public static Color GetBaseColor(AvaloniaObject obj)
{
return obj.GetValue(BaseColorProperty);
}

public static void SetBaseColor(AvaloniaObject obj, Color value)
{
obj.SetValue(BaseColorProperty, value);
}

public static HslDiff GetHue(AvaloniaObject obj)
{
return obj.GetValue(HueProperty);
}

public static void SetHue(AvaloniaObject obj, HslDiff value)
{
obj.SetValue(HueProperty, value);
}
}
37 changes: 0 additions & 37 deletions AvaloniaStyles/Controls/AlternativeScrollViewer.cs

This file was deleted.

19 changes: 10 additions & 9 deletions AvaloniaStyles/Controls/BaseMessageBoxWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

namespace AvaloniaStyles.Controls
{
public class BaseMessageBoxWindow : Window, IStyleable
public class BaseMessageBoxWindow : Window
{
protected override Type StyleKeyOverride => typeof(BaseMessageBoxWindow);

public static readonly StyledProperty<string> MessageProperty =
AvaloniaProperty.Register<BaseMessageBoxWindow, string>(nameof(Message));

Expand All @@ -30,36 +32,35 @@ public string Header
set => SetValue(HeaderProperty, value);
}

public static readonly StyledProperty<IControl> ImageProperty =
AvaloniaProperty.Register<BaseMessageBoxWindow, IControl>(nameof(Image));
public static readonly StyledProperty<Control> ImageProperty =
AvaloniaProperty.Register<BaseMessageBoxWindow, Control>(nameof(Image));

public IControl Image
public Control Image
{
get => GetValue(ImageProperty);
set => SetValue(ImageProperty, value);
}

public BaseMessageBoxWindow()
{
this.AttachDevTools();
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
PseudoClasses.Add(":macos");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
PseudoClasses.Add(":windows");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
PseudoClasses.Add(":linux");

Win32.SetDarkMode(PlatformImpl.Handle.Handle, SystemTheme.EffectiveThemeIsDark);
if (TryGetPlatformHandle() is { } handle)
Win32.SetDarkMode(handle.Handle, SystemTheme.EffectiveThemeIsDark);
}

Type IStyleable.StyleKey => typeof(BaseMessageBoxWindow);

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome;
if (Background is ISolidColorBrush brush)
Win32.SetTitleBarColor(PlatformImpl.Handle.Handle, brush.Color);
if (TryGetPlatformHandle() is { } handle)
Win32.SetTitleBarColor(handle.Handle, brush.Color);
}
}
}
Loading

0 comments on commit d83de42

Please sign in to comment.