From 783498de7cf481d972eadb2f56e1b25921e13123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Komosi=C5=84ski?= Date: Mon, 17 May 2021 11:05:24 +0200 Subject: [PATCH] Merge pull request #5926 from MarchingCube/devtools-layout-ux Cleanup layout visualizer and improve UX. --- .../ViewModels/ControlLayoutViewModel.cs | 29 ++- .../Diagnostics/Views/ControlDetailsView.xaml | 186 +++++++++++------- .../Diagnostics/Views/ThicknessEditor.cs | 21 +- 3 files changed, 145 insertions(+), 91 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs index fd2e4c3355..ef227f7374 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/ControlLayoutViewModel.cs @@ -1,4 +1,6 @@ +using System; using System.ComponentModel; +using System.Text; using Avalonia.Controls; using Avalonia.Layout; using Avalonia.VisualTree; @@ -95,12 +97,27 @@ namespace Avalonia.Diagnostics.ViewModels { string CreateConstraintInfo(StyledProperty minProperty, StyledProperty maxProperty) { - if (ao.IsSet(minProperty) || ao.IsSet(maxProperty)) + bool hasMin = ao.IsSet(minProperty); + bool hasMax = ao.IsSet(maxProperty); + + if (hasMin || hasMax) { - var minValue = ao.GetValue(minProperty); - var maxValue = ao.GetValue(maxProperty); + var builder = new StringBuilder(); + + if (hasMin) + { + var minValue = ao.GetValue(minProperty); + builder.AppendFormat("Min: {0}", Math.Round(minValue, 2)); + builder.AppendLine(); + } + + if (hasMax) + { + var maxValue = ao.GetValue(maxProperty); + builder.AppendFormat("Max: {0}", Math.Round(maxValue, 2)); + } - return $"{minValue} < size < {maxValue}"; + return builder.ToString(); } return null; @@ -183,8 +200,8 @@ namespace Avalonia.Diagnostics.ViewModels { var size = _control.Bounds; - Width = size.Width; - Height = size.Height; + Width = Math.Round(size.Width, 2); + Height = Math.Round(size.Height, 2); } } } diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml index 9ba576c826..50534e77b8 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml @@ -8,11 +8,16 @@ + + + + + @@ -24,43 +29,60 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -110,47 +132,67 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs index c7611c8c46..2f03a23fdf 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/ThicknessEditor.cs @@ -1,21 +1,9 @@ using Avalonia.Controls; using Avalonia.Data; -using Avalonia.Data.Converters; using Avalonia.Media; namespace Avalonia.Diagnostics.Views { - internal static class Converters - { - public static IValueConverter HasConstraintConverter = - new FuncValueConverter(ConvertToDecoration); - - private static TextDecorationCollection ConvertToDecoration(object arg) - { - return arg != null ? TextDecorations.Underline : null; - } - } - internal class ThicknessEditor : ContentControl { public static readonly DirectProperty ThicknessProperty = @@ -44,6 +32,14 @@ namespace Avalonia.Diagnostics.Views AvaloniaProperty.RegisterDirect(nameof(Bottom), o => o.Bottom, (o, v) => o.Bottom = v); + public static readonly StyledProperty HighlightProperty = + AvaloniaProperty.Register(nameof(Highlight)); + + public IBrush Highlight + { + get => GetValue(HighlightProperty); + set => SetValue(HighlightProperty, value); + } private Thickness _thickness; private string _header; @@ -52,7 +48,6 @@ namespace Avalonia.Diagnostics.Views private double _top; private double _right; private double _bottom; - private bool _isUpdatingThickness; public Thickness Thickness