Browse Source

Merge pull request #1449 from AvaloniaUI/fixes/1447-alignment

Fix alignment of fixed-size controls in ContentPresenter
pull/1480/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
e8be665b17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/Avalonia.Controls/Presenters/ContentPresenter.cs
  2. 25
      tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs

6
src/Avalonia.Controls/Presenters/ContentPresenter.cs

@ -221,7 +221,7 @@ namespace Avalonia.Controls.Presenters
{
var content = Content;
var oldChild = Child;
var newChild = CreateChild();
var newChild = CreateChild();
// Remove the old child if we're not recycling it.
if (oldChild != null && newChild != oldChild)
@ -397,8 +397,6 @@ namespace Avalonia.Controls.Presenters
size = size.WithHeight(Math.Min(size.Height, DesiredSize.Height - padding.Top - padding.Bottom));
}
size = LayoutHelper.ApplyLayoutConstraints(Child, size);
if (useLayoutRounding)
{
size = new Size(
@ -412,7 +410,6 @@ namespace Avalonia.Controls.Presenters
switch (horizontalContentAlignment)
{
case HorizontalAlignment.Center:
case HorizontalAlignment.Stretch:
originX += (availableSizeMinusMargins.Width - size.Width) / 2;
break;
case HorizontalAlignment.Right:
@ -423,7 +420,6 @@ namespace Avalonia.Controls.Presenters
switch (verticalContentAlignment)
{
case VerticalAlignment.Center:
case VerticalAlignment.Stretch:
originY += (availableSizeMinusMargins.Height - size.Height) / 2;
break;
case VerticalAlignment.Bottom:

25
tests/Avalonia.Controls.UnitTests/Presenters/ContentPresenterTests_Layout.cs

@ -80,6 +80,31 @@ namespace Avalonia.Controls.UnitTests.Presenters
Assert.Equal(new Rect(expectedX, expectedY, expectedWidth, expectedHeight), content.Bounds);
}
[Fact]
public void Should_Correctly_Align_Child_With_Fixed_Size()
{
Border content;
var target = new ContentPresenter
{
HorizontalContentAlignment = HorizontalAlignment.Stretch,
VerticalContentAlignment = VerticalAlignment.Stretch,
Content = content = new Border
{
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Bottom,
Width = 16,
Height = 16,
},
};
target.UpdateChild();
target.Measure(new Size(100, 100));
target.Arrange(new Rect(0, 0, 100, 100));
// Check correct result for Issue #1447.
Assert.Equal(new Rect(0, 84, 16, 16), content.Bounds);
}
[Fact]
public void Content_Can_Be_Stretched()
{

Loading…
Cancel
Save