|
|
@ -12,14 +12,16 @@ namespace Avalonia.Layout |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class LayoutManager : ILayoutManager |
|
|
public class LayoutManager : ILayoutManager |
|
|
{ |
|
|
{ |
|
|
|
|
|
private readonly ILayoutRoot _owner; |
|
|
private readonly LayoutQueue<ILayoutable> _toMeasure = new LayoutQueue<ILayoutable>(v => !v.IsMeasureValid); |
|
|
private readonly LayoutQueue<ILayoutable> _toMeasure = new LayoutQueue<ILayoutable>(v => !v.IsMeasureValid); |
|
|
private readonly LayoutQueue<ILayoutable> _toArrange = new LayoutQueue<ILayoutable>(v => !v.IsArrangeValid); |
|
|
private readonly LayoutQueue<ILayoutable> _toArrange = new LayoutQueue<ILayoutable>(v => !v.IsArrangeValid); |
|
|
private readonly Action _executeLayoutPass; |
|
|
private readonly Action _executeLayoutPass; |
|
|
private bool _queued; |
|
|
private bool _queued; |
|
|
private bool _running; |
|
|
private bool _running; |
|
|
|
|
|
|
|
|
public LayoutManager() |
|
|
public LayoutManager(ILayoutRoot owner) |
|
|
{ |
|
|
{ |
|
|
|
|
|
_owner = owner ?? throw new ArgumentNullException(nameof(owner)); |
|
|
_executeLayoutPass = ExecuteLayoutPass; |
|
|
_executeLayoutPass = ExecuteLayoutPass; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -73,6 +75,11 @@ namespace Avalonia.Layout |
|
|
|
|
|
|
|
|
Dispatcher.UIThread.VerifyAccess(); |
|
|
Dispatcher.UIThread.VerifyAccess(); |
|
|
|
|
|
|
|
|
|
|
|
if (!_owner.IsVisible) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!_running) |
|
|
if (!_running) |
|
|
{ |
|
|
{ |
|
|
_running = true; |
|
|
_running = true; |
|
|
@ -131,13 +138,13 @@ namespace Avalonia.Layout |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
public virtual void ExecuteInitialLayoutPass(ILayoutRoot root) |
|
|
public virtual void ExecuteInitialLayoutPass() |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
_running = true; |
|
|
_running = true; |
|
|
Measure(root); |
|
|
Measure(_owner); |
|
|
Arrange(root); |
|
|
Arrange(_owner); |
|
|
} |
|
|
} |
|
|
finally |
|
|
finally |
|
|
{ |
|
|
{ |
|
|
@ -151,6 +158,17 @@ namespace Avalonia.Layout |
|
|
ExecuteLayoutPass(); |
|
|
ExecuteLayoutPass(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Obsolete("Call ExecuteInitialLayoutPass without parameter")] |
|
|
|
|
|
public void ExecuteInitialLayoutPass(ILayoutRoot root) |
|
|
|
|
|
{ |
|
|
|
|
|
if (root != _owner) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new ArgumentException("ExecuteInitialLayoutPass called with incorrect root."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ExecuteInitialLayoutPass(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void ExecuteMeasurePass() |
|
|
private void ExecuteMeasurePass() |
|
|
{ |
|
|
{ |
|
|
while (_toMeasure.Count > 0) |
|
|
while (_toMeasure.Count > 0) |
|
|
@ -228,7 +246,7 @@ namespace Avalonia.Layout |
|
|
|
|
|
|
|
|
private void QueueLayoutPass() |
|
|
private void QueueLayoutPass() |
|
|
{ |
|
|
{ |
|
|
if (!_queued && !_running) |
|
|
if (!_queued && !_running && _owner.IsVisible) |
|
|
{ |
|
|
{ |
|
|
Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); |
|
|
Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); |
|
|
_queued = true; |
|
|
_queued = true; |
|
|
|