|
|
@@ -14,290 +14,231 @@ namespace Avalonia.Layout.UnitTests
|
|
|
[Fact]
|
|
|
public void Measures_And_Arranges_InvalidateMeasured_Control()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ var control = new LayoutTestControl();
|
|
|
+ var root = new LayoutTestRoot { Child = control };
|
|
|
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var control = new LayoutTestControl();
|
|
|
- var root = new LayoutTestRoot { Child = control };
|
|
|
-
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- control.Measured = control.Arranged = false;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ control.Measured = control.Arranged = false;
|
|
|
|
|
|
- control.InvalidateMeasure();
|
|
|
- target.ExecuteLayoutPass();
|
|
|
+ control.InvalidateMeasure();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- Assert.True(control.Measured);
|
|
|
- Assert.True(control.Arranged);
|
|
|
- }
|
|
|
+ Assert.True(control.Measured);
|
|
|
+ Assert.True(control.Arranged);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Arranges_InvalidateArranged_Control()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ var control = new LayoutTestControl();
|
|
|
+ var root = new LayoutTestRoot { Child = control };
|
|
|
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var control = new LayoutTestControl();
|
|
|
- var root = new LayoutTestRoot { Child = control };
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ control.Measured = control.Arranged = false;
|
|
|
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- control.Measured = control.Arranged = false;
|
|
|
+ control.InvalidateArrange();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- control.InvalidateArrange();
|
|
|
- target.ExecuteLayoutPass();
|
|
|
-
|
|
|
- Assert.False(control.Measured);
|
|
|
- Assert.True(control.Arranged);
|
|
|
- }
|
|
|
+ Assert.False(control.Measured);
|
|
|
+ Assert.True(control.Arranged);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Measures_Parent_Of_Newly_Added_Control()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
-
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var control = new LayoutTestControl();
|
|
|
- var root = new LayoutTestRoot();
|
|
|
+ var control = new LayoutTestControl();
|
|
|
+ var root = new LayoutTestRoot();
|
|
|
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- root.Child = control;
|
|
|
- root.Measured = root.Arranged = false;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ root.Child = control;
|
|
|
+ root.Measured = root.Arranged = false;
|
|
|
|
|
|
- target.ExecuteLayoutPass();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- Assert.True(root.Measured);
|
|
|
- Assert.True(root.Arranged);
|
|
|
- Assert.True(control.Measured);
|
|
|
- Assert.True(control.Arranged);
|
|
|
- }
|
|
|
+ Assert.True(root.Measured);
|
|
|
+ Assert.True(root.Arranged);
|
|
|
+ Assert.True(control.Measured);
|
|
|
+ Assert.True(control.Arranged);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Measures_In_Correct_Order()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
-
|
|
|
- using (Start(target))
|
|
|
+ LayoutTestControl control1;
|
|
|
+ LayoutTestControl control2;
|
|
|
+ var root = new LayoutTestRoot
|
|
|
{
|
|
|
- LayoutTestControl control1;
|
|
|
- LayoutTestControl control2;
|
|
|
- var root = new LayoutTestRoot
|
|
|
+ Child = control1 = new LayoutTestControl
|
|
|
{
|
|
|
- Child = control1 = new LayoutTestControl
|
|
|
- {
|
|
|
- Child = control2 = new LayoutTestControl(),
|
|
|
- }
|
|
|
- };
|
|
|
+ Child = control2 = new LayoutTestControl(),
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
|
|
|
- var order = new List<ILayoutable>();
|
|
|
- Size MeasureOverride(ILayoutable control, Size size)
|
|
|
- {
|
|
|
- order.Add(control);
|
|
|
- return new Size(10, 10);
|
|
|
- }
|
|
|
+ var order = new List<ILayoutable>();
|
|
|
+ Size MeasureOverride(ILayoutable control, Size size)
|
|
|
+ {
|
|
|
+ order.Add(control);
|
|
|
+ return new Size(10, 10);
|
|
|
+ }
|
|
|
|
|
|
- root.DoMeasureOverride = MeasureOverride;
|
|
|
- control1.DoMeasureOverride = MeasureOverride;
|
|
|
- control2.DoMeasureOverride = MeasureOverride;
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
+ root.DoMeasureOverride = MeasureOverride;
|
|
|
+ control1.DoMeasureOverride = MeasureOverride;
|
|
|
+ control2.DoMeasureOverride = MeasureOverride;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
|
|
|
- control2.InvalidateMeasure();
|
|
|
- control1.InvalidateMeasure();
|
|
|
- root.InvalidateMeasure();
|
|
|
+ control2.InvalidateMeasure();
|
|
|
+ control1.InvalidateMeasure();
|
|
|
+ root.InvalidateMeasure();
|
|
|
|
|
|
- order.Clear();
|
|
|
- target.ExecuteLayoutPass();
|
|
|
+ order.Clear();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- Assert.Equal(new ILayoutable[] { root, control1, control2 }, order);
|
|
|
- }
|
|
|
+ Assert.Equal(new ILayoutable[] { root, control1, control2 }, order);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Measures_Root_And_Grandparent_In_Correct_Order()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
-
|
|
|
- using (Start(target))
|
|
|
+ LayoutTestControl control1;
|
|
|
+ LayoutTestControl control2;
|
|
|
+ var root = new LayoutTestRoot
|
|
|
{
|
|
|
- LayoutTestControl control1;
|
|
|
- LayoutTestControl control2;
|
|
|
- var root = new LayoutTestRoot
|
|
|
+ Child = control1 = new LayoutTestControl
|
|
|
{
|
|
|
- Child = control1 = new LayoutTestControl
|
|
|
- {
|
|
|
- Child = control2 = new LayoutTestControl(),
|
|
|
- }
|
|
|
- };
|
|
|
+ Child = control2 = new LayoutTestControl(),
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
|
|
|
- var order = new List<ILayoutable>();
|
|
|
- Size MeasureOverride(ILayoutable control, Size size)
|
|
|
- {
|
|
|
- order.Add(control);
|
|
|
- return new Size(10, 10);
|
|
|
- }
|
|
|
+ var order = new List<ILayoutable>();
|
|
|
+ Size MeasureOverride(ILayoutable control, Size size)
|
|
|
+ {
|
|
|
+ order.Add(control);
|
|
|
+ return new Size(10, 10);
|
|
|
+ }
|
|
|
|
|
|
- root.DoMeasureOverride = MeasureOverride;
|
|
|
- control1.DoMeasureOverride = MeasureOverride;
|
|
|
- control2.DoMeasureOverride = MeasureOverride;
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
+ root.DoMeasureOverride = MeasureOverride;
|
|
|
+ control1.DoMeasureOverride = MeasureOverride;
|
|
|
+ control2.DoMeasureOverride = MeasureOverride;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
|
|
|
- control2.InvalidateMeasure();
|
|
|
- root.InvalidateMeasure();
|
|
|
+ control2.InvalidateMeasure();
|
|
|
+ root.InvalidateMeasure();
|
|
|
|
|
|
- order.Clear();
|
|
|
- target.ExecuteLayoutPass();
|
|
|
+ order.Clear();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- Assert.Equal(new ILayoutable[] { root, control2 }, order);
|
|
|
- }
|
|
|
+ Assert.Equal(new ILayoutable[] { root, control2 }, order);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Doesnt_Measure_Non_Invalidated_Root()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ var control = new LayoutTestControl();
|
|
|
+ var root = new LayoutTestRoot { Child = control };
|
|
|
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var control = new LayoutTestControl();
|
|
|
- var root = new LayoutTestRoot { Child = control };
|
|
|
-
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- root.Measured = root.Arranged = false;
|
|
|
- control.Measured = control.Arranged = false;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ root.Measured = root.Arranged = false;
|
|
|
+ control.Measured = control.Arranged = false;
|
|
|
|
|
|
- control.InvalidateMeasure();
|
|
|
- target.ExecuteLayoutPass();
|
|
|
+ control.InvalidateMeasure();
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- Assert.False(root.Measured);
|
|
|
- Assert.False(root.Arranged);
|
|
|
- Assert.True(control.Measured);
|
|
|
- Assert.True(control.Arranged);
|
|
|
- }
|
|
|
+ Assert.False(root.Measured);
|
|
|
+ Assert.False(root.Arranged);
|
|
|
+ Assert.True(control.Measured);
|
|
|
+ Assert.True(control.Arranged);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Doesnt_Measure_Removed_Control()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ var control = new LayoutTestControl();
|
|
|
+ var root = new LayoutTestRoot { Child = control };
|
|
|
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var control = new LayoutTestControl();
|
|
|
- var root = new LayoutTestRoot { Child = control };
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ control.Measured = control.Arranged = false;
|
|
|
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- control.Measured = control.Arranged = false;
|
|
|
+ control.InvalidateMeasure();
|
|
|
+ root.Child = null;
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
|
|
|
- control.InvalidateMeasure();
|
|
|
- root.Child = null;
|
|
|
- target.ExecuteLayoutPass();
|
|
|
-
|
|
|
- Assert.False(control.Measured);
|
|
|
- Assert.False(control.Arranged);
|
|
|
- }
|
|
|
+ Assert.False(control.Measured);
|
|
|
+ Assert.False(control.Arranged);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Measures_Root_With_Infinity()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ var root = new LayoutTestRoot();
|
|
|
+ var availableSize = default(Size);
|
|
|
|
|
|
- using (Start(target))
|
|
|
- {
|
|
|
- var root = new LayoutTestRoot();
|
|
|
- var availableSize = default(Size);
|
|
|
+ // Should not measure with this size.
|
|
|
+ root.MaxClientSize = new Size(123, 456);
|
|
|
|
|
|
- // Should not measure with this size.
|
|
|
- root.MaxClientSize = new Size(123, 456);
|
|
|
-
|
|
|
- root.DoMeasureOverride = (_, s) =>
|
|
|
- {
|
|
|
- availableSize = s;
|
|
|
- return new Size(100, 100);
|
|
|
- };
|
|
|
+ root.DoMeasureOverride = (_, s) =>
|
|
|
+ {
|
|
|
+ availableSize = s;
|
|
|
+ return new Size(100, 100);
|
|
|
+ };
|
|
|
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
|
|
|
- Assert.Equal(Size.Infinity, availableSize);
|
|
|
- }
|
|
|
+ Assert.Equal(Size.Infinity, availableSize);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Arranges_Root_With_DesiredSize()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
-
|
|
|
- using (Start(target))
|
|
|
+ var root = new LayoutTestRoot
|
|
|
{
|
|
|
- var root = new LayoutTestRoot
|
|
|
- {
|
|
|
- Width = 100,
|
|
|
- Height = 100,
|
|
|
- };
|
|
|
+ Width = 100,
|
|
|
+ Height = 100,
|
|
|
+ };
|
|
|
|
|
|
- var arrangeSize = default(Size);
|
|
|
+ var arrangeSize = default(Size);
|
|
|
|
|
|
- root.DoArrangeOverride = (_, s) =>
|
|
|
- {
|
|
|
- arrangeSize = s;
|
|
|
- return s;
|
|
|
- };
|
|
|
-
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- Assert.Equal(new Size(100, 100), arrangeSize);
|
|
|
-
|
|
|
- root.Width = 120;
|
|
|
+ root.DoArrangeOverride = (_, s) =>
|
|
|
+ {
|
|
|
+ arrangeSize = s;
|
|
|
+ return s;
|
|
|
+ };
|
|
|
+
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ Assert.Equal(new Size(100, 100), arrangeSize);
|
|
|
|
|
|
- target.ExecuteLayoutPass();
|
|
|
- Assert.Equal(new Size(120, 100), arrangeSize);
|
|
|
- }
|
|
|
+ root.Width = 120;
|
|
|
+
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
+ Assert.Equal(new Size(120, 100), arrangeSize);
|
|
|
}
|
|
|
|
|
|
[Fact]
|
|
|
public void Invalidating_Child_Remeasures_Parent()
|
|
|
{
|
|
|
- var target = new LayoutManager();
|
|
|
+ Border border;
|
|
|
+ StackPanel panel;
|
|
|
|
|
|
- using (Start(target))
|
|
|
+ var root = new LayoutTestRoot
|
|
|
{
|
|
|
- AvaloniaLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(target);
|
|
|
-
|
|
|
- Border border;
|
|
|
- StackPanel panel;
|
|
|
-
|
|
|
- var root = new LayoutTestRoot
|
|
|
+ Child = panel = new StackPanel
|
|
|
{
|
|
|
- Child = panel = new StackPanel
|
|
|
+ Children =
|
|
|
{
|
|
|
- Children =
|
|
|
- {
|
|
|
- (border = new Border())
|
|
|
- }
|
|
|
+ (border = new Border())
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- target.ExecuteInitialLayoutPass(root);
|
|
|
- Assert.Equal(new Size(0, 0), root.DesiredSize);
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
- border.Width = 100;
|
|
|
- border.Height = 100;
|
|
|
+ root.LayoutManager.ExecuteInitialLayoutPass(root);
|
|
|
+ Assert.Equal(new Size(0, 0), root.DesiredSize);
|
|
|
|
|
|
- target.ExecuteLayoutPass();
|
|
|
- Assert.Equal(new Size(100, 100), panel.DesiredSize);
|
|
|
- }
|
|
|
- }
|
|
|
+ border.Width = 100;
|
|
|
+ border.Height = 100;
|
|
|
|
|
|
- private IDisposable Start(LayoutManager layoutManager)
|
|
|
- {
|
|
|
- var result = AvaloniaLocator.EnterScope();
|
|
|
- AvaloniaLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(layoutManager);
|
|
|
- return result;
|
|
|
+ root.LayoutManager.ExecuteLayoutPass();
|
|
|
+ Assert.Equal(new Size(100, 100), panel.DesiredSize);
|
|
|
}
|
|
|
}
|
|
|
}
|