Browse Source

Merge branch 'master' into CompactDensityStyle

pull/4157/head
danwalmsley 6 years ago
committed by GitHub
parent
commit
0cd35e8f9e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs
  2. 2
      src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevel.cs
  3. 3
      src/Avalonia.Controls/TopLevel.cs
  4. 4
      src/Avalonia.Controls/Window.cs
  5. 2
      src/Avalonia.Controls/WindowBase.cs
  6. 12
      src/Avalonia.Layout/ILayoutManager.cs
  7. 61
      src/Avalonia.Layout/LayoutManager.cs
  8. 9
      src/Avalonia.Layout/LayoutQueue.cs
  9. 2
      tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs
  10. 2
      tests/Avalonia.Benchmarks/Layout/Measure.cs
  11. 2
      tests/Avalonia.Benchmarks/Traversal/VisualTreeTraversal.cs
  12. 2
      tests/Avalonia.Controls.UnitTests/GridTests.cs
  13. 2
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs
  14. 9
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization.cs
  15. 27
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs
  16. 6
      tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs
  17. 25
      tests/Avalonia.Controls.UnitTests/TopLevelTests.cs
  18. 48
      tests/Avalonia.Layout.UnitTests/LayoutManagerTests.cs
  19. 4
      tests/Avalonia.Layout.UnitTests/LayoutableTests.cs
  20. 20
      tests/Avalonia.LeakTests/ControlTests.cs
  21. 4
      tests/Avalonia.UnitTests/TestRoot.cs
  22. 3
      tests/Avalonia.UnitTests/TestTemplatedRoot.cs
  23. 8
      tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests.cs
  24. 6
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs
  25. 10
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests_Layers.cs

2
src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs

@ -25,7 +25,7 @@ namespace Avalonia.Controls.Embedding
{
EnsureInitialized();
ApplyTemplate();
LayoutManager.ExecuteInitialLayoutPass(this);
LayoutManager.ExecuteInitialLayoutPass();
}
private void EnsureInitialized()

2
src/Avalonia.Controls/Embedding/Offscreen/OffscreenTopLevel.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls.Embedding.Offscreen
{
EnsureInitialized();
ApplyTemplate();
LayoutManager.ExecuteInitialLayoutPass(this);
LayoutManager.ExecuteInitialLayoutPass();
}
private void EnsureInitialized()

3
src/Avalonia.Controls/TopLevel.cs

@ -318,7 +318,7 @@ namespace Avalonia.Controls
/// <summary>
/// Creates the layout manager for this <see cref="TopLevel" />.
/// </summary>
protected virtual ILayoutManager CreateLayoutManager() => new LayoutManager();
protected virtual ILayoutManager CreateLayoutManager() => new LayoutManager(this);
/// <summary>
/// Handles a paint notification from <see cref="ITopLevelImpl.Resized"/>.
@ -351,6 +351,7 @@ namespace Avalonia.Controls
OnClosed(EventArgs.Empty);
Renderer?.Dispose();
Renderer = null;
LayoutManager?.Dispose();
}
/// <summary>

4
src/Avalonia.Controls/Window.cs

@ -519,7 +519,7 @@ namespace Avalonia.Controls
}
}
LayoutManager.ExecuteInitialLayoutPass(this);
LayoutManager.ExecuteInitialLayoutPass();
using (BeginAutoSizing())
{
@ -592,7 +592,7 @@ namespace Avalonia.Controls
}
}
LayoutManager.ExecuteInitialLayoutPass(this);
LayoutManager.ExecuteInitialLayoutPass();
var result = new TaskCompletionSource<TResult>();

2
src/Avalonia.Controls/WindowBase.cs

@ -162,7 +162,7 @@ namespace Avalonia.Controls
if (!_hasExecutedInitialLayoutPass)
{
LayoutManager.ExecuteInitialLayoutPass(this);
LayoutManager.ExecuteInitialLayoutPass();
_hasExecutedInitialLayoutPass = true;
}
PlatformImpl?.Show();

12
src/Avalonia.Layout/ILayoutManager.cs

@ -7,7 +7,7 @@ namespace Avalonia.Layout
/// <summary>
/// Manages measuring and arranging of controls.
/// </summary>
public interface ILayoutManager
public interface ILayoutManager : IDisposable
{
/// <summary>
/// Raised when the layout manager completes a layout pass.
@ -35,6 +35,15 @@ namespace Avalonia.Layout
/// </remarks>
void ExecuteLayoutPass();
/// <summary>
/// Executes the initial layout pass on a layout root.
/// </summary>
/// <remarks>
/// You should not usually need to call this method explictly, the layout root will call
/// it to carry out the initial layout of the control.
/// </remarks>
void ExecuteInitialLayoutPass();
/// <summary>
/// Executes the initial layout pass on a layout root.
/// </summary>
@ -43,6 +52,7 @@ namespace Avalonia.Layout
/// You should not usually need to call this method explictly, the layout root will call
/// it to carry out the initial layout of the control.
/// </remarks>
[Obsolete("Call ExecuteInitialLayoutPass without parameter")]
void ExecuteInitialLayoutPass(ILayoutRoot root);
}
}

61
src/Avalonia.Layout/LayoutManager.cs

@ -10,16 +10,19 @@ namespace Avalonia.Layout
/// <summary>
/// Manages measuring and arranging of controls.
/// </summary>
public class LayoutManager : ILayoutManager
public class LayoutManager : ILayoutManager, IDisposable
{
private readonly ILayoutRoot _owner;
private readonly LayoutQueue<ILayoutable> _toMeasure = new LayoutQueue<ILayoutable>(v => !v.IsMeasureValid);
private readonly LayoutQueue<ILayoutable> _toArrange = new LayoutQueue<ILayoutable>(v => !v.IsArrangeValid);
private readonly Action _executeLayoutPass;
private bool _disposed;
private bool _queued;
private bool _running;
public LayoutManager()
public LayoutManager(ILayoutRoot owner)
{
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
_executeLayoutPass = ExecuteLayoutPass;
}
@ -31,6 +34,11 @@ namespace Avalonia.Layout
control = control ?? throw new ArgumentNullException(nameof(control));
Dispatcher.UIThread.VerifyAccess();
if (_disposed)
{
return;
}
if (!control.IsAttachedToVisualTree)
{
#if DEBUG
@ -41,6 +49,11 @@ namespace Avalonia.Layout
#endif
}
if (control.VisualRoot != _owner)
{
throw new ArgumentException("Attempt to call InvalidateMeasure on wrong LayoutManager.");
}
_toMeasure.Enqueue(control);
_toArrange.Enqueue(control);
QueueLayoutPass();
@ -52,6 +65,11 @@ namespace Avalonia.Layout
control = control ?? throw new ArgumentNullException(nameof(control));
Dispatcher.UIThread.VerifyAccess();
if (_disposed)
{
return;
}
if (!control.IsAttachedToVisualTree)
{
#if DEBUG
@ -62,6 +80,11 @@ namespace Avalonia.Layout
#endif
}
if (control.VisualRoot != _owner)
{
throw new ArgumentException("Attempt to call InvalidateArrange on wrong LayoutManager.");
}
_toArrange.Enqueue(control);
QueueLayoutPass();
}
@ -73,6 +96,11 @@ namespace Avalonia.Layout
Dispatcher.UIThread.VerifyAccess();
if (_disposed)
{
return;
}
if (!_running)
{
_running = true;
@ -131,13 +159,18 @@ namespace Avalonia.Layout
}
/// <inheritdoc/>
public virtual void ExecuteInitialLayoutPass(ILayoutRoot root)
public virtual void ExecuteInitialLayoutPass()
{
if (_disposed)
{
return;
}
try
{
_running = true;
Measure(root);
Arrange(root);
Measure(_owner);
Arrange(_owner);
}
finally
{
@ -151,6 +184,24 @@ namespace Avalonia.Layout
ExecuteLayoutPass();
}
[Obsolete("Call ExecuteInitialLayoutPass without parameter")]
public void ExecuteInitialLayoutPass(ILayoutRoot root)
{
if (root != _owner)
{
throw new ArgumentException("ExecuteInitialLayoutPass called with incorrect root.");
}
ExecuteInitialLayoutPass();
}
public void Dispose()
{
_disposed = true;
_toMeasure.Dispose();
_toArrange.Dispose();
}
private void ExecuteMeasurePass()
{
while (_toMeasure.Count > 0)

9
src/Avalonia.Layout/LayoutQueue.cs

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Avalonia.Layout
{
internal class LayoutQueue<T> : IReadOnlyCollection<T>
internal class LayoutQueue<T> : IReadOnlyCollection<T>, IDisposable
{
private struct Info
{
@ -84,5 +84,12 @@ namespace Avalonia.Layout
_notFinalizedBuffer.Clear();
}
public void Dispose()
{
_inner.Clear();
_loopQueueInfo.Clear();
_notFinalizedBuffer.Clear();
}
}
}

2
tests/Avalonia.Benchmarks/Layout/ControlsBenchmark.cs

@ -24,7 +24,7 @@ namespace Avalonia.Benchmarks.Layout
Renderer = new NullRenderer()
};
_root.LayoutManager.ExecuteInitialLayoutPass(_root);
_root.LayoutManager.ExecuteInitialLayoutPass();
}
[Benchmark]

2
tests/Avalonia.Benchmarks/Layout/Measure.cs

@ -25,7 +25,7 @@ namespace Avalonia.Benchmarks.Layout
_controls.Add(panel);
_controls = ControlHierarchyCreator.CreateChildren(_controls, panel, 3, 5, 5);
_root.LayoutManager.ExecuteInitialLayoutPass(_root);
_root.LayoutManager.ExecuteInitialLayoutPass();
}
[Benchmark, MethodImpl(MethodImplOptions.NoInlining)]

2
tests/Avalonia.Benchmarks/Traversal/VisualTreeTraversal.cs

@ -26,7 +26,7 @@ namespace Avalonia.Benchmarks.Traversal
_shuffledControls = _controls.OrderBy(r => random.Next()).ToList();
_root.LayoutManager.ExecuteInitialLayoutPass(_root);
_root.LayoutManager.ExecuteInitialLayoutPass();
}
[Benchmark]

2
tests/Avalonia.Controls.UnitTests/GridTests.cs

@ -1194,7 +1194,7 @@ namespace Avalonia.Controls.UnitTests
Height = 50,
};
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
PrintColumnDefinitions(grids[0]);
Assert.Equal(5, grids[0].ColumnDefinitions[0].ActualWidth);

2
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -329,7 +329,7 @@ namespace Avalonia.Controls.UnitTests
return tb;
}, true);
lm.ExecuteInitialLayoutPass(wnd);
lm.ExecuteInitialLayoutPass();
target.Items = items;

9
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization.cs

@ -232,7 +232,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroll = (TestScroller)target.Parent;
scroll.Width = scroll.Height = 100;
scroll.LayoutManager.ExecuteInitialLayoutPass(scroll);
scroll.LayoutManager.ExecuteInitialLayoutPass();
// Ensure than an intermediate measure pass doesn't add more controls than it
// should. This can happen if target gets measured with Size.Infinity which
@ -324,6 +324,11 @@ namespace Avalonia.Controls.UnitTests.Presenters
private class TestScroller : ScrollContentPresenter, IRenderRoot, ILayoutRoot
{
public TestScroller()
{
LayoutManager = new LayoutManager(this);
}
public IRenderer Renderer { get; }
public Size ClientSize { get; }
public double RenderScaling => 1;
@ -332,7 +337,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
public double LayoutScaling => 1;
public ILayoutManager LayoutManager { get; } = new LayoutManager();
public ILayoutManager LayoutManager { get; }
public IRenderTarget CreateRenderTarget() => throw new NotImplementedException();
public void Invalidate(Rect rect) => throw new NotImplementedException();

27
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

@ -723,7 +723,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var last = (target.Items as IList)[10];
@ -740,7 +740,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var last = (target.Items as IList)[10];
@ -838,7 +838,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[5];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -855,7 +855,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[9];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -874,7 +874,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
scroller.Width = 100;
scroller.Height = 95;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[8];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -893,7 +893,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
scroller.Width = 100;
scroller.Height = 95;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
((ILogicalScrollable)target).Offset = new Vector(0, 11);
var from = target.Panel.Children[1];
@ -946,7 +946,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[5];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -963,7 +963,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var scroller = (TestScroller)target.Parent;
scroller.Width = scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[9];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -982,7 +982,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
scroller.Width = 95;
scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
var from = target.Panel.Children[8];
var result = ((ILogicalScrollable)target).GetControlInDirection(
@ -1001,7 +1001,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
scroller.Width = 95;
scroller.Height = 100;
scroller.LayoutManager.ExecuteInitialLayoutPass(scroller);
scroller.LayoutManager.ExecuteInitialLayoutPass();
((ILogicalScrollable)target).Offset = new Vector(11, 0);
var from = target.Panel.Children[1];
@ -1062,6 +1062,11 @@ namespace Avalonia.Controls.UnitTests.Presenters
private class TestScroller : ScrollContentPresenter, IRenderRoot, ILayoutRoot, ILogicalRoot
{
public TestScroller()
{
LayoutManager = new LayoutManager(this);
}
public IRenderer Renderer { get; }
public Size ClientSize { get; }
public double RenderScaling => 1;
@ -1070,7 +1075,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
public double LayoutScaling => 1;
public ILayoutManager LayoutManager { get; } = new LayoutManager();
public ILayoutManager LayoutManager { get; }
public IRenderTarget CreateRenderTarget() => throw new NotImplementedException();
public void Invalidate(Rect rect) => throw new NotImplementedException();

6
tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs

@ -158,7 +158,7 @@ namespace Avalonia.Controls.UnitTests
target.SetValue(ScrollViewer.ViewportProperty, new Size(50, 50));
target.Offset = new Vector(10, 10);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
target.ScrollChanged += (s, e) =>
{
@ -188,7 +188,7 @@ namespace Avalonia.Controls.UnitTests
target.SetValue(ScrollViewer.ViewportProperty, new Size(50, 50));
target.Offset = new Vector(10, 10);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
target.ScrollChanged += (s, e) =>
{
@ -218,7 +218,7 @@ namespace Avalonia.Controls.UnitTests
target.SetValue(ScrollViewer.ViewportProperty, new Size(50, 50));
target.Offset = new Vector(10, 10);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
target.ScrollChanged += (s, e) =>
{

25
tests/Avalonia.Controls.UnitTests/TopLevelTests.cs

@ -106,7 +106,7 @@ namespace Avalonia.Controls.UnitTests
}
};
target.LayoutManager.ExecuteInitialLayoutPass(target);
target.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Rect(0, 0, 321, 432), target.Bounds);
}
@ -267,6 +267,23 @@ namespace Avalonia.Controls.UnitTests
}
}
[Fact]
public void Close_Should_Dispose_LayoutManager()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var impl = new Mock<ITopLevelImpl>();
impl.SetupAllProperties();
var layoutManager = new Mock<ILayoutManager>();
var target = new TestTopLevel(impl.Object, layoutManager.Object);
impl.Object.Closed();
layoutManager.Verify(x => x.Dispose());
}
}
[Fact]
public void Reacts_To_Changes_In_Global_Styles()
{
@ -282,7 +299,7 @@ namespace Avalonia.Controls.UnitTests
Content = child,
};
target.LayoutManager.ExecuteInitialLayoutPass(target);
target.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Thickness(0), child.BorderThickness);
@ -295,7 +312,7 @@ namespace Avalonia.Controls.UnitTests
};
Application.Current.Styles.Add(style);
target.LayoutManager.ExecuteInitialLayoutPass(target);
target.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Thickness(2), child.BorderThickness);
@ -323,7 +340,7 @@ namespace Avalonia.Controls.UnitTests
public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
: base(impl)
{
_layoutManager = layoutManager ?? new LayoutManager();
_layoutManager = layoutManager ?? new LayoutManager(this);
}
protected override ILayoutManager CreateLayoutManager() => _layoutManager;

48
tests/Avalonia.Layout.UnitTests/LayoutManagerTests.cs

@ -13,7 +13,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = control.Arranged = false;
control.InvalidateMeasure();
@ -23,13 +23,29 @@ namespace Avalonia.Layout.UnitTests
Assert.True(control.Arranged);
}
[Fact]
public void Doesnt_Measure_And_Arrange_InvalidateMeasured_Control_When_TopLevel_Is_Not_Visible()
{
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control, IsVisible = false };
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = control.Arranged = false;
control.InvalidateMeasure();
root.LayoutManager.ExecuteLayoutPass();
Assert.False(control.Measured);
Assert.False(control.Arranged);
}
[Fact]
public void Arranges_InvalidateArranged_Control()
{
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = control.Arranged = false;
control.InvalidateArrange();
@ -45,7 +61,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot();
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
root.Child = control;
root.Measured = root.Arranged = false;
@ -80,7 +96,7 @@ namespace Avalonia.Layout.UnitTests
root.DoMeasureOverride = MeasureOverride;
control1.DoMeasureOverride = MeasureOverride;
control2.DoMeasureOverride = MeasureOverride;
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control2.InvalidateMeasure();
control1.InvalidateMeasure();
@ -115,7 +131,7 @@ namespace Avalonia.Layout.UnitTests
root.DoMeasureOverride = MeasureOverride;
control1.DoMeasureOverride = MeasureOverride;
control2.DoMeasureOverride = MeasureOverride;
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control2.InvalidateMeasure();
root.InvalidateMeasure();
@ -132,7 +148,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
root.Measured = root.Arranged = false;
control.Measured = control.Arranged = false;
@ -151,7 +167,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = control.Arranged = false;
control.InvalidateMeasure();
@ -177,7 +193,7 @@ namespace Avalonia.Layout.UnitTests
return new Size(100, 100);
};
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(Size.Infinity, availableSize);
}
@ -199,7 +215,7 @@ namespace Avalonia.Layout.UnitTests
return s;
};
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Size(100, 100), arrangeSize);
root.Width = 120;
@ -225,7 +241,7 @@ namespace Avalonia.Layout.UnitTests
}
};
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Size(0, 0), root.DesiredSize);
border.Width = 100;
@ -241,7 +257,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = false;
int cnt = 0;
@ -272,7 +288,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Arranged = false;
int cnt = 0;
@ -313,7 +329,7 @@ namespace Avalonia.Layout.UnitTests
panel.Children.AddRange(nonArrageableTargets);
panel.Children.AddRange(targets);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
foreach (var c in panel.Children.OfType<LayoutTestControl>())
{
@ -347,7 +363,7 @@ namespace Avalonia.Layout.UnitTests
var control = new LayoutTestControl();
var root = new LayoutTestRoot { Child = control };
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = false;
control.DoMeasureOverride = (l, s) =>
@ -380,7 +396,7 @@ namespace Avalonia.Layout.UnitTests
var root = new LayoutTestRoot { Child = control };
var count = 0;
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
control.Measured = false;
control.DoMeasureOverride = (l, s) =>
@ -399,7 +415,7 @@ namespace Avalonia.Layout.UnitTests
root.InvalidateMeasure();
control.InvalidateMeasure();
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(new Size(200, 200), control.Bounds.Size);
Assert.Equal(new Size(200, 200), control.DesiredSize);

4
tests/Avalonia.Layout.UnitTests/LayoutableTests.cs

@ -208,14 +208,12 @@ namespace Avalonia.Layout.UnitTests
{
Border border1;
Border border2;
var layoutManager = new LayoutManager();
var root = new TestRoot
{
Child = border1 = new Border
{
Child = border2 = new Border(),
},
LayoutManager = layoutManager,
};
var raised = 0;
@ -233,7 +231,7 @@ namespace Avalonia.Layout.UnitTests
root.Measure(new Size(100, 100));
root.Arrange(new Rect(0, 0, 100, 100));
layoutManager.ExecuteLayoutPass();
root.LayoutManager.ExecuteLayoutPass();
Assert.Equal(3, raised);
Assert.Equal(new Rect(0, 0, 100, 100), border1.Bounds);

20
tests/Avalonia.LeakTests/ControlTests.cs

@ -44,7 +44,7 @@ namespace Avalonia.LeakTests
window.Show();
// Do a layout and make sure that Canvas gets added to visual tree.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<Canvas>(window.Presenter.Child);
// Clear the content and ensure the Canvas is removed.
@ -82,7 +82,7 @@ namespace Avalonia.LeakTests
window.Show();
// Do a layout and make sure that Canvas gets added to visual tree.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<Canvas>(window.Find<Canvas>("foo"));
Assert.IsType<Canvas>(window.Presenter.Child);
@ -122,7 +122,7 @@ namespace Avalonia.LeakTests
// Do a layout and make sure that ScrollViewer gets added to visual tree and its
// template applied.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<ScrollViewer>(window.Presenter.Child);
Assert.IsType<Canvas>(((ScrollViewer)window.Presenter.Child).Presenter.Child);
@ -159,7 +159,7 @@ namespace Avalonia.LeakTests
// Do a layout and make sure that TextBox gets added to visual tree and its
// template applied.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<TextBox>(window.Presenter.Child);
Assert.NotEmpty(window.Presenter.Child.GetVisualChildren());
@ -203,7 +203,7 @@ namespace Avalonia.LeakTests
// Do a layout and make sure that TextBox gets added to visual tree and its
// Text property set.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<TextBox>(window.Presenter.Child);
Assert.Equal("foo", ((TextBox)window.Presenter.Child).Text);
@ -241,7 +241,7 @@ namespace Avalonia.LeakTests
// Do a layout and make sure that TextBox gets added to visual tree and its
// template applied.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.Same(textBox, window.Presenter.Child);
// Get the border from the TextBox template.
@ -295,7 +295,7 @@ namespace Avalonia.LeakTests
window.Show();
// Do a layout and make sure that TreeViewItems get realized.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.Single(target.ItemContainerGenerator.Containers);
// Clear the content and ensure the TreeView is removed.
@ -329,7 +329,7 @@ namespace Avalonia.LeakTests
window.Show();
// Do a layout and make sure that Slider gets added to visual tree.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<Slider>(window.Presenter.Child);
// Clear the content and ensure the Slider is removed.
@ -403,7 +403,7 @@ namespace Avalonia.LeakTests
// Do a layout and make sure that Canvas gets added to visual tree with
// its render transform.
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
var canvas = Assert.IsType<Canvas>(window.Presenter.Child);
Assert.IsType<RotateTransform>(canvas.RenderTransform);
@ -514,7 +514,7 @@ namespace Avalonia.LeakTests
window.Show();
window.LayoutManager.ExecuteInitialLayoutPass(window);
window.LayoutManager.ExecuteInitialLayoutPass();
Assert.IsType<Path>(window.Presenter.Child);
window.Content = null;

4
tests/Avalonia.UnitTests/TestRoot.cs

@ -19,6 +19,8 @@ namespace Avalonia.UnitTests
public TestRoot()
{
Renderer = Mock.Of<IRenderer>();
LayoutManager = new LayoutManager(this);
IsVisible = true;
}
public TestRoot(IControl child)
@ -44,7 +46,7 @@ namespace Avalonia.UnitTests
public double LayoutScaling { get; set; } = 1;
public ILayoutManager LayoutManager { get; set; } = new LayoutManager();
public ILayoutManager LayoutManager { get; set; }
public double RenderScaling => 1;

3
tests/Avalonia.UnitTests/TestTemplatedRoot.cs

@ -16,6 +16,7 @@ namespace Avalonia.UnitTests
public TestTemplatedRoot()
{
LayoutManager = new LayoutManager(this);
Template = new FuncControlTemplate<TestTemplatedRoot>((x, scope) => new ContentPresenter
{
Name = "PART_ContentPresenter",
@ -28,7 +29,7 @@ namespace Avalonia.UnitTests
public double LayoutScaling => 1;
public ILayoutManager LayoutManager { get; set; } = new LayoutManager();
public ILayoutManager LayoutManager { get; set; }
public double RenderScaling => 1;

8
tests/Avalonia.Visuals.UnitTests/Rendering/ImmediateRendererTests.cs

@ -134,7 +134,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var root = new TestRoot(child);
root.Renderer = new ImmediateRenderer(root);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
root.Measure(new Size(50, 100));
root.Arrange(new Rect(new Size(50, 100)));
@ -171,7 +171,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var root = new TestRoot(child);
root.Renderer = new ImmediateRenderer(root);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
root.Measure(new Size(300, 100));
root.Arrange(new Rect(new Size(300, 100)));
@ -222,7 +222,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var root = new TestRoot(rootGrid);
root.Renderer = new ImmediateRenderer(root);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
var rootSize = new Size(RootWidth, RootHeight);
root.Measure(rootSize);
@ -277,7 +277,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var root = new TestRoot(rootGrid);
root.Renderer = new ImmediateRenderer(root);
root.LayoutManager.ExecuteInitialLayoutPass(root);
root.LayoutManager.ExecuteInitialLayoutPass();
var rootSize = new Size(RootWidth, RootHeight);
root.Measure(rootSize);

6
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests.cs

@ -653,7 +653,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var scene = new Scene(tree);
var sceneBuilder = new SceneBuilder();
@ -696,7 +696,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var scene = new Scene(tree);
var sceneBuilder = new SceneBuilder();
@ -744,7 +744,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var scene = new Scene(tree);
var sceneBuilder = new SceneBuilder();

10
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/SceneBuilderTests_Layers.cs

@ -40,7 +40,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var animation = new BehaviorSubject<double>(0.5);
border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);
@ -105,7 +105,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var animation = new BehaviorSubject<double>(0.5);
border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);
@ -147,7 +147,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var animation = new BehaviorSubject<double>(0.5);
border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);
@ -197,7 +197,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var animation = new BehaviorSubject<double>(0.5);
border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);
@ -241,7 +241,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
};
var layout = tree.LayoutManager;
layout.ExecuteInitialLayoutPass(tree);
layout.ExecuteInitialLayoutPass();
var animation = new BehaviorSubject<double>(0.5);
border.Bind(Border.OpacityProperty, animation, BindingPriority.Animation);

Loading…
Cancel
Save