Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Avalonia to 0.10.0-preview1 #146

Merged
merged 4 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 1 addition & 3 deletions CSharpMath.Avalonia.Example/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

<Application.Styles>

<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Fluent/Accents/FluentLight.xaml"/>

<StyleInclude Source="/SideBar.xaml"/>
<StyleInclude Source="/Styles.xaml"/>

</Application.Styles>
Expand Down
15 changes: 2 additions & 13 deletions CSharpMath.Avalonia.Example/CSharpMath.Avalonia.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<AvaloniaResource Include="**\*.xaml" />
<EmbeddedResource Include="..\Icon.png" Link="Icon.png" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.6" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.0-preview1" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0-preview1" />
<ProjectReference Include="..\CSharpMath.Avalonia\CSharpMath.Avalonia.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="Pages\MathButtonPage.xaml.cs">
<DependentUpon>MathButtonPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\MathViewPage.xaml.cs">
<DependentUpon>MathViewPage.xaml</DependentUpon>
</Compile>
<Compile Update="Pages\TextViewPage.xaml.cs">
<DependentUpon>TextViewPage.xaml</DependentUpon>
</Compile>
</ItemGroup>

</Project>
74 changes: 36 additions & 38 deletions CSharpMath.Avalonia.Example/MainView.xaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,38 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:pages="clr-namespace:CSharpMath.Avalonia.Example.Pages"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CSharpMath.Avalonia.Example.MainView"
Background="{DynamicResource ThemeBackgroundBrush}"
Foreground="{DynamicResource ThemeForegroundBrush}"
FontSize="{DynamicResource FontSizeNormal}">

<TabControl x:Name="Sidebar"
Classes="sidebar">

<TabControl.Tag>

<ComboBox x:Name="Themes"
DockPanel.Dock="Bottom"
SelectedIndex="0"
Width="100"
Margin="8">

<ComboBoxItem>Light</ComboBoxItem>
<ComboBoxItem>Dark</ComboBoxItem>

</ComboBox>

</TabControl.Tag>

<TabItem Header="MathView">
<pages:MathViewPage/>
</TabItem>

<TabItem Header="TextView">
<pages:TextViewPage/>
</TabItem>
<TabItem Header="MathButton">
<pages:MathButtonPage/>
</TabItem>

</TabControl>
<UserControl
x:Class="CSharpMath.Avalonia.Example.MainView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pages="clr-namespace:CSharpMath.Avalonia.Example.Pages"
Background="{DynamicResource ThemeBackgroundBrush}"
FontSize="{DynamicResource FontSizeNormal}"
Foreground="{DynamicResource ThemeForegroundBrush}">

<DockPanel>

<StackPanel
HorizontalAlignment="Right"
DockPanel.Dock="Bottom"
Orientation="Horizontal">
<RadioButton
x:Name="lightThemeRbn"
Margin="2,8"
Content="Light"
IsChecked="true" />
<RadioButton Margin="2,8" Content="Dark" />
</StackPanel>

<TabControl x:Name="Sidebar" Padding="16">
<TabItem Header="MathView">
<pages:MathViewPage />
</TabItem>
<TabItem Header="TextView">
<pages:TextViewPage />
</TabItem>
<TabItem Header="MathButton">
<pages:MathButtonPage />
</TabItem>
</TabControl>

</DockPanel>

</UserControl>
21 changes: 6 additions & 15 deletions CSharpMath.Avalonia.Example/MainView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Markup.Xaml.Styling;
Expand All @@ -7,21 +8,11 @@ public class MainView : UserControl {
public MainView() {
InitializeComponent();

var light = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='avares://Avalonia.Themes.Default/Accents/BaseLight.xaml'/>");
var dark = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='avares://Avalonia.Themes.Default/Accents/BaseDark.xaml'/>");
var themes = this.Find<ComboBox>("Themes");
themes.SelectionChanged += (sender, e) => {
switch (themes.SelectedIndex) {
case 0:
Styles[0] = light;
break;
case 1:
Styles[0] = dark;
break;
}
};

Styles.Add(light);
var light = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='avares://Avalonia.Themes.Fluent/Accents/FluentLight.xaml'/>");
var dark = AvaloniaXamlLoader.Parse<StyleInclude>(@"<StyleInclude xmlns='https://github.com/avaloniaui' Source='avares://Avalonia.Themes.Fluent/Accents/FluentDark.xaml'/>");
var themes = this.Find<RadioButton>("lightThemeRbn");
themes.Checked += (sender, e) => Application.Current.Styles[0] = light;
themes.Unchecked += (sender, e) => Application.Current.Styles[0] = dark;
}

private void InitializeComponent() {
Expand Down
84 changes: 0 additions & 84 deletions CSharpMath.Avalonia.Example/SideBar.xaml

This file was deleted.

2 changes: 1 addition & 1 deletion CSharpMath.Avalonia/CSharpMath.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<AvaloniaResource Include="**\*.xaml" />
<PackageReference Include="Avalonia" Version="0.9.6" />
<PackageReference Include="Avalonia" Version="0.10.0-preview1" />
<ProjectReference Include="..\CSharpMath.Rendering\CSharpMath.Rendering.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Compile Include="..\CSharpMath.CoreTests\_Helpers\ApproximateAssertions.cs" Link="ApproximateAssertions.cs" />
<ProjectReference Include="..\CSharpMath.Avalonia\CSharpMath.Avalonia.csproj" />
<ProjectReference Include="..\CSharpMath.SkiaSharp\CSharpMath.SkiaSharp.csproj" />
<PackageReference Include="Avalonia.Skia" Version="0.9.4" />
<PackageReference Include="Avalonia.Skia" Version="0.10.0-preview1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.8" />
Expand Down
4 changes: 4 additions & 0 deletions CSharpMath.Rendering.Tests/TestRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ protected void Run<TContent>(

// Prevent black background behind black rendered output in File Explorer preview
painter.HighlightColor = painter.UnwrapColor(System.Drawing.Color.FromArgb(0xF0, 0xF0, 0xF0));
if (painter.FontSize is PainterConstants.DefaultFontSize)
// We want a large and clear output so we increase the font size
// If we really want to test PainterConstants.DefaultFontSize = 14, choose e.g. 14.001 instead
painter.FontSize = 50;
painter.LaTeX = latex;

var actualFile = new FileInfo(System.IO.Path.Combine(folder, inFile + "." + frontEnd + ".png"));
Expand Down
2 changes: 1 addition & 1 deletion CSharpMath.Rendering/FrontEnd/Painter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CSharpMath.Rendering.FrontEnd {
using BackEnd;

public static class PainterConstants {
public const float DefaultFontSize = 50f;
public const float DefaultFontSize = 14;
}
public abstract class Painter<TCanvas, TContent, TColor> : ICSharpMathAPI<TContent, TColor> where TContent : class {
public const float DefaultFontSize = PainterConstants.DefaultFontSize;
Expand Down
6 changes: 3 additions & 3 deletions CSharpMath.Xaml.Tests.NuGet/Test.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CSharpMath.Xaml.Tests.NuGet {
namespace CSharpMath.Xaml.Tests.NuGet {
using Avalonia;
using SkiaSharp;
using Forms;
Expand All @@ -11,9 +11,9 @@ public void TestImage() {
Xamarin.Forms.Device.PlatformServices = new Xamarin.Forms.Core.UnitTests.MockPlatformServices();

using (var forms = System.IO.File.OpenWrite(File(nameof(Forms))))
new Forms.MathView { LaTeX = "1" }.Painter.DrawAsStream()?.CopyTo(forms);
new Forms.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsStream()?.CopyTo(forms);
using (var avalonia = System.IO.File.OpenWrite(File(nameof(Avalonia))))
new Avalonia.MathView { LaTeX = "1" }.Painter.DrawAsPng(avalonia);
new Avalonia.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsPng(avalonia);

using (var forms = System.IO.File.OpenRead(File(nameof(Forms))))
Xunit.Assert.Contains(forms.Length, new[] { 344L, 797 }); // 797 on Mac, 344 on Ubuntu
Expand Down
14 changes: 8 additions & 6 deletions CSharpMath.Xaml/Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public static XProperty CreateProperty<TThis, TValue>(
Action<TThis, TValue>? updateOtherProperty = null)
where TThis : BaseView<TPainter, TContent> {
var defaultValue = defaultValueGet(staticPainter);
void PropertyChanged(TThis @this, object newValue) {
propertySet(@this.Painter, (TValue)newValue);
updateOtherProperty?.Invoke(@this, (TValue)newValue);
void PropertyChanged(TThis @this, object? newValue) {
// We need to support nullable classes and structs, so we cannot forbid null here
// So this use of the null-forgiving operator should be blamed on non-generic PropertyChanged handlers
var @new = (TValue)newValue!;
propertySet(@this.Painter, @new);
updateOtherProperty?.Invoke(@this, @new);
if (affectsMeasure) @this.InvalidateMeasure();
// Redraw immediately! No deferred drawing
#if Avalonia
Expand All @@ -54,10 +57,9 @@ void PropertyChanged(TThis @this, object newValue) {
public BaseView() {
// Respect built-in styles
Styles.Add(new global::Avalonia.Styling.Style(global::Avalonia.Styling.Selectors.Is<BaseView<TPainter, TContent>>) {
Setters = new[]
Setters =
{
new global::Avalonia.Styling.Setter(TextColorProperty, new global::Avalonia.Markup.Xaml.MarkupExtensions.DynamicResourceExtension("ThemeForegroundColor")),
new global::Avalonia.Styling.Setter(FontSizeProperty, new global::Avalonia.Markup.Xaml.MarkupExtensions.DynamicResourceExtension("FontSizeNormal"))
new global::Avalonia.Styling.Setter(TextColorProperty, new global::Avalonia.Markup.Xaml.MarkupExtensions.DynamicResourceExtension("SystemBaseHighColor"))
}
});
}
Expand Down