Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call a layout pass on RenderTransform changes #15124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Avalonia.Base/Layout/ILayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public interface ILayoutManager : IDisposable
/// <param name="control">The control.</param>
void InvalidateArrange(Layoutable control);

/// <summary>
/// Notifies the layout manager that a control queues a calculation of the effective viewport.
/// </summary>
/// <param name="control">The control.</param>
void InvalidateViewport(Visual control);

/// <summary>
/// Executes a layout pass.
/// </summary>
Expand Down
33 changes: 33 additions & 0 deletions src/Avalonia.Base/Layout/LayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,39 @@ public virtual void InvalidateArrange(Layoutable control)
QueueLayoutPass();
}

/// <inheritdoc/>
public virtual void InvalidateViewport(Visual control)
{
control = control ?? throw new ArgumentNullException(nameof(control));
Dispatcher.UIThread.VerifyAccess();

if (_disposed)
{
return;
}

if (!control.IsAttachedToVisualTree)
{
#if DEBUG
throw new AvaloniaInternalException(
"LayoutManager.InvalidateViewport called on a control that is detached from the visual tree.");
#else
return;
#endif
}

if (control.VisualRoot != _owner)
{
throw new ArgumentException("Attempt to call InvalidateViewport on wrong LayoutManager.");
}

if (_effectiveViewportChangedListeners is object &&
_effectiveViewportChangedListeners.Count > 0)
{
QueueLayoutPass();
}
}

internal void ExecuteQueuedLayoutPass()
{
if (!_queued)
Expand Down
4 changes: 4 additions & 0 deletions src/Avalonia.Base/Layout/Layoutable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ private void AncestorBecameVisible(ILayoutManager layoutManager)
layoutManager.InvalidateArrange(this);
InvalidateVisual();
}
else
{
layoutManager.InvalidateViewport(this);
}

var count = VisualChildren.Count;

Expand Down
11 changes: 11 additions & 0 deletions src/Avalonia.Base/Visual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Specialized;
using Avalonia.Collections;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Logging;
using Avalonia.LogicalTree;
using Avalonia.Media;
Expand Down Expand Up @@ -378,6 +379,14 @@ public void InvalidateVisual()
VisualRoot?.Renderer.AddDirty(this);
}

/// <summary>
/// Queues a calculation of the effective viewport.
/// </summary>
protected void InvalidateViewport()
{
(VisualRoot as ILayoutRoot)?.LayoutManager?.InvalidateViewport(this);
}

/// <summary>
/// Renders the visual to a <see cref="DrawingContext"/>.
/// </summary>
Expand Down Expand Up @@ -612,6 +621,7 @@ private static void RenderTransformChanged(AvaloniaPropertyChangedEventArgs<ITra
}

sender.InvalidateVisual();
sender.InvalidateViewport();
}
}

Expand Down Expand Up @@ -656,6 +666,7 @@ private static void ZIndexChanged(AvaloniaPropertyChangedEventArgs e)
private void RenderTransformChanged(object? sender, EventArgs e)
{
InvalidateVisual();
InvalidateViewport();
}

/// <summary>
Expand Down