Browse Source

Make Window and Popup respect layout properties.

Had to remove syncing client size to `Width`/`Height` in `PopupRoot` bceause without the `SizeToContent` property it was impossible to tell whether its `Width`/`Height` came from a requested bound or from the actual window size.
pull/3797/head
Steven Kirk 6 years ago
parent
commit
945054be25
  1. 27
      src/Avalonia.Controls/Primitives/PopupRoot.cs
  2. 23
      src/Avalonia.Controls/Window.cs
  3. 2
      src/Avalonia.Controls/WindowBase.cs

27
src/Avalonia.Controls/Primitives/PopupRoot.cs

@ -117,6 +117,33 @@ namespace Avalonia.Controls.Primitives
});
}
protected override Size MeasureOverride(Size availableSize)
{
var measured = base.MeasureOverride(availableSize);
var width = measured.Width;
var height = measured.Height;
var widthCache = Width;
var heightCache = Height;
if (!double.IsNaN(widthCache))
{
width = widthCache;
}
width = Math.Min(width, MaxWidth);
width = Math.Max(width, MinWidth);
if (!double.IsNaN(heightCache))
{
height = heightCache;
}
height = Math.Min(height, MaxHeight);
height = Math.Max(height, MinHeight);
return new Size(width, height);
}
protected override sealed Size ArrangeSetBounds(Size size)
{
using (BeginAutoSizing())

23
src/Avalonia.Controls/Window.cs

@ -570,8 +570,8 @@ namespace Avalonia.Controls
protected override Size MeasureOverride(Size availableSize)
{
var sizeToContent = SizeToContent;
var constraint = availableSize;
var clientSize = ClientSize;
var constraint = clientSize;
if (sizeToContent.HasFlagCustom(SizeToContent.Width))
{
@ -587,12 +587,26 @@ namespace Avalonia.Controls
if (!sizeToContent.HasFlagCustom(SizeToContent.Width))
{
result = result.WithWidth(clientSize.Width);
if (!double.IsInfinity(availableSize.Width))
{
result = result.WithWidth(availableSize.Width);
}
else
{
result = result.WithWidth(clientSize.Width);
}
}
if (!sizeToContent.HasFlagCustom(SizeToContent.Height))
{
result = result.WithHeight(clientSize.Height);
if (!double.IsInfinity(availableSize.Height))
{
result = result.WithHeight(availableSize.Height);
}
else
{
result = result.WithHeight(clientSize.Height);
}
}
return result;
@ -622,6 +636,9 @@ namespace Avalonia.Controls
SizeToContent = SizeToContent.Manual;
}
Width = clientSize.Width;
Height = clientSize.Height;
base.HandleResized(clientSize);
}

2
src/Avalonia.Controls/WindowBase.cs

@ -224,8 +224,6 @@ namespace Avalonia.Controls
/// <param name="clientSize">The new client size.</param>
protected override void HandleResized(Size clientSize)
{
Width = clientSize.Width;
Height = clientSize.Height;
ClientSize = clientSize;
LayoutManager.ExecuteLayoutPass();
Renderer?.Resized(clientSize);

Loading…
Cancel
Save