Browse Source
* feat(DevTools): Focus follower * fix: remove commented code * fix: Address Review * fix: unused field * fix: missing dispose * fix: do not Avalonia.Diagnostics Popup * feat: using FocusAdornerProperty * code clean up * fix: null annotation * Revert using FocusAdornerUnsafeAsSpan-logical-children
committed by
GitHub
5 changed files with 293 additions and 18 deletions
@ -0,0 +1,47 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Controls.Primitives; |
||||
|
using Avalonia.Input; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Reactive; |
||||
|
|
||||
|
namespace Avalonia.Diagnostics.Controls; |
||||
|
|
||||
|
internal class ControlHighlightAdorner : Control |
||||
|
{ |
||||
|
|
||||
|
readonly IPen _pen; |
||||
|
|
||||
|
private ControlHighlightAdorner(IPen pen) |
||||
|
{ |
||||
|
_pen = pen; |
||||
|
this.Clip = null; |
||||
|
} |
||||
|
|
||||
|
public static IDisposable? Add(InputElement owner, IBrush highlightBrush) |
||||
|
{ |
||||
|
|
||||
|
if (AdornerLayer.GetAdornerLayer(owner) is { } layer) |
||||
|
{ |
||||
|
var pen = new Pen(highlightBrush, 2).ToImmutable(); |
||||
|
var adorner = new ControlHighlightAdorner(pen) |
||||
|
{ |
||||
|
[AdornerLayer.AdornedElementProperty] = owner |
||||
|
}; |
||||
|
layer.Children.Add(adorner); |
||||
|
|
||||
|
return Disposable.Create((layer, adorner), state => |
||||
|
{ |
||||
|
state.layer.Children.Remove(state.adorner); |
||||
|
}); |
||||
|
} |
||||
|
return default; |
||||
|
} |
||||
|
|
||||
|
public override void Render(DrawingContext context) |
||||
|
{ |
||||
|
base.Render(context); |
||||
|
context.DrawRectangle(_pen, Bounds.Deflate(2)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using System.Globalization; |
||||
|
using Avalonia.Data; |
||||
|
using Avalonia.Data.Converters; |
||||
|
using Avalonia.Media; |
||||
|
|
||||
|
namespace Avalonia.Diagnostics.Converters; |
||||
|
|
||||
|
internal class BrushSelectorConveter : AvaloniaObject, IValueConverter |
||||
|
{ |
||||
|
public static readonly DirectProperty<BrushSelectorConveter, IBrush?> BrushProperty = |
||||
|
AvaloniaProperty.RegisterDirect<BrushSelectorConveter, IBrush?>(nameof(Brush) |
||||
|
, o => o.Brush |
||||
|
, (o, v) => o.Brush = v); |
||||
|
|
||||
|
public IBrush? Brush { get; set; } |
||||
|
|
||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) |
||||
|
{ |
||||
|
if (ReferenceEquals(value, parameter)) |
||||
|
{ |
||||
|
return Brush; |
||||
|
} |
||||
|
else if (value is ISolidColorBrush a |
||||
|
&& parameter is ISolidColorBrush b |
||||
|
&& a.Color == b.Color |
||||
|
&& a.Transform == b.Transform |
||||
|
&& b.Opacity == a.Opacity |
||||
|
) |
||||
|
{ |
||||
|
return Brush; |
||||
|
} |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) |
||||
|
{ |
||||
|
return BindingOperations.DoNothing; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue