|
|
@@ -2,12 +2,14 @@ using System;
|
|
|
using System.Linq;
|
|
|
using Avalonia.Controls.Presenters;
|
|
|
using Avalonia.Controls.Primitives;
|
|
|
+using Avalonia.Controls.Primitives.PopupPositioning;
|
|
|
using Avalonia.Controls.Templates;
|
|
|
using Avalonia.LogicalTree;
|
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.Styling;
|
|
|
using Avalonia.UnitTests;
|
|
|
using Avalonia.VisualTree;
|
|
|
+using Moq;
|
|
|
using Xunit;
|
|
|
|
|
|
namespace Avalonia.Controls.UnitTests.Primitives
|
|
|
@@ -207,6 +209,24 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public void Child_Should_Be_Measured_With_MaxWidth_MaxHeight_When_Set()
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ var child = new ChildControl();
|
|
|
+ var window = new Window();
|
|
|
+ var target = CreateTarget(window);
|
|
|
+
|
|
|
+ target.MaxWidth = 500;
|
|
|
+ target.MaxHeight = 600;
|
|
|
+ target.Content = child;
|
|
|
+ target.Show();
|
|
|
+
|
|
|
+ Assert.Equal(new Size(500, 600), child.MeasureSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void Should_Not_Have_Offset_On_Bounds_When_Content_Larger_Than_Max_Window_Size()
|
|
|
{
|
|
|
@@ -216,12 +236,10 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
|
|
var window = new Window();
|
|
|
var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
|
|
|
|
|
- popupImpl.Setup(x => x.ClientSize).Returns(new Size(400, 480));
|
|
|
-
|
|
|
var child = new Canvas
|
|
|
{
|
|
|
Width = 400,
|
|
|
- Height = 800,
|
|
|
+ Height = 1344,
|
|
|
};
|
|
|
|
|
|
var target = CreateTarget(window, popupImpl.Object);
|
|
|
@@ -229,7 +247,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
|
|
|
|
|
target.Show();
|
|
|
|
|
|
- Assert.Equal(new Size(400, 480), target.Bounds.Size);
|
|
|
+ Assert.Equal(new Size(400, 1024), target.Bounds.Size);
|
|
|
|
|
|
// Issue #3784 causes this to be (0, 160) which makes no sense as Window has no
|
|
|
// parent control to be offset against.
|
|
|
@@ -237,6 +255,61 @@ namespace Avalonia.Controls.UnitTests.Primitives
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Fact]
|
|
|
+ public void MinWidth_MinHeight_Should_Be_Respected()
|
|
|
+ {
|
|
|
+ // Issue #3796
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ var window = new Window();
|
|
|
+ var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
|
|
+
|
|
|
+ var target = CreateTarget(window, popupImpl.Object);
|
|
|
+ target.MinWidth = 400;
|
|
|
+ target.MinHeight = 800;
|
|
|
+ target.Content = new Border
|
|
|
+ {
|
|
|
+ Width = 100,
|
|
|
+ Height = 100,
|
|
|
+ };
|
|
|
+
|
|
|
+ target.Show();
|
|
|
+
|
|
|
+ Assert.Equal(new Rect(0, 0, 400, 800), target.Bounds);
|
|
|
+ Assert.Equal(new Size(400, 800), target.ClientSize);
|
|
|
+ Assert.Equal(new Size(400, 800), target.PlatformImpl.ClientSize);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void Setting_Width_Should_Resize_WindowImpl()
|
|
|
+ {
|
|
|
+ // Issue #3796
|
|
|
+ using (UnitTestApplication.Start(TestServices.StyledWindow))
|
|
|
+ {
|
|
|
+ var window = new Window();
|
|
|
+ var popupImpl = MockWindowingPlatform.CreatePopupMock(window.PlatformImpl);
|
|
|
+ var positioner = new Mock<IPopupPositioner>();
|
|
|
+ popupImpl.Setup(x => x.PopupPositioner).Returns(positioner.Object);
|
|
|
+
|
|
|
+ var target = CreateTarget(window, popupImpl.Object);
|
|
|
+ target.Width = 400;
|
|
|
+ target.Height = 800;
|
|
|
+
|
|
|
+ target.Show();
|
|
|
+
|
|
|
+ Assert.Equal(400, target.Width);
|
|
|
+ Assert.Equal(800, target.Height);
|
|
|
+
|
|
|
+ target.Width = 410;
|
|
|
+ target.LayoutManager.ExecuteLayoutPass();
|
|
|
+
|
|
|
+ positioner.Verify(x =>
|
|
|
+ x.Update(It.Is<PopupPositionerParameters>(x => x.Size.Width == 410)));
|
|
|
+ Assert.Equal(410, target.Width);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private PopupRoot CreateTarget(TopLevel popupParent, IPopupImpl impl = null)
|
|
|
{
|
|
|
impl ??= popupParent.PlatformImpl.CreatePopup();
|