Browse Source

prevent excess layout passes in layout manager to catch other scenarios causing

excessive layout passes.
pull/8305/head
Dan Walmsley 4 years ago
parent
commit
96931e2203
  1. 14
      src/Avalonia.Base/Layout/LayoutManager.cs
  2. 6
      src/Avalonia.Controls/TopLevel.cs
  3. 6
      src/Avalonia.Controls/WindowBase.cs

14
src/Avalonia.Base/Layout/LayoutManager.cs

@ -28,7 +28,7 @@ namespace Avalonia.Layout
public LayoutManager(ILayoutRoot owner)
{
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
_executeLayoutPass = ExecuteLayoutPass;
_executeLayoutPass = ExecuteQueuedLayoutPass;
}
public virtual event EventHandler? LayoutUpdated;
@ -94,6 +94,16 @@ namespace Avalonia.Layout
QueueLayoutPass();
}
private void ExecuteQueuedLayoutPass()
{
if (!_queued)
{
return;
}
ExecuteLayoutPass();
}
/// <inheritdoc/>
public virtual void ExecuteLayoutPass()
{
@ -319,8 +329,8 @@ namespace Avalonia.Layout
{
if (!_queued && !_running)
{
Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout);
_queued = true;
Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout);
}
}

6
src/Avalonia.Controls/TopLevel.cs

@ -413,11 +413,7 @@ namespace Avalonia.Controls
FrameSize = PlatformImpl!.FrameSize;
Width = clientSize.Width;
Height = clientSize.Height;
// Setting ClientSize and Width / Height above caused ExecuteLayoutPass to be queued.
// Instead of explicitly calling LayoutManager.ExecuteLayoutPass here, we clear the job queue.
Dispatcher.UIThread.RunJobs(DispatcherPriority.Layout);
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
}

6
src/Avalonia.Controls/WindowBase.cs

@ -220,11 +220,7 @@ namespace Avalonia.Controls
{
ClientSize = clientSize;
FrameSize = PlatformImpl?.FrameSize;
// Setting ClientSize and Width / Height above caused ExecuteLayoutPass to be queued.
// Instead of explicitly calling LayoutManager.ExecuteLayoutPass here, we clear the job queue.
Dispatcher.UIThread.RunJobs(DispatcherPriority.Layout);
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);
}

Loading…
Cancel
Save