From 229c8b7f12762ce4f37c241c13c15e50bde83c1b Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Fri, 29 May 2020 00:36:15 +0200 Subject: [PATCH 01/85] Benchmark and simple optimization for INPC accessor. --- .../Plugins/InpcPropertyAccessorPlugin.cs | 8 ++- .../Data/PropertyAccessorBenchmarks.cs | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tests/Avalonia.Benchmarks/Data/PropertyAccessorBenchmarks.cs diff --git a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs index f2ed86d2aa..84ef0fb695 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs @@ -1,7 +1,5 @@ using System; using System.ComponentModel; -using System.Linq; -using System.Reactive.Linq; using System.Reflection; using Avalonia.Utilities; @@ -31,7 +29,11 @@ namespace Avalonia.Data.Core.Plugins Contract.Requires(propertyName != null); reference.TryGetTarget(out object instance); - var p = instance.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == propertyName); + + const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | + BindingFlags.Static | BindingFlags.Instance; + + var p = instance.GetType().GetProperty(propertyName, bindingFlags); if (p != null) { diff --git a/tests/Avalonia.Benchmarks/Data/PropertyAccessorBenchmarks.cs b/tests/Avalonia.Benchmarks/Data/PropertyAccessorBenchmarks.cs new file mode 100644 index 0000000000..5c2502422a --- /dev/null +++ b/tests/Avalonia.Benchmarks/Data/PropertyAccessorBenchmarks.cs @@ -0,0 +1,57 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using Avalonia.Data.Core.Plugins; +using BenchmarkDotNet.Attributes; +using JetBrains.Annotations; + +namespace Avalonia.Benchmarks.Data +{ + [MemoryDiagnoser, InProcess] + public class PropertyAccessorBenchmarks + { + private readonly InpcPropertyAccessorPlugin _plugin = new InpcPropertyAccessorPlugin(); + private readonly TestObject _targetStrongRef = new TestObject(); + private readonly WeakReference _targetWeakRef; + + public PropertyAccessorBenchmarks() + { + _targetWeakRef = new WeakReference(_targetStrongRef); + } + + [Benchmark] + public void InpcAccessor() + { + _plugin.Start(_targetWeakRef, nameof(TestObject.Test)); + } + + private class TestObject : INotifyPropertyChanged + { + private string _test; + + public string Test + { + get => _test; + set + { + if (_test == value) + { + return; + } + + _test = value; + + OnPropertyChanged(); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } + } +} From aa934c81f6f613935683615e25073ed45af93a93 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 11:39:59 +0800 Subject: [PATCH 02/85] Porting resources --- .../Accents/FluentBaseDark.xaml | 28 +++++++++- .../Accents/FluentBaseLight.xaml | 28 +++++++++- .../Accents/FluentControlResourcesDark.xaml | 55 ++++++++++++++++++- .../Accents/FluentControlResourcesLight.xaml | 55 ++++++++++++++++++- 4 files changed, 154 insertions(+), 12 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml index 292870c3cf..e8e4c96786 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml @@ -1,6 +1,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml index f734e1eff8..b693df38f4 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml @@ -1,6 +1,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index 3f9dc68383..1de481b40b 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -1,6 +1,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index 46b8f4422c..1b755c133d 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -1,6 +1,6 @@ - From cbc94cd708662b603572a91dcd639cbbf050235d Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 12:04:45 +0800 Subject: [PATCH 03/85] WIP --- src/Avalonia.Themes.Default/Slider.xaml | 329 ++++++++++++++++++------ 1 file changed, 246 insertions(+), 83 deletions(-) diff --git a/src/Avalonia.Themes.Default/Slider.xaml b/src/Avalonia.Themes.Default/Slider.xaml index b21cbf3650..f9857be906 100644 --- a/src/Avalonia.Themes.Default/Slider.xaml +++ b/src/Avalonia.Themes.Default/Slider.xaml @@ -1,93 +1,256 @@ - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + From e4ff69e0c724fffc4455a0f940ce1b9b5a71c3da Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 12:12:26 +0800 Subject: [PATCH 04/85] swap --- src/Avalonia.Themes.Default/Slider.xaml | 331 ++++++------------------ src/Avalonia.Themes.Fluent/Slider.xaml | 329 +++++++++++++++++------ 2 files changed, 330 insertions(+), 330 deletions(-) diff --git a/src/Avalonia.Themes.Default/Slider.xaml b/src/Avalonia.Themes.Default/Slider.xaml index f9857be906..9196663dd0 100644 --- a/src/Avalonia.Themes.Default/Slider.xaml +++ b/src/Avalonia.Themes.Default/Slider.xaml @@ -1,256 +1,93 @@ - - - 0,0,0,4 - 15 - 15 - 32 - 32 - 10 - 20 - 20 - 20 - 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - + + \ No newline at end of file diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index b21cbf3650..f9857be906 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -1,93 +1,256 @@ - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + From b689ba3c6d23b6f7710f944196a74c04a0b47ab0 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 14:21:04 +0800 Subject: [PATCH 05/85] port visual states --- src/Avalonia.Themes.Fluent/Slider.xaml | 266 +++++++++++-------------- 1 file changed, 116 insertions(+), 150 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index f9857be906..014095b924 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -1,5 +1,4 @@ - + 0,0,0,4 15 @@ -12,8 +11,7 @@ 20 20 - - + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + - - - - - + + - + - - - - - + + - - + + - - - - - - - - - - - From f255f2685e0eba530b4b0f8bcc0b77eb0c94ce49 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 15:13:32 +0800 Subject: [PATCH 06/85] try making slider work --- src/Avalonia.Controls/Slider.cs | 15 +- src/Avalonia.Themes.Fluent/Slider.xaml | 207 +++++++++--------- src/Avalonia.Visuals/Media/Color.cs | 2 + .../Media/ColorToSolidColorBrushConverter.cs | 36 +++ 4 files changed, 148 insertions(+), 112 deletions(-) create mode 100644 src/Avalonia.Visuals/Media/ColorToSolidColorBrushConverter.cs diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index e92c8faf20..9faf77d445 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -94,9 +94,18 @@ namespace Avalonia.Controls _increaseButton.Click -= IncreaseClick; } - _decreaseButton = e.NameScope.Find - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - From 3b48112e1d3f44beaf0df52eb738554e3bd81e57 Mon Sep 17 00:00:00 2001 From: amwx Date: Fri, 29 May 2020 04:24:07 -0500 Subject: [PATCH 17/85] Fluent Calendar Style --- src/Avalonia.Themes.Fluent/Calendar.xaml | 2 +- src/Avalonia.Themes.Fluent/CalendarButton.xaml | 9 ++++++--- src/Avalonia.Themes.Fluent/CalendarDayButton.xaml | 14 ++++++-------- src/Avalonia.Themes.Fluent/CalendarItem.xaml | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Calendar.xaml b/src/Avalonia.Themes.Fluent/Calendar.xaml index 2fbc705d83..6ae334dbae 100644 --- a/src/Avalonia.Themes.Fluent/Calendar.xaml +++ b/src/Avalonia.Themes.Fluent/Calendar.xaml @@ -5,7 +5,7 @@ // All other rights reserved. --> - + diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml index 87cc0d38a0..ba765dcb74 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml @@ -1,4 +1,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index f09569e613..70a9fcacef 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -1,6 +1,6 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index 97497495be..90179184f5 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -1,6 +1,6 @@ - From 6005d3fdbfaaa6fab47cf471faff348d72420dd4 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 12:04:45 +0800 Subject: [PATCH 20/85] WIP --- src/Avalonia.Themes.Default/Slider.xaml | 329 ++++++++++++++++++------ 1 file changed, 246 insertions(+), 83 deletions(-) diff --git a/src/Avalonia.Themes.Default/Slider.xaml b/src/Avalonia.Themes.Default/Slider.xaml index b21cbf3650..f9857be906 100644 --- a/src/Avalonia.Themes.Default/Slider.xaml +++ b/src/Avalonia.Themes.Default/Slider.xaml @@ -1,93 +1,256 @@ - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + From 703ff980949fe896284e5dbdf5e163719a6f6a31 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 12:12:26 +0800 Subject: [PATCH 21/85] swap --- src/Avalonia.Themes.Default/Slider.xaml | 331 ++++++------------------ src/Avalonia.Themes.Fluent/Slider.xaml | 329 +++++++++++++++++------ 2 files changed, 330 insertions(+), 330 deletions(-) diff --git a/src/Avalonia.Themes.Default/Slider.xaml b/src/Avalonia.Themes.Default/Slider.xaml index f9857be906..9196663dd0 100644 --- a/src/Avalonia.Themes.Default/Slider.xaml +++ b/src/Avalonia.Themes.Default/Slider.xaml @@ -1,256 +1,93 @@ - - - 0,0,0,4 - 15 - 15 - 32 - 32 - 10 - 20 - 20 - 20 - 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - + + \ No newline at end of file diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index b21cbf3650..f9857be906 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -1,93 +1,256 @@ - - - + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + From 4c7bcc09cfa542d974230d7e45bcc6bdca74ee62 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 14:21:04 +0800 Subject: [PATCH 22/85] port visual states --- src/Avalonia.Themes.Fluent/Slider.xaml | 266 +++++++++++-------------- 1 file changed, 116 insertions(+), 150 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index f9857be906..014095b924 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -1,5 +1,4 @@ - + 0,0,0,4 15 @@ -12,8 +11,7 @@ 20 20 - - + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + - - - - - + + - + - - - - - + + - - + + - - - - - - - - - - - From c577f6a5bdc613662ee5909b689921ebcb774129 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Thu, 28 May 2020 15:13:32 +0800 Subject: [PATCH 23/85] try making slider work --- src/Avalonia.Controls/Slider.cs | 15 +- src/Avalonia.Themes.Fluent/Slider.xaml | 207 +++++++++--------- src/Avalonia.Visuals/Media/Color.cs | 2 + .../Media/ColorToSolidColorBrushConverter.cs | 36 +++ 4 files changed, 148 insertions(+), 112 deletions(-) create mode 100644 src/Avalonia.Visuals/Media/ColorToSolidColorBrushConverter.cs diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index e92c8faf20..9faf77d445 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -94,9 +94,18 @@ namespace Avalonia.Controls _increaseButton.Click -= IncreaseClick; } - _decreaseButton = e.NameScope.Find - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - From 5065e6c072020860312c01053365105759c5e7eb Mon Sep 17 00:00:00 2001 From: amwx Date: Fri, 29 May 2020 04:24:07 -0500 Subject: [PATCH 35/85] Fluent Calendar Style --- src/Avalonia.Themes.Fluent/Calendar.xaml | 2 +- src/Avalonia.Themes.Fluent/CalendarButton.xaml | 9 ++++++--- src/Avalonia.Themes.Fluent/CalendarDayButton.xaml | 14 ++++++-------- src/Avalonia.Themes.Fluent/CalendarItem.xaml | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Calendar.xaml b/src/Avalonia.Themes.Fluent/Calendar.xaml index 2fbc705d83..6ae334dbae 100644 --- a/src/Avalonia.Themes.Fluent/Calendar.xaml +++ b/src/Avalonia.Themes.Fluent/Calendar.xaml @@ -5,7 +5,7 @@ // All other rights reserved. --> - + --> + + diff --git a/src/Avalonia.Themes.Fluent/CalendarDayButton.xaml b/src/Avalonia.Themes.Fluent/CalendarDayButton.xaml index 4f6f5951d2..ff72044c93 100644 --- a/src/Avalonia.Themes.Fluent/CalendarDayButton.xaml +++ b/src/Avalonia.Themes.Fluent/CalendarDayButton.xaml @@ -19,12 +19,14 @@ + + + BorderThickness="0" ClipToBounds="True"> + BorderBrush="{TemplateBinding BorderBrush}"/> - + + + --> + diff --git a/src/Avalonia.Themes.Fluent/CalendarItem.xaml b/src/Avalonia.Themes.Fluent/CalendarItem.xaml index 7e17ee7075..df17da84dc 100644 --- a/src/Avalonia.Themes.Fluent/CalendarItem.xaml +++ b/src/Avalonia.Themes.Fluent/CalendarItem.xaml @@ -61,6 +61,9 @@ + + + + + + @@ -109,22 +109,22 @@ - - - + + + + + + + - - + + From cf7a9122b45d0b8d395948426808f8cc7b6a1a8d Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 30 May 2020 19:06:14 +0800 Subject: [PATCH 39/85] Fix merge conflicts --- src/Avalonia.Controls/ListBoxItem.cs | 30 +-- src/Avalonia.Controls/Mixins/PressedMixin.cs | 37 ++++ src/Avalonia.Controls/Platform/IPopupImpl.cs | 2 + src/Avalonia.Controls/Primitives/Popup.cs | 21 +- src/Avalonia.Controls/Primitives/PopupRoot.cs | 6 +- src/Avalonia.Controls/Slider.cs | 8 +- .../Utils/BorderRenderHelper.cs | 9 +- src/Avalonia.DesignerSupport/Remote/Stubs.cs | 4 + src/Avalonia.Input/NavigationDirection.cs | 2 +- src/Avalonia.Native/PopupImpl.cs | 5 + .../Accents/BaseDark.xaml | 12 +- .../Accents/BaseLight.xaml | 12 +- .../Accents/FluentBaseDark.xaml | 154 ++++++++----- .../Accents/FluentBaseLight.xaml | 153 ++++++++----- .../Accents/FluentControlResourcesDark.xaml | 149 +++++++++---- .../Accents/FluentControlResourcesLight.xaml | 149 +++++++++---- .../AutoCompleteBox.xaml | 68 ++++-- src/Avalonia.Themes.Fluent/PopupRoot.xaml | 38 ++-- src/Avalonia.Themes.Fluent/RadioButton.xaml | 207 ++++++++++++++---- src/Avalonia.Themes.Fluent/Slider.xaml | 12 +- src/Avalonia.X11/X11Window.cs | 4 + src/Windows/Avalonia.Win32/PopupImpl.cs | 34 ++- .../Mixins/PressedMixinTests.cs | 37 ++++ 23 files changed, 806 insertions(+), 347 deletions(-) create mode 100644 src/Avalonia.Controls/Mixins/PressedMixin.cs create mode 100644 tests/Avalonia.Controls.UnitTests/Mixins/PressedMixinTests.cs diff --git a/src/Avalonia.Controls/ListBoxItem.cs b/src/Avalonia.Controls/ListBoxItem.cs index 46a7ccec0b..e04c79987f 100644 --- a/src/Avalonia.Controls/ListBoxItem.cs +++ b/src/Avalonia.Controls/ListBoxItem.cs @@ -20,6 +20,7 @@ namespace Avalonia.Controls static ListBoxItem() { SelectableMixin.Attach(IsSelectedProperty); + PressedMixin.Attach(); FocusableProperty.OverrideDefaultValue(true); } @@ -31,34 +32,5 @@ namespace Avalonia.Controls get { return GetValue(IsSelectedProperty); } set { SetValue(IsSelectedProperty, value); } } - - protected override void OnPointerPressed(PointerPressedEventArgs e) - { - base.OnPointerPressed(e); - - if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) - { - UpdatePseudoClasses(true); - } - } - - protected override void OnPointerReleased(PointerReleasedEventArgs e) - { - base.OnPointerReleased(e); - - UpdatePseudoClasses(false); - } - - protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e) - { - base.OnPointerCaptureLost(e); - - UpdatePseudoClasses(false); - } - - private void UpdatePseudoClasses(bool isPressed) - { - PseudoClasses.Set(":pressed", isPressed); - } } } diff --git a/src/Avalonia.Controls/Mixins/PressedMixin.cs b/src/Avalonia.Controls/Mixins/PressedMixin.cs new file mode 100644 index 0000000000..4c5792b4a0 --- /dev/null +++ b/src/Avalonia.Controls/Mixins/PressedMixin.cs @@ -0,0 +1,37 @@ +using Avalonia.Interactivity; +using Avalonia.Input; + +namespace Avalonia.Controls.Mixins +{ + /// + /// Adds pressed functionality to control classes. + /// + /// Adds the ':pressed' class when the item is pressed. + /// + public static class PressedMixin + { + /// + /// Initializes a new instance of the class. + /// + /// The control type. + public static void Attach() where TControl : Control + { + InputElement.PointerPressedEvent.AddClassHandler((x, e) => HandlePointerPressed(x, e), RoutingStrategies.Tunnel); + InputElement.PointerReleasedEvent.AddClassHandler((x, e) => HandlePointerReleased(x), RoutingStrategies.Tunnel); + InputElement.PointerCaptureLostEvent.AddClassHandler((x, e) => HandlePointerReleased(x), RoutingStrategies.Tunnel); + } + + private static void HandlePointerPressed(TControl sender, PointerPressedEventArgs e) where TControl : Control + { + if (e.GetCurrentPoint(sender).Properties.IsLeftButtonPressed) + { + ((IPseudoClasses)sender.Classes).Set(":pressed", true); + } + } + + private static void HandlePointerReleased(TControl sender) where TControl : Control + { + ((IPseudoClasses)sender.Classes).Set(":pressed", false); + } + } +} diff --git a/src/Avalonia.Controls/Platform/IPopupImpl.cs b/src/Avalonia.Controls/Platform/IPopupImpl.cs index 3944695f04..477d5fab43 100644 --- a/src/Avalonia.Controls/Platform/IPopupImpl.cs +++ b/src/Avalonia.Controls/Platform/IPopupImpl.cs @@ -8,5 +8,7 @@ namespace Avalonia.Platform public interface IPopupImpl : IWindowBaseImpl { IPopupPositioner PopupPositioner { get; } + + void SetWindowManagerAddShadowHint(bool enabled); } } diff --git a/src/Avalonia.Controls/Primitives/Popup.cs b/src/Avalonia.Controls/Primitives/Popup.cs index 66f2153b6c..49315e1b25 100644 --- a/src/Avalonia.Controls/Primitives/Popup.cs +++ b/src/Avalonia.Controls/Primitives/Popup.cs @@ -19,6 +19,9 @@ namespace Avalonia.Controls.Primitives /// public class Popup : Control, IVisualTreeHost { + public static readonly StyledProperty WindowManagerAddShadowHintProperty = + AvaloniaProperty.Register(nameof(WindowManagerAddShadowHint), true); + /// /// Defines the property. /// @@ -89,7 +92,7 @@ namespace Avalonia.Controls.Primitives { IsHitTestVisibleProperty.OverrideDefaultValue(false); ChildProperty.Changed.AddClassHandler((x, e) => x.ChildChanged(e)); - IsOpenProperty.Changed.AddClassHandler((x, e) => x.IsOpenChanged((AvaloniaPropertyChangedEventArgs)e)); + IsOpenProperty.Changed.AddClassHandler((x, e) => x.IsOpenChanged((AvaloniaPropertyChangedEventArgs)e)); } /// @@ -104,6 +107,12 @@ namespace Avalonia.Controls.Primitives public IPopupHost? Host => _openState?.PopupHost; + public bool WindowManagerAddShadowHint + { + get { return GetValue(WindowManagerAddShadowHintProperty); } + set { SetValue(WindowManagerAddShadowHintProperty, value); } + } + /// /// Gets or sets the control to display in the popup. /// @@ -293,6 +302,8 @@ namespace Avalonia.Controls.Primitives _openState = new PopupOpenState(topLevel, popupHost, cleanupPopup); + WindowManagerAddShadowHintChanged(popupHost, WindowManagerAddShadowHint); + popupHost.Show(); using (BeginIgnoringIsOpen()) @@ -332,6 +343,14 @@ namespace Avalonia.Controls.Primitives return Disposable.Create((unsubscribe, target, handler), state => state.unsubscribe(state.target, state.handler)); } + private void WindowManagerAddShadowHintChanged(IPopupHost host, bool hint) + { + if(host is PopupRoot pr) + { + pr.PlatformImpl.SetWindowManagerAddShadowHint(hint); + } + } + /// /// Called when the property changes. /// diff --git a/src/Avalonia.Controls/Primitives/PopupRoot.cs b/src/Avalonia.Controls/Primitives/PopupRoot.cs index 788fe03162..aab7a68795 100644 --- a/src/Avalonia.Controls/Primitives/PopupRoot.cs +++ b/src/Avalonia.Controls/Primitives/PopupRoot.cs @@ -17,14 +17,14 @@ namespace Avalonia.Controls.Primitives public sealed class PopupRoot : WindowBase, IInteractive, IHostedVisualTreeRoot, IDisposable, IStyleHost, IPopupHost { private readonly TopLevel _parent; - private PopupPositionerParameters _positionerParameters; + private PopupPositionerParameters _positionerParameters; /// /// Initializes static members of the class. /// static PopupRoot() { - BackgroundProperty.OverrideDefaultValue(typeof(PopupRoot), Brushes.White); + BackgroundProperty.OverrideDefaultValue(typeof(PopupRoot), Brushes.White); } /// @@ -53,7 +53,7 @@ namespace Avalonia.Controls.Primitives /// Gets the platform-specific window implementation. /// [CanBeNull] - public new IPopupImpl PlatformImpl => (IPopupImpl)base.PlatformImpl; + public new IPopupImpl PlatformImpl => (IPopupImpl)base.PlatformImpl; /// /// Gets the parent control in the event route. diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index b218c003c2..2db7c5cb83 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -1,6 +1,6 @@ using System; +using Avalonia.Controls.Mixins; using Avalonia.Controls.Primitives; -using Avalonia.Data; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Layout; @@ -40,13 +40,11 @@ namespace Avalonia.Controls /// static Slider() { + PressedMixin.Attach(); OrientationProperty.OverrideDefaultValue(typeof(Slider), Orientation.Horizontal); Thumb.DragStartedEvent.AddClassHandler((x, e) => x.OnThumbDragStarted(e), RoutingStrategies.Bubble); Thumb.DragDeltaEvent.AddClassHandler((x, e) => x.OnThumbDragDelta(e), RoutingStrategies.Bubble); - Thumb.DragCompletedEvent.AddClassHandler((x, e) => x.OnThumbDragCompleted(e), RoutingStrategies.Bubble); - PointerPressedEvent.AddClassHandler((x, e) => x.HandlePointerPressed(e), RoutingStrategies.Tunnel, true); - PointerReleasedEvent.AddClassHandler((x, e) => x.HandlePointerReleased(), RoutingStrategies.Tunnel, true); - PointerCaptureLostEvent.AddClassHandler((x, e) => x.HandlePointerReleased(), RoutingStrategies.Tunnel, true); + Thumb.DragCompletedEvent.AddClassHandler((x, e) => x.OnThumbDragCompleted(e), RoutingStrategies.Bubble); } /// diff --git a/src/Avalonia.Controls/Utils/BorderRenderHelper.cs b/src/Avalonia.Controls/Utils/BorderRenderHelper.cs index 586fe4d341..51eb6edbea 100644 --- a/src/Avalonia.Controls/Utils/BorderRenderHelper.cs +++ b/src/Avalonia.Controls/Utils/BorderRenderHelper.cs @@ -118,12 +118,11 @@ namespace Avalonia.Controls.Utils pen = new Pen(borderBrush, borderThickness); } - var rrect = new RoundedRect(new Rect(_size), _cornerRadius.TopLeft, _cornerRadius.TopRight, - _cornerRadius.BottomRight, _cornerRadius.BottomLeft); + var rect = new Rect(_size); if (Math.Abs(borderThickness) > double.Epsilon) - { - rrect = rrect.Deflate(borderThickness * 0.5, borderThickness * 0.5); - } + rect = rect.Deflate(borderThickness * 0.5); + var rrect = new RoundedRect(rect, _cornerRadius.TopLeft, _cornerRadius.TopRight, + _cornerRadius.BottomRight, _cornerRadius.BottomLeft); context.PlatformImpl.DrawRectangle(background, pen, rrect, boxShadows); } diff --git a/src/Avalonia.DesignerSupport/Remote/Stubs.cs b/src/Avalonia.DesignerSupport/Remote/Stubs.cs index a9665b1519..c2565cc59c 100644 --- a/src/Avalonia.DesignerSupport/Remote/Stubs.cs +++ b/src/Avalonia.DesignerSupport/Remote/Stubs.cs @@ -146,6 +146,10 @@ namespace Avalonia.DesignerSupport.Remote public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) { } + public void SetWindowManagerAddShadowHint(bool enabled) + { + } + public WindowTransparencyLevel TransparencyLevel { get; private set; } } diff --git a/src/Avalonia.Input/NavigationDirection.cs b/src/Avalonia.Input/NavigationDirection.cs index 34bedac141..9b9af0b0a6 100644 --- a/src/Avalonia.Input/NavigationDirection.cs +++ b/src/Avalonia.Input/NavigationDirection.cs @@ -102,7 +102,7 @@ namespace Avalonia.Input switch (key) { case Key.Tab: - return (modifiers & KeyModifiers.Shift) != 0 ? + return (modifiers & KeyModifiers.Shift) == 0 ? NavigationDirection.Next : NavigationDirection.Previous; case Key.Up: return NavigationDirection.Up; diff --git a/src/Avalonia.Native/PopupImpl.cs b/src/Avalonia.Native/PopupImpl.cs index e4ee293757..c41be1723b 100644 --- a/src/Avalonia.Native/PopupImpl.cs +++ b/src/Avalonia.Native/PopupImpl.cs @@ -59,6 +59,11 @@ namespace Avalonia.Native } public override IPopupImpl CreatePopup() => new PopupImpl(_factory, _opts, _glFeature, this); + + public void SetWindowManagerAddShadowHint(bool enabled) + { + } + public IPopupPositioner PopupPositioner { get; } } } diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml index 7ce6c5a19f..bf169400f0 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseDark.xaml @@ -139,6 +139,7 @@ + False @@ -159,8 +160,7 @@ 24 40 3 - 374 - 0 + 0 2 0 21 @@ -258,10 +258,10 @@ 0,0,0,0 0,0,0,0 3,0,3,0 - 1 - 0,2,0,2 - -1,0,-1,0 - 12,11,0,13 + 1 + 0,2,0,2 + -1,0,-1,0 + 12,11,0,13 2 2 2 diff --git a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml index 026edca4f9..b32c816851 100644 --- a/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/BaseLight.xaml @@ -139,6 +139,7 @@ + False @@ -158,8 +159,7 @@ 24 40 3 - 374 - 0 + 0 2 0 21 @@ -257,10 +257,10 @@ 0,0,0,0 0,0,0,0 3,0,3,0 - 1 - 0,2,0,2 - -1,0,-1,0 - 12,11,0,13 + 1 + 0,2,0,2 + -1,0,-1,0 + 12,11,0,13 2 2 2 diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml index ab4806d6cd..865f9e8759 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseDark.xaml @@ -1,5 +1,5 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml index 1d3e415e90..ae69e82ea5 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentBaseLight.xaml @@ -1,5 +1,5 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml index b395e3983f..3a992a24f9 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesDark.xaml @@ -1,5 +1,5 @@ - diff --git a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml index e1cc0302c7..575c3b33ae 100644 --- a/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml +++ b/src/Avalonia.Themes.Fluent/Accents/FluentControlResourcesLight.xaml @@ -1,5 +1,5 @@ - diff --git a/src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml b/src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml index 788b60892b..52bacdb36e 100644 --- a/src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml +++ b/src/Avalonia.Themes.Fluent/AutoCompleteBox.xaml @@ -1,37 +1,69 @@ - + + + + + + Alabama + Alaska + Arizona + Arkansas + California + Colorado + Connecticut + Delaware + + + + + diff --git a/src/Avalonia.Themes.Fluent/PopupRoot.xaml b/src/Avalonia.Themes.Fluent/PopupRoot.xaml index 9af4f5a910..25c71e3493 100644 --- a/src/Avalonia.Themes.Fluent/PopupRoot.xaml +++ b/src/Avalonia.Themes.Fluent/PopupRoot.xaml @@ -1,17 +1,21 @@ - + + + diff --git a/src/Avalonia.Themes.Fluent/RadioButton.xaml b/src/Avalonia.Themes.Fluent/RadioButton.xaml index 4cdb116cdd..23bcfc616a 100644 --- a/src/Avalonia.Themes.Fluent/RadioButton.xaml +++ b/src/Avalonia.Themes.Fluent/RadioButton.xaml @@ -1,60 +1,173 @@ + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index fff8525ebd..07dc318961 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -48,9 +48,9 @@ - - - + + + @@ -109,9 +109,9 @@ - - - + + + diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 4899f0efc0..1d41fe4bdd 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/src/Avalonia.X11/X11Window.cs @@ -1098,6 +1098,10 @@ namespace Avalonia.X11 public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) => _transparencyHelper.SetTransparencyRequest(transparencyLevel); + public void SetWindowManagerAddShadowHint(bool enabled) + { + } + public WindowTransparencyLevel TransparencyLevel => _transparencyHelper.CurrentLevel; } } diff --git a/src/Windows/Avalonia.Win32/PopupImpl.cs b/src/Windows/Avalonia.Win32/PopupImpl.cs index 504cefb9b3..efcf1ea674 100644 --- a/src/Windows/Avalonia.Win32/PopupImpl.cs +++ b/src/Windows/Avalonia.Win32/PopupImpl.cs @@ -7,6 +7,8 @@ namespace Avalonia.Win32 { class PopupImpl : WindowImpl, IPopupImpl { + private bool _dropShadowHint = true; + public override void Show() { UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate); @@ -36,11 +38,7 @@ namespace Avalonia.Win32 IntPtr.Zero, IntPtr.Zero); - var classes = (int)UnmanagedMethods.GetClassLongPtr(result, (int)UnmanagedMethods.ClassLongIndex.GCL_STYLE); - - classes |= (int)UnmanagedMethods.ClassStyles.CS_DROPSHADOW; - - UnmanagedMethods.SetClassLong(result, UnmanagedMethods.ClassLongIndex.GCL_STYLE, new IntPtr(classes)); + EnableBoxShadow(result, _dropShadowHint); return result; } @@ -68,6 +66,32 @@ namespace Avalonia.Win32 //TODO: We ignore the scaling override for now } + private void EnableBoxShadow (IntPtr hwnd, bool enabled) + { + var classes = (int)UnmanagedMethods.GetClassLongPtr(hwnd, (int)UnmanagedMethods.ClassLongIndex.GCL_STYLE); + + if (enabled) + { + classes |= (int)UnmanagedMethods.ClassStyles.CS_DROPSHADOW; + } + else + { + classes &= ~(int)UnmanagedMethods.ClassStyles.CS_DROPSHADOW; + } + + UnmanagedMethods.SetClassLong(hwnd, UnmanagedMethods.ClassLongIndex.GCL_STYLE, new IntPtr(classes)); + } + + public void SetWindowManagerAddShadowHint(bool enabled) + { + _dropShadowHint = enabled; + + if (Handle != null) + { + EnableBoxShadow(Handle.Handle, enabled); + } + } + public IPopupPositioner PopupPositioner { get; } } } diff --git a/tests/Avalonia.Controls.UnitTests/Mixins/PressedMixinTests.cs b/tests/Avalonia.Controls.UnitTests/Mixins/PressedMixinTests.cs new file mode 100644 index 0000000000..0ff1f40121 --- /dev/null +++ b/tests/Avalonia.Controls.UnitTests/Mixins/PressedMixinTests.cs @@ -0,0 +1,37 @@ +using Avalonia.Controls.Mixins; +using Avalonia.UnitTests; +using Xunit; + +namespace Avalonia.Controls.UnitTests.Mixins +{ + public class PressedMixinTests + { + private MouseTestHelper _mouse = new MouseTestHelper(); + + [Fact] + public void Selected_Class_Should_Not_Initially_Be_Added() + { + var target = new TestControl(); + + Assert.Empty(target.Classes); + } + + [Fact] + public void Setting_IsSelected_Should_Add_Selected_Class() + { + var target = new TestControl(); + + _mouse.Down(target); + + Assert.Equal(new[] { ":pressed" }, target.Classes); + } + + private class TestControl : Control + { + static TestControl() + { + PressedMixin.Attach(); + } + } + } +} From a43b080e36d8f10bec77abd7ce956a05cc1a62a6 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 30 May 2020 19:16:14 +0800 Subject: [PATCH 40/85] add TickBar styles back --- src/Avalonia.Themes.Fluent/Slider.xaml | 44 ++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index 75f64952ed..ac6ecf419a 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -58,11 +58,11 @@ - + - + - + @@ -119,11 +119,11 @@ - + - + - + @@ -175,6 +175,22 @@ + + + + + + + + + + + + + + + + From abe3914258aad5cc7cd4b97bd619761830f0584b Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 30 May 2020 19:22:57 +0800 Subject: [PATCH 41/85] fix tickbar fill --- src/Avalonia.Themes.Fluent/Slider.xaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index ac6ecf419a..77b5f9568d 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -176,19 +176,19 @@ @@ -209,19 +209,19 @@ + + - - - - - - - - - - - - - - - - + From 5f421f33788a8d5343b4064b459986fea720444f Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 30 May 2020 21:23:15 +0800 Subject: [PATCH 44/85] fix reservedspace --- src/Avalonia.Controls/TickBar.cs | 18 ------------------ src/Avalonia.Themes.Fluent/Slider.xaml | 13 ++++++++++--- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/Avalonia.Controls/TickBar.cs b/src/Avalonia.Controls/TickBar.cs index aa140a197b..b6637643e8 100644 --- a/src/Avalonia.Controls/TickBar.cs +++ b/src/Avalonia.Controls/TickBar.cs @@ -36,24 +36,6 @@ namespace Avalonia.Controls Bottom, // NOTE: if you add or remove any values in this enum, be sure to update TickBar.IsValidTickBarPlacement() - }; - - public static class TickBarConverter - { - public static readonly IValueConverter ReservedSpaceBind = - new FuncValueConverter(x => - { - if (x is null) - { - - } - if (x is Rect y) - { - return y; - } - return new Rect(); - }); - } /// diff --git a/src/Avalonia.Themes.Fluent/Slider.xaml b/src/Avalonia.Themes.Fluent/Slider.xaml index 648845f4b7..7afbac5f63 100644 --- a/src/Avalonia.Themes.Fluent/Slider.xaml +++ b/src/Avalonia.Themes.Fluent/Slider.xaml @@ -50,8 +50,12 @@ + + + - @@ -111,8 +115,12 @@ + + + - @@ -172,7 +180,6 @@ - From 546e52be154485d580b4c4f17f382cc92f7ae5de Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sat, 30 May 2020 13:31:04 -0300 Subject: [PATCH 45/85] remove unused code. --- src/Avalonia.Controls/Slider.cs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/Avalonia.Controls/Slider.cs b/src/Avalonia.Controls/Slider.cs index ba183904e3..01a23c2582 100644 --- a/src/Avalonia.Controls/Slider.cs +++ b/src/Avalonia.Controls/Slider.cs @@ -98,7 +98,7 @@ namespace Avalonia.Controls _decreaseButton = e.NameScope.Find