Browse Source
Fix ScrollContentPresenter's child margin with layout rounding
pull/11916/head
Julien Lebosquain
3 years ago
No known key found for this signature in database
GPG Key ID: 1833CAD10ACC46FD
2 changed files with
41 additions and
2 deletions
-
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs
-
tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs
|
|
|
@ -7,7 +7,7 @@ using Avalonia.Input.GestureRecognizers; |
|
|
|
using Avalonia.Utilities; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Layout; |
|
|
|
|
|
|
|
namespace Avalonia.Controls.Presenters |
|
|
|
{ |
|
|
|
@ -473,7 +473,15 @@ namespace Avalonia.Controls.Presenters |
|
|
|
} |
|
|
|
|
|
|
|
Viewport = finalSize; |
|
|
|
Extent = Child!.Bounds.Size.Inflate(Child.Margin); |
|
|
|
|
|
|
|
var childMargin = Child!.Margin; |
|
|
|
if (Child.UseLayoutRounding) |
|
|
|
{ |
|
|
|
var scale = LayoutHelper.GetLayoutScale(Child); |
|
|
|
childMargin = LayoutHelper.RoundLayoutThickness(childMargin, scale, scale); |
|
|
|
} |
|
|
|
|
|
|
|
Extent = Child!.Bounds.Size.Inflate(childMargin); |
|
|
|
_isAnchorElementDirty = true; |
|
|
|
|
|
|
|
return finalSize; |
|
|
|
|
|
|
|
@ -4,6 +4,7 @@ using System.Reactive.Linq; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Avalonia.Controls.UnitTests.Presenters |
|
|
|
@ -244,6 +245,36 @@ namespace Avalonia.Controls.UnitTests.Presenters |
|
|
|
Assert.Equal(new Size(110, 110), target.Extent); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Extent_Should_Include_Content_Margin_Scaled_With_Layout_Rounding() |
|
|
|
{ |
|
|
|
var root = new TestRoot |
|
|
|
{ |
|
|
|
LayoutScaling = 1.25, |
|
|
|
UseLayoutRounding = true |
|
|
|
}; |
|
|
|
|
|
|
|
var target = new ScrollContentPresenter |
|
|
|
{ |
|
|
|
HorizontalAlignment = HorizontalAlignment.Center, |
|
|
|
VerticalAlignment = VerticalAlignment.Center, |
|
|
|
Content = new Border |
|
|
|
{ |
|
|
|
Width = 200, |
|
|
|
Height = 200, |
|
|
|
Margin = new Thickness(2) |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
root.Child = target; |
|
|
|
target.UpdateChild(); |
|
|
|
target.Measure(new Size(1000, 1000)); |
|
|
|
target.Arrange(new Rect(0, 0, 1000, 1000)); |
|
|
|
|
|
|
|
Assert.Equal(new Size(203.2, 203.2), target.Viewport); |
|
|
|
Assert.Equal(new Size(203.2, 203.2), target.Extent); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Extent_Width_Should_Be_Arrange_Width_When_CanScrollHorizontally_False() |
|
|
|
{ |
|
|
|
|