Browse Source

Merge pull request #1350 from AvaloniaUI/fixes/337-focus-adorner-clipping

Clip Focus Adorners
pull/1276/merge
Jeremy Koritzinsky 8 years ago
committed by GitHub
parent
commit
be1fab69de
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/Avalonia.Controls/Primitives/AdornerLayer.cs
  2. 6
      src/Avalonia.Visuals/VisualTree/TransformedBounds.cs

16
src/Avalonia.Controls/Primitives/AdornerLayer.cs

@ -53,12 +53,13 @@ namespace Avalonia.Controls.Primitives
foreach (var child in Children)
{
var info = (AdornedElementInfo)child.GetValue(s_adornedElementInfoProperty);
var info = child.GetValue(s_adornedElementInfoProperty);
if (info != null && info.Bounds.HasValue)
{
child.RenderTransform = new MatrixTransform(info.Bounds.Value.Transform);
child.RenderTransformOrigin = new RelativePoint(new Point(0,0), RelativeUnit.Absolute);
UpdateClip(child, info.Bounds.Value);
child.Arrange(info.Bounds.Value.Bounds);
}
else
@ -78,6 +79,19 @@ namespace Avalonia.Controls.Primitives
layer?.UpdateAdornedElement(adorner, adorned);
}
private void UpdateClip(IControl control, TransformedBounds bounds)
{
var clip = control.Clip as RectangleGeometry;
if (clip == null)
{
clip = new RectangleGeometry { Transform = new MatrixTransform() };
control.Clip = clip;
}
clip.Rect = bounds.Clip.TransformToAABB(-bounds.Transform);
}
private void ChildrenCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)

6
src/Avalonia.Visuals/VisualTree/TransformedBounds.cs

@ -24,17 +24,17 @@ namespace Avalonia.VisualTree
}
/// <summary>
/// Gets the control's bounds.
/// Gets the control's bounds in its local coordinate space.
/// </summary>
public Rect Bounds { get; }
/// <summary>
/// Gets the control's clip rectangle.
/// Gets the control's clip rectangle in global coordinate space.
/// </summary>
public Rect Clip { get; }
/// <summary>
/// Gets the control's transform.
/// Gets the transform from local to global coordinate space.
/// </summary>
public Matrix Transform { get; }

Loading…
Cancel
Save