Browse Source

Fixed unnecessary window displacement on resize (#18004)

* Added new test: changing window size should not change position

* Removed unnecessary window placement assignment to fix window position shifting due to incorrect workspace coordinate usage

* Fixed test because buttons went off the window on tiny screen resolutions

* Make test Windows specific

* Use `Bounds` instead of `Width` and `Height` properties as they are "requested" size rather than actual size (see #18060)
repro/18104-drag-drop-flyout-placement
Melissa 1 year ago
committed by GitHub
parent
commit
29fbaaa878
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      samples/IntegrationTestApp/ShowWindowTest.axaml
  2. 4
      samples/IntegrationTestApp/ShowWindowTest.axaml.cs
  3. 6
      src/Windows/Avalonia.Win32/WindowImpl.cs
  4. 18
      tests/Avalonia.IntegrationTests.Appium/WindowTests.cs

6
samples/IntegrationTestApp/ShowWindowTest.axaml

@ -53,7 +53,11 @@
<Label Grid.Row="11" Content="MeasuredWith:" />
<TextBlock Grid.Column="1" Grid.Row="11" Name="CurrentMeasuredWithText" Text="{Binding #MyBorder.MeasuredWith}" />
<Button Name="HideButton" Grid.Row="12" Command="{Binding $parent[Window].Hide}">Hide</Button>
<StackPanel Orientation="Horizontal" Grid.Row="12">
<Button Name="HideButton" Command="{Binding $parent[Window].Hide}">Hide</Button>
<Button Name="AddToWidth" Click="AddToWidth_Click">Add to Width</Button>
<Button Name="AddToHeight" Click="AddToHeight_Click">Add to Height</Button>
</StackPanel>
</Grid>
</integrationTestApp:MeasureBorder>

4
samples/IntegrationTestApp/ShowWindowTest.axaml.cs

@ -2,6 +2,7 @@ using System;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;
namespace IntegrationTestApp
@ -70,5 +71,8 @@ namespace IntegrationTestApp
{
_orderTextBox!.Text = MacOSIntegration.GetOrderedIndex(this).ToString();
}
private void AddToWidth_Click(object? sender, RoutedEventArgs e) => Width = Bounds.Width + 10;
private void AddToHeight_Click(object? sender, RoutedEventArgs e) => Height = Bounds.Height + 10;
}
}

6
src/Windows/Avalonia.Win32/WindowImpl.cs

@ -608,12 +608,6 @@ namespace Avalonia.Win32
return;
}
}
else
{
var position = Position;
windowPlacement.NormalPosition.left = position.X;
windowPlacement.NormalPosition.top = position.Y;
}
windowPlacement.NormalPosition.right = windowPlacement.NormalPosition.left + windowWidth;
windowPlacement.NormalPosition.bottom = windowPlacement.NormalPosition.top + windowHeight;

18
tests/Avalonia.IntegrationTests.Appium/WindowTests.cs

@ -349,6 +349,24 @@ namespace Avalonia.IntegrationTests.Appium
}
}
[PlatformFact(TestPlatforms.Windows)]
public void Changing_Size_Should_Not_Change_Position()
{
using (OpenWindow())
{
var info = GetWindowInfo();
Session.FindElementByAccessibilityId("AddToWidth").SendClick();
Session.FindElementByAccessibilityId("AddToHeight").SendClick();
var updatedInfo = GetWindowInfo();
Assert.Equal(info.Position, updatedInfo.Position);
Assert.Equal(info.FrameSize
.WithWidth(info.FrameSize.Width + 10)
.WithHeight(info.FrameSize.Height + 10), updatedInfo.FrameSize);
}
}
public static TheoryData<Size?, ShowWindowMode, WindowStartupLocation, bool> StartupLocationData()
{
var sizes = new Size?[] { null, new Size(400, 300) };

Loading…
Cancel
Save