From 1f5560a8a82b5ccc7d5eed756e7aadcf07446789 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Tue, 29 Mar 2022 16:06:57 +0200 Subject: [PATCH 1/3] feat(DevTools): Open DevTools with Focused Element Automatically Selected in Tree --- src/Avalonia.Diagnostics/Diagnostics/DevTools.cs | 8 +++++--- .../Diagnostics/Views/MainWindow.xaml.cs | 10 +++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs index 683c2e6549..fad4d3146a 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs @@ -105,13 +105,15 @@ namespace Avalonia.Diagnostics private static IDisposable Open(Application? application, DevToolsOptions options, Window? owner = default) { + var focussedControl = KeyboardDevice.Instance?.FocusedElement as IControl; if (application is null) { throw new ArgumentNullException(nameof(application)); } if (s_open.TryGetValue(application, out var window)) - { + { window.Activate(); + window.SelectedControl(focussedControl); } else { @@ -122,7 +124,7 @@ namespace Avalonia.Diagnostics Height = options.Size.Height, }; window.SetOptions(options); - + window.SelectedControl(focussedControl); window.Closed += DevToolsClosed; s_open.Add(application, window); if (options.ShowAsChildWindow && owner is { }) @@ -133,7 +135,7 @@ namespace Avalonia.Diagnostics { window.Show(); } - } + } return Disposable.Create(() => window?.Close()); } } diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs index 1e152dcdd4..7abe2570e3 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainWindow.xaml.cs @@ -110,7 +110,7 @@ namespace Avalonia.Diagnostics.Views { #pragma warning disable CS0618 // Type or member is obsolete var point = (topLevel as IInputRoot)?.MouseDevice?.GetPosition(topLevel) ?? default; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0618 // Type or member is obsolete return (IControl?)topLevel.GetVisualsAt(point, x => { @@ -255,5 +255,13 @@ namespace Avalonia.Diagnostics.Views } } } + + internal void SelectedControl(IControl? control) + { + if (control is { }) + { + (DataContext as MainViewModel)?.SelectControl(control); + } + } } } From e048374c1d8a3b8fcedc9684adc0f72c2611f438 Mon Sep 17 00:00:00 2001 From: workgroupengineering Date: Tue, 29 Mar 2022 17:05:39 +0200 Subject: [PATCH 2/3] fix nits --- src/Avalonia.Diagnostics/Diagnostics/DevTools.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs index fad4d3146a..9029ddf2bd 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/DevTools.cs @@ -135,7 +135,7 @@ namespace Avalonia.Diagnostics { window.Show(); } - } + } return Disposable.Create(() => window?.Close()); } } From a06d287fb956ace8a4c41f5c9069a9d4479adf71 Mon Sep 17 00:00:00 2001 From: robloo Date: Tue, 29 Mar 2022 20:25:55 -0400 Subject: [PATCH 3/3] Switch ExperimentalAcrylicMaterial to using new HsvColor --- .../Media/ExperimentalAcrylicMaterial.cs | 62 +++---------------- 1 file changed, 8 insertions(+), 54 deletions(-) diff --git a/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs b/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs index cdea5f5fa3..0e485d0db8 100644 --- a/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs +++ b/src/Avalonia.Visuals/Media/ExperimentalAcrylicMaterial.cs @@ -142,52 +142,6 @@ namespace Avalonia.Media Color IExperimentalAcrylicMaterial.TintColor => _effectiveTintColor; - private struct HsvColor - { - public float Hue { get; set; } - public float Saturation { get; set; } - public float Value { get; set; } - } - - private static HsvColor RgbToHsv(Color color) - { - var r = color.R / 255.0f; - var g = color.G / 255.0f; - var b = color.B / 255.0f; - var max = Math.Max(r, Math.Max(g, b)); - var min = Math.Min(r, Math.Min(g, b)); - - float h, s, v; - h = v = max; - - var d = max - min; - s = max == 0 ? 0 : d / max; - - if (max == min) - { - h = 0; // achromatic - } - else - { - if (max == r) - { - h = (g - b) / d + (g < b ? 6 : 0); - } - else if (max == g) - { - h = (b - r) / d + 2; - } - else if (max == b) - { - h = (r - g) / d + 4; - } - - h /= 6; - } - - return new HsvColor { Hue = h, Saturation = s, Value = v }; - } - private static Color GetEffectiveTintColor(Color tintColor, double tintOpacity) { // Update tintColor's alpha with the combined opacity value @@ -198,7 +152,7 @@ namespace Avalonia.Media private static double GetTintOpacityModifier(Color tintColor) { - // This method supresses the maximum allowable tint opacity depending on the luminosity and saturation of a color by + // This method suppresses the maximum allowable tint opacity depending on the luminosity and saturation of a color by // compressing the range of allowable values - for example, a user-defined value of 100% will be mapped to 45% for pure // white (100% luminosity), 85% for pure black (0% luminosity), and 90% for pure gray (50% luminosity). The intensity of // the effect increases linearly as luminosity deviates from 50%. After this effect is calculated, we cancel it out @@ -210,22 +164,22 @@ namespace Avalonia.Media const double midPointMaxOpacity = 0.45; // 50% luminosity const double blackMaxOpacity = 0.45; // 0% luminosity - var hsv = RgbToHsv(tintColor); + var hsv = tintColor.ToHsv(); double opacityModifier = midPointMaxOpacity; - if (hsv.Value != midPoint) + if (hsv.V != midPoint) { // Determine maximum suppression amount double lowestMaxOpacity = midPointMaxOpacity; double maxDeviation = midPoint; - if (hsv.Value > midPoint) + if (hsv.V > midPoint) { lowestMaxOpacity = whiteMaxOpacity; // At white (100% hsvV) maxDeviation = 1 - maxDeviation; } - else if (hsv.Value < midPoint) + else if (hsv.V < midPoint) { lowestMaxOpacity = blackMaxOpacity; // At black (0% hsvV) } @@ -233,14 +187,14 @@ namespace Avalonia.Media double maxOpacitySuppression = midPointMaxOpacity - lowestMaxOpacity; // Determine normalized deviation from the midpoint - double deviation = Math.Abs(hsv.Value - midPoint); + double deviation = Math.Abs(hsv.V - midPoint); double normalizedDeviation = deviation / maxDeviation; // If we have saturation, reduce opacity suppression to allow that color to come through more - if (hsv.Saturation > 0) + if (hsv.S > 0) { // Dampen opacity suppression based on how much saturation there is - maxOpacitySuppression *= Math.Max(1 - (hsv.Saturation * 2), 0.0); + maxOpacitySuppression *= Math.Max(1 - (hsv.S * 2), 0.0); } double opacitySuppression = maxOpacitySuppression * normalizedDeviation;