Browse Source
Fix MeasureCore when there's a size constraint and there's a negative margin. (#18462)
pull/18991/head
Johan Appelgren
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
32 additions and
3 deletions
-
src/Avalonia.Base/Layout/Layoutable.cs
-
tests/Avalonia.Base.UnitTests/Layout/LayoutableTests.cs
|
|
|
@ -596,15 +596,15 @@ namespace Avalonia.Layout |
|
|
|
(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; |
|
|
|
|
|
|
|
|
|
|
|
@ -435,6 +435,35 @@ namespace Avalonia.Base.UnitTests.Layout |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
[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; } |
|
|
|
|