From 4e6f379334430a6fa5139a15c3d1d03484a6a1e7 Mon Sep 17 00:00:00 2001 From: SKProCH Date: Mon, 5 Dec 2022 20:50:13 +0300 Subject: [PATCH 1/8] Make all TextElement properties affect TextPresenter's render --- src/Avalonia.Controls/Presenters/TextPresenter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index cc1fa6c513..1381160550 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -110,7 +110,8 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { - AffectsRender(CaretBrushProperty, SelectionBrushProperty); + AffectsRender(CaretBrushProperty, SelectionBrushProperty, + TextElement.FontFamilyProperty, TextElement.FontSizeProperty, TextElement.FontStyleProperty, TextElement.FontWeightProperty, TextElement.FontStretchProperty, TextElement.ForegroundProperty); } public TextPresenter() From 3b8a2a9be2153a4c9660f17f1c53c450ebe15b89 Mon Sep 17 00:00:00 2001 From: SKProCH Date: Tue, 6 Dec 2022 12:14:49 +0300 Subject: [PATCH 2/8] Reformat AffectRender's parameters --- src/Avalonia.Controls/Presenters/TextPresenter.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 1381160550..683b8f1768 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -110,8 +110,15 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { - AffectsRender(CaretBrushProperty, SelectionBrushProperty, - TextElement.FontFamilyProperty, TextElement.FontSizeProperty, TextElement.FontStyleProperty, TextElement.FontWeightProperty, TextElement.FontStretchProperty, TextElement.ForegroundProperty); + AffectsRender( + CaretBrushProperty, + SelectionBrushProperty, + TextElement.FontFamilyProperty, + TextElement.FontSizeProperty, + TextElement.FontStyleProperty, + TextElement.FontWeightProperty, + TextElement.FontStretchProperty, + TextElement.ForegroundProperty); } public TextPresenter() From 0320fc703350195ecadb0229b95bc438b1833115 Mon Sep 17 00:00:00 2001 From: SKProCH Date: Tue, 6 Dec 2022 21:34:25 +0300 Subject: [PATCH 3/8] Remove unnecessary TextElement properties from TextPresenter's AffectRender --- src/Avalonia.Controls/Presenters/TextPresenter.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 683b8f1768..7eaff49910 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -110,15 +110,7 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { - AffectsRender( - CaretBrushProperty, - SelectionBrushProperty, - TextElement.FontFamilyProperty, - TextElement.FontSizeProperty, - TextElement.FontStyleProperty, - TextElement.FontWeightProperty, - TextElement.FontStretchProperty, - TextElement.ForegroundProperty); + AffectsRender(CaretBrushProperty, SelectionBrushProperty, TextElement.ForegroundProperty); } public TextPresenter() From 4bb3a0d8bebce6eeadca964f36f729f55bc46621 Mon Sep 17 00:00:00 2001 From: Julian Date: Mon, 12 Dec 2022 11:55:28 +0000 Subject: [PATCH 4/8] Add missing SystemControlBackgroundAltLowBrush in fluent theme --- src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml | 1 + src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml index 89841c92c0..0192fb1b54 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml @@ -36,6 +36,7 @@ + diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml index 89b646fb52..a9e5ed949a 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml @@ -36,6 +36,7 @@ + From d918d13b65c3c7f0092aeaa0d5a4f19d876fad5e Mon Sep 17 00:00:00 2001 From: wangmaotsing Date: Thu, 15 Dec 2022 11:06:01 +0800 Subject: [PATCH 5/8] DashStyle.Dashes is marked as nullable. --- src/Avalonia.Base/Media/DashStyle.cs | 8 ++++---- src/Avalonia.Base/Media/IDashStyle.cs | 2 +- src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Base/Media/DashStyle.cs b/src/Avalonia.Base/Media/DashStyle.cs index 3a30b2d32f..9c30b6f872 100644 --- a/src/Avalonia.Base/Media/DashStyle.cs +++ b/src/Avalonia.Base/Media/DashStyle.cs @@ -17,8 +17,8 @@ namespace Avalonia.Media /// /// Defines the property. /// - public static readonly StyledProperty> DashesProperty = - AvaloniaProperty.Register>(nameof(Dashes)); + public static readonly StyledProperty?> DashesProperty = + AvaloniaProperty.Register?>(nameof(Dashes)); /// /// Defines the property. @@ -83,7 +83,7 @@ namespace Avalonia.Media /// /// Gets or sets the length of alternating dashes and gaps. /// - public AvaloniaList Dashes + public AvaloniaList? Dashes { get => GetValue(DashesProperty); set => SetValue(DashesProperty, value); @@ -98,7 +98,7 @@ namespace Avalonia.Media set => SetValue(OffsetProperty, value); } - IReadOnlyList IDashStyle.Dashes => Dashes; + IReadOnlyList? IDashStyle.Dashes => Dashes; /// /// Raised when the dash style changes. diff --git a/src/Avalonia.Base/Media/IDashStyle.cs b/src/Avalonia.Base/Media/IDashStyle.cs index 7208216603..b988ad210a 100644 --- a/src/Avalonia.Base/Media/IDashStyle.cs +++ b/src/Avalonia.Base/Media/IDashStyle.cs @@ -12,7 +12,7 @@ namespace Avalonia.Media /// /// Gets or sets the length of alternating dashes and gaps. /// - IReadOnlyList Dashes { get; } + IReadOnlyList? Dashes { get; } /// /// Gets or sets how far in the dash sequence the stroke will start. diff --git a/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs b/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs index 82485c13b0..1f53f06955 100644 --- a/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs +++ b/src/Avalonia.Base/Media/Immutable/ImmutableDashStyle.cs @@ -17,7 +17,7 @@ namespace Avalonia.Media.Immutable /// /// The dashes collection. /// The dash sequence offset. - public ImmutableDashStyle(IEnumerable dashes, double offset) + public ImmutableDashStyle(IEnumerable? dashes, double offset) { _dashes = dashes?.ToArray() ?? Array.Empty(); Offset = offset; @@ -69,7 +69,7 @@ namespace Avalonia.Media.Immutable return hashCode; } - private static bool SequenceEqual(IReadOnlyList left, IReadOnlyList right) + private static bool SequenceEqual(IReadOnlyList left, IReadOnlyList? right) { if (ReferenceEquals(left, right)) { From 155a65284070e9f566b54535fc15a8be8f663faf Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Thu, 15 Dec 2022 10:59:29 +0100 Subject: [PATCH 6/8] fix(AngleWin32PlatformGraphics): dead code --- .../Avalonia.Win32/OpenGl/Angle/AngleWin32PlatformGraphics.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32PlatformGraphics.cs b/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32PlatformGraphics.cs index 9b4eefd170..9a829aff92 100644 --- a/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32PlatformGraphics.cs +++ b/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleWin32PlatformGraphics.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.ExceptionServices; using Avalonia.Logging; using Avalonia.OpenGL; using Avalonia.OpenGL.Angle; @@ -88,8 +87,6 @@ internal class AngleWin32PlatformGraphics : IPlatformGraphics return null; } - return new AngleWin32PlatformGraphics(egl, AngleWin32EglDisplay.CreateSharedD3D11Display(egl)); - foreach (var api in (options?.AllowedPlatformApis ?? new [] { AngleOptions.PlatformApi.DirectX11 From 362d38649f4af4afe05d20d52e4e1dd108d71314 Mon Sep 17 00:00:00 2001 From: Dmitry Zhelnin Date: Thu, 15 Dec 2022 15:25:59 +0300 Subject: [PATCH 7/8] Skia drawing context: support odd number of dashes --- src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 848da1bfb6..a7bec62366 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -1137,11 +1137,14 @@ namespace Avalonia.Skia if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0) { var srcDashes = pen.DashStyle.Dashes; - var dashesArray = new float[srcDashes.Count]; - for (var i = 0; i < srcDashes.Count; ++i) + var count = srcDashes.Count % 2 == 0 ? srcDashes.Count : srcDashes.Count * 2; + + var dashesArray = new float[count]; + + for (var i = 0; i < count; ++i) { - dashesArray[i] = (float) srcDashes[i] * paint.StrokeWidth; + dashesArray[i] = (float) srcDashes[i % srcDashes.Count] * paint.StrokeWidth; } var offset = (float)(pen.DashStyle.Offset * pen.Thickness); From 71121229518225d5c5644cd733c48d9925187a20 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Thu, 15 Dec 2022 17:11:25 +0100 Subject: [PATCH 8/8] feat: Enable Rule CS0162 --- .editorconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.editorconfig b/.editorconfig index 7995062f9f..ff7ac5d69e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -140,6 +140,8 @@ dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomme # CS1591: Missing XML comment for publicly visible type or member dotnet_diagnostic.CS1591.severity = suggestion +# CS0162: Remove unreachable code +dotnet_diagnostic.CS0162.severity = error # CA1304: Specify CultureInfo dotnet_diagnostic.CA1304.severity = warning # CA1802: Use literals where appropriate