Browse Source

Break layout flip flop in headless

pull/11763/head
jankrib 3 years ago
parent
commit
26d4746096
  1. 13
      src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs
  2. 24
      tests/Avalonia.Headless.UnitTests/RenderingTests.cs

13
src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs

@ -114,23 +114,26 @@ namespace Avalonia.Headless
public Size MaxClientSize { get; } = new Size(1920, 1280); public Size MaxClientSize { get; } = new Size(1920, 1280);
public void Resize(Size clientSize, WindowResizeReason reason) public void Resize(Size clientSize, WindowResizeReason reason)
{ {
if (ClientSize == clientSize)
return;
// Emulate X11 behavior here // Emulate X11 behavior here
if (IsPopup) if (IsPopup)
DoResize(clientSize); DoResize(clientSize, reason);
else else
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
{ {
DoResize(clientSize); DoResize(clientSize, reason);
}); }, DispatcherPriority.Send);
} }
private void DoResize(Size clientSize) private void DoResize(Size clientSize, WindowResizeReason reason)
{ {
// Uncomment this check and experience a weird bug in layout engine // Uncomment this check and experience a weird bug in layout engine
if (ClientSize != clientSize) if (ClientSize != clientSize)
{ {
ClientSize = clientSize; ClientSize = clientSize;
Resized?.Invoke(clientSize, WindowResizeReason.Unspecified); Resized?.Invoke(clientSize, reason);
} }
} }

24
tests/Avalonia.Headless.UnitTests/RenderingTests.cs

@ -1,4 +1,5 @@
using Avalonia.Controls; using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Threading; using Avalonia.Threading;
@ -24,6 +25,27 @@ public class RenderingTests
Content = new PathIcon Content = new PathIcon
{ {
Data = StreamGeometry.Parse("M0,9 L10,0 20,9 19,10 10,2 1,10 z") Data = StreamGeometry.Parse("M0,9 L10,0 20,9 19,10 10,2 1,10 z")
#if NUNIT
[AvaloniaTest, Timeout(10000)]
#elif XUNIT
[AvaloniaFact(Timeout = 10000)]
#endif
public void Should_Not_Hang_With_Non_Trivial_Layout()
{
var window = new Window
{
Content = new ContentControl
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Padding = new Thickness(1),
Content = new ListBox
{
ItemsSource = new ObservableCollection<string>()
{
"Test 1",
"Test 2"
}
} }
}, },
SizeToContent = SizeToContent.WidthAndHeight SizeToContent = SizeToContent.WidthAndHeight

Loading…
Cancel
Save