From 349d7e9e6763d9d477fc57945f992675b5c480de Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 23 Jun 2023 19:38:08 -0400 Subject: [PATCH 1/6] Fix compat fluent theme not being applied --- .../DensityStyles/Compact.xaml | 13 +++---- src/Avalonia.Themes.Fluent/FluentTheme.xaml | 2 +- .../FluentTheme.xaml.cs | 35 +++++++++---------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml b/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml index d335e6f4b9..f6efefa05a 100644 --- a/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml +++ b/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml @@ -1,10 +1,3 @@ - - - 14 14 24 @@ -18,5 +11,7 @@ 24 12,1,0,3 32 - - + + diff --git a/src/Avalonia.Themes.Fluent/FluentTheme.xaml b/src/Avalonia.Themes.Fluent/FluentTheme.xaml index c84772aa61..f4467e40ce 100644 --- a/src/Avalonia.Themes.Fluent/FluentTheme.xaml +++ b/src/Avalonia.Themes.Fluent/FluentTheme.xaml @@ -18,7 +18,7 @@ - + diff --git a/src/Avalonia.Themes.Fluent/FluentTheme.xaml.cs b/src/Avalonia.Themes.Fluent/FluentTheme.xaml.cs index 5af22dbd1d..378041356a 100644 --- a/src/Avalonia.Themes.Fluent/FluentTheme.xaml.cs +++ b/src/Avalonia.Themes.Fluent/FluentTheme.xaml.cs @@ -16,9 +16,10 @@ namespace Avalonia.Themes.Fluent /// /// Includes the fluent theme in an application. /// - public class FluentTheme : Styles + public class FluentTheme : Styles, IResourceNode { - private readonly Styles _compactStyles; + private readonly ResourceDictionary _compactStyles; + private DensityStyle _densityStyle; /// /// Initializes a new instance of the class. @@ -28,9 +29,7 @@ namespace Avalonia.Themes.Fluent { AvaloniaXamlLoader.Load(sp, this); - _compactStyles = (Styles)GetAndRemove("CompactStyles"); - - EnsureCompactStyles(); + _compactStyles = (ResourceDictionary)GetAndRemove("CompactStyles"); Palettes = Resources.MergedDictionaries.OfType().FirstOrDefault() ?? throw new InvalidOperationException("FluentTheme was initialized with missing ColorPaletteResourcesCollection."); @@ -43,17 +42,17 @@ namespace Avalonia.Themes.Fluent return val; } } - - public static readonly StyledProperty DensityStyleProperty = - AvaloniaProperty.Register(nameof(DensityStyle)); + + public static readonly DirectProperty DensityStyleProperty = AvaloniaProperty.RegisterDirect( + nameof(DensityStyle), o => o.DensityStyle, (o, v) => o.DensityStyle = v); /// /// Gets or sets the density style of the fluent theme (normal, compact). /// public DensityStyle DensityStyle { - get => GetValue(DensityStyleProperty); - set => SetValue(DensityStyleProperty, value); + get => _densityStyle; + set => SetAndRaise(DensityStyleProperty, ref _densityStyle, value); } public IDictionary Palettes { get; } @@ -64,20 +63,20 @@ namespace Avalonia.Themes.Fluent if (change.Property == DensityStyleProperty) { - EnsureCompactStyles(); + Owner?.NotifyHostedResourcesChanged(ResourcesChangedEventArgs.Empty); } } - private void EnsureCompactStyles() + bool IResourceNode.TryGetResource(object key, ThemeVariant? theme, out object? value) { - if (DensityStyle == DensityStyle.Compact) + // DensityStyle dictionary should be checked first + if (_densityStyle == DensityStyle.Compact + && _compactStyles.TryGetResource(key, theme, out value)) { - Add(_compactStyles); - } - else - { - Remove(_compactStyles); + return true; } + + return base.TryGetResource(key, theme, out value); } } } From dcd1b59d3101a3d28d47fe3e888371a83b12d6b1 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 23 Jun 2023 19:38:55 -0400 Subject: [PATCH 2/6] Make compact resources better --- .../DensityStyles/Compact.xaml | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml b/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml index f6efefa05a..830198f6d1 100644 --- a/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml +++ b/src/Avalonia.Themes.Fluent/DensityStyles/Compact.xaml @@ -1,17 +1,25 @@ - 14 - 14 - 24 - 2,2,6,1 - 32 - 24 - 0,1,0,2 - 0,1,0,2 - 9,0,0,1 - 10,0,30,0 - 24 - 12,1,0,3 - 32  + 14 + 14 + 24 + 32 + 4, 2 + 4,2 + 24 + 11,5,11,7 + 4 4 8 4 + 5, 2 + 24 + 0,1,0,2 + 0,1,0,2 + 9,0,0,1 + 10,0,30,0 + 24 + 12,1,0,3 + 32 + 28 + 6, 0 + 6,4 From 5fb1cf9f829c437befd163ea9ab6b5657e03e1af Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Mon, 26 Jun 2023 11:43:44 +0200 Subject: [PATCH 3/6] Fix DataGridColumn.CellStyleClasses not settable from xaml --- src/Avalonia.Controls.DataGrid/DataGridColumn.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs index d28c0969c4..a5695afeb7 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridColumn.cs @@ -38,7 +38,7 @@ namespace Avalonia.Controls private ICellEditBinding _editBinding; private IBinding _clipboardContentBinding; private ControlTheme _cellTheme; - private readonly Classes _cellStyleClasses = new Classes(); + private Classes _cellStyleClasses; /// /// Initializes a new instance of the class. @@ -393,17 +393,7 @@ namespace Avalonia.Controls } } - public Classes CellStyleClasses - { - get => _cellStyleClasses; - set - { - if(_cellStyleClasses != value) - { - _cellStyleClasses.Replace(value); - } - } - } + public Classes CellStyleClasses => _cellStyleClasses ??= new(); /// /// Backing field for CellTheme property. From 862c175725bfb3978a32d6d03e94b2a8b1f9308c Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Tue, 27 Jun 2023 12:27:30 +0200 Subject: [PATCH 4/6] Fix ScrollContentPresenter's child margin with layout rounding --- .../Presenters/ScrollContentPresenter.cs | 12 +++++-- .../Presenters/ScrollContentPresenterTests.cs | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index bd694b200c..bd3d2b5171 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -7,7 +7,7 @@ using Avalonia.Input.GestureRecognizers; using Avalonia.Utilities; using Avalonia.VisualTree; using System.Linq; -using Avalonia.Interactivity; +using Avalonia.Layout; namespace Avalonia.Controls.Presenters { @@ -473,7 +473,15 @@ namespace Avalonia.Controls.Presenters } Viewport = finalSize; - Extent = Child!.Bounds.Size.Inflate(Child.Margin); + + var childMargin = Child!.Margin; + if (Child.UseLayoutRounding) + { + var scale = LayoutHelper.GetLayoutScale(Child); + childMargin = LayoutHelper.RoundLayoutThickness(childMargin, scale, scale); + } + + Extent = Child!.Bounds.Size.Inflate(childMargin); _isAnchorElementDirty = true; return finalSize; diff --git a/tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs b/tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs index f6130d49d6..c7ea5c1b69 100644 --- a/tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs @@ -4,6 +4,7 @@ using System.Reactive.Linq; using Avalonia.Controls.Presenters; using Avalonia.Controls.Primitives; using Avalonia.Layout; +using Avalonia.UnitTests; using Xunit; namespace Avalonia.Controls.UnitTests.Presenters @@ -244,6 +245,36 @@ namespace Avalonia.Controls.UnitTests.Presenters Assert.Equal(new Size(110, 110), target.Extent); } + [Fact] + public void Extent_Should_Include_Content_Margin_Scaled_With_Layout_Rounding() + { + var root = new TestRoot + { + LayoutScaling = 1.25, + UseLayoutRounding = true + }; + + var target = new ScrollContentPresenter + { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Content = new Border + { + Width = 200, + Height = 200, + Margin = new Thickness(2) + } + }; + + root.Child = target; + target.UpdateChild(); + target.Measure(new Size(1000, 1000)); + target.Arrange(new Rect(0, 0, 1000, 1000)); + + Assert.Equal(new Size(203.2, 203.2), target.Viewport); + Assert.Equal(new Size(203.2, 203.2), target.Extent); + } + [Fact] public void Extent_Width_Should_Be_Arrange_Width_When_CanScrollHorizontally_False() { From b488afaf799eb50bcc1de5f6728024557a3373e3 Mon Sep 17 00:00:00 2001 From: Valters Melnalksnis Date: Tue, 27 Jun 2023 13:49:20 +0300 Subject: [PATCH 5/6] Fix non-configurable minimum width for DataGridColumnHeader --- src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml index 082eac60be..0cc620dae9 100644 --- a/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml +++ b/src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml @@ -42,9 +42,10 @@ - + 0.6 0.8 + 32 M1875 1011l-787 787v-1798h-128v1798l-787 -787l-90 90l941 941l941 -941z M1965 947l-941 -941l-941 941l90 90l787 -787v1798h128v-1798l787 787z @@ -174,7 +175,7 @@ VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> - + - Date: Wed, 28 Jun 2023 01:27:12 +0300 Subject: [PATCH 6/6] fix SendDataRequest re-run task --- src/Avalonia.X11/X11Clipboard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.X11/X11Clipboard.cs b/src/Avalonia.X11/X11Clipboard.cs index 04d1aae194..6e18151fae 100644 --- a/src/Avalonia.X11/X11Clipboard.cs +++ b/src/Avalonia.X11/X11Clipboard.cs @@ -224,7 +224,7 @@ namespace Avalonia.X11 private Task SendDataRequest(IntPtr format) { - if (_requestedDataTcs == null || _requestedFormatsTcs.Task.IsCompleted) + if (_requestedDataTcs == null || _requestedDataTcs.Task.IsCompleted) _requestedDataTcs = new TaskCompletionSource(); XConvertSelection(_x11.Display, _x11.Atoms.CLIPBOARD, format, format, _handle, IntPtr.Zero); return _requestedDataTcs.Task;