Browse Source

Merge pull request #8075 from pr8x/adorner-layer-canvas

Fixing Canvas positioning for AdornerLayer
pull/8127/head
Max Katz 4 years ago
committed by GitHub
parent
commit
11737d94dd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      src/Avalonia.Controls/Canvas.cs
  2. 2
      src/Avalonia.Controls/Primitives/AdornerLayer.cs

75
src/Avalonia.Controls/Canvas.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Reactive.Concurrency;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Layout; using Avalonia.Layout;
@ -159,47 +160,57 @@ namespace Avalonia.Controls
} }
/// <summary> /// <summary>
/// Arranges the control's children. /// Arranges a single child.
/// </summary> /// </summary>
/// <param name="finalSize">The size allocated to the control.</param> /// <param name="child">The child to arrange.</param>
/// <returns>The space taken.</returns> /// <param name="finalSize">The size allocated to the canvas.</param>
protected override Size ArrangeOverride(Size finalSize) protected virtual void ArrangeChild(Control child, Size finalSize)
{ {
foreach (Control child in Children) double x = 0.0;
{ double y = 0.0;
double x = 0.0; double elementLeft = GetLeft(child);
double y = 0.0;
double elementLeft = GetLeft(child);
if (!double.IsNaN(elementLeft)) if (!double.IsNaN(elementLeft))
{ {
x = elementLeft; x = elementLeft;
} }
else else
{
// Arrange with right.
double elementRight = GetRight(child);
if (!double.IsNaN(elementRight))
{ {
// Arrange with right. x = finalSize.Width - child.DesiredSize.Width - elementRight;
double elementRight = GetRight(child);
if (!double.IsNaN(elementRight))
{
x = finalSize.Width - child.DesiredSize.Width - elementRight;
}
} }
}
double elementTop = GetTop(child); double elementTop = GetTop(child);
if (!double.IsNaN(elementTop) ) if (!double.IsNaN(elementTop))
{ {
y = elementTop; y = elementTop;
} }
else else
{
double elementBottom = GetBottom(child);
if (!double.IsNaN(elementBottom))
{ {
double elementBottom = GetBottom(child); y = finalSize.Height - child.DesiredSize.Height - elementBottom;
if (!double.IsNaN(elementBottom))
{
y = finalSize.Height - child.DesiredSize.Height - elementBottom;
}
} }
}
child.Arrange(new Rect(new Point(x, y), child.DesiredSize)); child.Arrange(new Rect(new Point(x, y), child.DesiredSize));
}
/// <summary>
/// Arranges the control's children.
/// </summary>
/// <param name="finalSize">The size allocated to the control.</param>
/// <returns>The space taken.</returns>
protected override Size ArrangeOverride(Size finalSize)
{
foreach (Control child in Children)
{
ArrangeChild(child, finalSize);
} }
return finalSize; return finalSize;

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

@ -105,7 +105,7 @@ namespace Avalonia.Controls.Primitives
} }
else else
{ {
child.Arrange(new Rect(finalSize)); ArrangeChild((Control) child, finalSize);
} }
} }
} }

Loading…
Cancel
Save