Skip to content

Commit 92e4e76

Browse files
Yoooi0Keboo
andauthored
Fix ColorPicker thumb jittering when dragging (#2894) (#2895)
* Fix ColorPicker thumb jittering when dragging (#2894) * Moving the failing ColorPicker test to a XAMLTest Co-authored-by: Kevin Bost <[email protected]>
1 parent 0785784 commit 92e4e76

File tree

6 files changed

+196
-191
lines changed

6 files changed

+196
-191
lines changed

MaterialDesignThemes.UITests/TestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[assembly: GenerateHelpers(typeof(SmartHint))]
66
[assembly: GenerateHelpers(typeof(TimePicker))]
77
[assembly: GenerateHelpers(typeof(DrawerHost))]
8+
[assembly: GenerateHelpers(typeof(ColorPicker))]
89

910
namespace MaterialDesignThemes.UITests;
1011

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Windows.Media;
2+
using MaterialDesignColors.ColorManipulation;
3+
4+
namespace MaterialDesignThemes.UITests.WPF;
5+
6+
public class ColorPickerTests : TestBase
7+
{
8+
public ColorPickerTests(ITestOutputHelper output)
9+
: base(output)
10+
{
11+
}
12+
13+
[Fact]
14+
public async Task OnLostFocusIfSelectedTimeIsNull_DatePartWillBeToday()
15+
{
16+
await using var recorder = new TestRecorder(App);
17+
18+
IVisualElement<ColorPicker> colorPicker = await LoadXaml<ColorPicker>(@"
19+
<materialDesign:ColorPicker Width=""400"" Height=""100"" Color=""Red""/>");
20+
21+
var thumb = await colorPicker.GetElement<Thumb>(ColorPicker.SaturationBrightnessPickerThumbPartName);
22+
23+
Color color = await colorPicker.GetColor();
24+
double lastBrightness = color.ToHsb().Brightness;
25+
26+
Rect thumbLocation = await thumb.GetCoordinates();
27+
28+
await thumb.SendInput(MouseInput.MoveToElement(Position.BottomLeft));
29+
await thumb.SendInput(MouseInput.MoveRelative(xOffset: -5, yOffset:-10));
30+
await thumb.SendInput(MouseInput.LeftDown());
31+
await thumb.SendInput(MouseInput.MoveRelative(yOffset:25));
32+
await Task.Delay(100);
33+
await thumb.SendInput(MouseInput.LeftUp());
34+
35+
36+
double currentBrightness = (await colorPicker.GetColor()).ToHsb().Brightness;
37+
Assert.True(currentBrightness < lastBrightness, $"Brightness {currentBrightness} is not less than {lastBrightness}");
38+
39+
recorder.Success();
40+
}
41+
}

MaterialDesignThemes.UITests/WPF/TimePickers/MaterialDesignTimePicker.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using System.Windows.Controls;
4-
using System.Windows.Controls.Primitives;
5-
using MaterialDesignThemes.Wpf;
6-
using XamlTest;
7-
8-
namespace MaterialDesignThemes.UITests.WPF.TimePickers;
1+
namespace MaterialDesignThemes.UITests.WPF.TimePickers;
92

103
public static class MaterialDesignTimePicker
114
{
Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
using System.IO;
2-
using System.Reflection;
3-
using System.Threading.Tasks;
4-
using System.Windows.Controls;
1+
using System.Reflection;
52
using MaterialDesignColors;
6-
using MaterialDesignThemes.UITests.WPF.DatePickers;
7-
using MaterialDesignThemes.Wpf;
8-
using XamlTest;
93

10-
namespace MaterialDesignThemes.UITests
4+
namespace MaterialDesignThemes.UITests;
5+
6+
public static class XamlTestMixins
117
{
12-
public static class XamlTestMixins
8+
public static async Task InitializeWithMaterialDesign(this IApp app,
9+
BaseTheme baseTheme = BaseTheme.Light,
10+
PrimaryColor primary = PrimaryColor.DeepPurple,
11+
SecondaryColor secondary = SecondaryColor.Lime,
12+
ColorAdjustment? colorAdjustment = null)
1313
{
14-
public static async Task InitializeWithMaterialDesign(this IApp app,
15-
BaseTheme baseTheme = BaseTheme.Light,
16-
PrimaryColor primary = PrimaryColor.DeepPurple,
17-
SecondaryColor secondary = SecondaryColor.Lime,
18-
ColorAdjustment? colorAdjustment = null)
14+
string colorAdjustString = "";
15+
if (colorAdjustment != null)
1916
{
20-
string colorAdjustString = "";
21-
if (colorAdjustment != null)
22-
{
23-
colorAdjustString = "ColorAdjustment=\"{materialDesign:ColorAdjustment}\"";
24-
}
17+
colorAdjustString = "ColorAdjustment=\"{materialDesign:ColorAdjustment}\"";
18+
}
2519

26-
string applicationResourceXaml = $@"<ResourceDictionary
20+
string applicationResourceXaml = $@"<ResourceDictionary
2721
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
2822
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
2923
xmlns:materialDesign=""http://materialdesigninxaml.net/winfx/xaml/themes"">
@@ -34,22 +28,22 @@ public static async Task InitializeWithMaterialDesign(this IApp app,
3428
<ResourceDictionary Source = ""pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"" />
3529
</ResourceDictionary.MergedDictionaries>
3630
</ResourceDictionary>";
37-
38-
await app.Initialize(applicationResourceXaml,
39-
Path.GetFullPath("MaterialDesignColors.dll"),
40-
Path.GetFullPath("MaterialDesignThemes.Wpf.dll"),
41-
Assembly.GetExecutingAssembly().Location);
42-
}
31+
32+
await app.Initialize(applicationResourceXaml,
33+
Path.GetFullPath("MaterialDesignColors.dll"),
34+
Path.GetFullPath("MaterialDesignThemes.Wpf.dll"),
35+
Assembly.GetExecutingAssembly().Location);
36+
}
4337

44-
public static async Task<IVisualElement<T>> CreateWindowWith<T>(this IApp app, string xaml, params (string namespacePrefix, Type type)[] additionalNamespaceDeclarations)
38+
public static async Task<IVisualElement<T>> CreateWindowWith<T>(this IApp app, string xaml, params (string namespacePrefix, Type type)[] additionalNamespaceDeclarations)
39+
{
40+
var extraNamespaceDeclarations = new StringBuilder("");
41+
foreach ((string namespacePrefix, Type type) in additionalNamespaceDeclarations)
4542
{
46-
var extraNamespaceDeclarations = new StringBuilder("");
47-
foreach ((string namespacePrefix, Type type) in additionalNamespaceDeclarations)
48-
{
49-
extraNamespaceDeclarations.AppendLine($@"xmlns:{namespacePrefix}=""clr-namespace:{type.Namespace};assembly={type.Assembly.GetName().Name}""");
50-
}
43+
extraNamespaceDeclarations.AppendLine($@"xmlns:{namespacePrefix}=""clr-namespace:{type.Namespace};assembly={type.Assembly.GetName().Name}""");
44+
}
5145
52-
string windowXaml = @$"<Window
46+
string windowXaml = @$"<Window
5347
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
5448
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
5549
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
@@ -70,13 +64,13 @@ public static async Task<IVisualElement<T>> CreateWindowWith<T>(this IApp app, s
7064
WindowStartupLocation=""CenterScreen"">
7165
{xaml}
7266
</Window>";
73-
IWindow window = await app.CreateWindow(windowXaml);
74-
return await window.GetElement<T>(".Content");
75-
}
67+
IWindow window = await app.CreateWindow(windowXaml);
68+
return await window.GetElement<T>(".Content");
69+
}
7670

77-
public static async Task<IVisualElement> CreateWindowWith(this IApp app, string xaml)
78-
{
79-
string windowXaml = @$"<Window
71+
public static async Task<IVisualElement> CreateWindowWith(this IApp app, string xaml)
72+
{
73+
string windowXaml = @$"<Window
8074
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
8175
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
8276
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
@@ -96,14 +90,14 @@ public static async Task<IVisualElement> CreateWindowWith(this IApp app, string
9690
WindowStartupLocation=""CenterScreen"">
9791
{xaml}
9892
</Window>";
99-
IWindow window = await app.CreateWindow(windowXaml);
100-
return await window.GetElement(".Content");
101-
}
93+
IWindow window = await app.CreateWindow(windowXaml);
94+
return await window.GetElement(".Content");
95+
}
10296

103-
public static async Task<IVisualElement> CreateWindowWithUserControl<TControl>(this IApp app)
104-
where TControl : UserControl
105-
{
106-
string windowXaml = @$"<Window
97+
public static async Task<IVisualElement> CreateWindowWithUserControl<TControl>(this IApp app)
98+
where TControl : UserControl
99+
{
100+
string windowXaml = @$"<Window
107101
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
108102
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
109103
xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
@@ -124,8 +118,7 @@ public static async Task<IVisualElement> CreateWindowWithUserControl<TControl>(t
124118
WindowStartupLocation=""CenterScreen"">
125119
<local:{typeof(TControl).Name} />
126120
</Window>";
127-
IWindow window = await app.CreateWindow(windowXaml);
128-
return await window.GetElement(".Content.Content");
129-
}
121+
IWindow window = await app.CreateWindow(windowXaml);
122+
return await window.GetElement(".Content.Content");
130123
}
131124
}

0 commit comments

Comments
 (0)