Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Avalonia.Base/Layout/Layoutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,15 @@ protected virtual Size MeasureCore(Size availableSize)
(width, height) = LayoutHelper.RoundLayoutSizeUp(new Size(width, height), scale);
}

width += margin.Left + margin.Right;
height += margin.Top + margin.Bottom;

if (width > availableSize.Width)
width = availableSize.Width;

if (height > availableSize.Height)
height = availableSize.Height;

width += margin.Left + margin.Right;
height += margin.Top + margin.Bottom;

if (width < 0)
width = 0;

Expand Down
29 changes: 29 additions & 0 deletions tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,35 @@ void SetShouldThrow(IEnumerable<StyledProperty<double>> properies, double value)
});
}

[Fact]
public void Constraint_And_Negative_Margin()
{
using var app = UnitTestApplication.Start(TestServices.MockPlatformRenderInterface);

var textBlock = new TextBlock
{
Margin = new Thickness(-10),
Text = "Lorem ipsum dolor sit amet",
};

var border = new Border
{
MaxWidth = 100,
Child = textBlock,
};

border.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
border.Arrange(new Rect(default, border.DesiredSize));

Assert.Multiple(() =>
{
Assert.Equal(new Size(100, 0), border.DesiredSize);
Assert.Equal(new Rect(0, 0, 100, 0), border.Bounds);
Assert.Equal(new Size(100, 0), textBlock.DesiredSize);
Assert.Equal(new Rect(-10, -10, 120, 20), textBlock.Bounds);
});
}

private class TestLayoutable : Layoutable
{
public Size ArrangeSize { get; private set; }
Expand Down
Loading