From 57ec11d9d35ae1df091e271fc3b7666c17c6a77f Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 15 Apr 2021 13:57:19 +0100 Subject: [PATCH 1/3] upstream relativepanel fixes from https://github.com/HandyOrg/HandyControl/commit/f4d4bdde1036ab3e160e805a40dea127d72616a5 --- src/Avalonia.Controls/RelativePanel.cs | 46 ++++++++++++++------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Avalonia.Controls/RelativePanel.cs b/src/Avalonia.Controls/RelativePanel.cs index 27f13a3f57..8fe56d1fb2 100644 --- a/src/Avalonia.Controls/RelativePanel.cs +++ b/src/Avalonia.Controls/RelativePanel.cs @@ -55,7 +55,7 @@ namespace Avalonia.Controls _childGraph.Measure(availableSize); _childGraph.Reset(false); - var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN()); + var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN(), availableSize); _childGraph.Reset(); _childGraph.Measure(boundingSize); return boundingSize; @@ -286,6 +286,8 @@ namespace Avalonia.Controls private void MeasureChild(GraphNode node) { + var availableSize = AvailableSize; + var child = node.Element; child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); node.OriginDesiredSize = child.DesiredSize; @@ -328,10 +330,10 @@ namespace Avalonia.Controls : node.AlignBottomWithNode.Bottom * 0.5; } - var availableHeight = AvailableSize.Height - node.Top - node.Bottom; + var availableHeight = availableSize.Height - node.Top - node.Bottom; if (availableHeight.IsNaN()) { - availableHeight = AvailableSize.Height; + availableHeight = availableSize.Height; if (!node.Top.IsNaN() && node.Bottom.IsNaN()) { @@ -343,10 +345,10 @@ namespace Avalonia.Controls } } - var availableWidth = AvailableSize.Width - node.Left - node.Right; + var availableWidth = availableSize.Width - node.Left - node.Right; if (availableWidth.IsNaN()) { - availableWidth = AvailableSize.Width; + availableWidth = availableSize.Width; if (!node.Left.IsNaN() && node.Right.IsNaN()) { @@ -380,7 +382,7 @@ namespace Avalonia.Controls if (node.Left.IsNaN()) { - node.Left = AvailableSize.Width - node.RightOfNode.Right; + node.Left = availableSize.Width - node.RightOfNode.Right; } } @@ -393,14 +395,14 @@ namespace Avalonia.Controls if (node.Top.IsNaN()) { - node.Top = AvailableSize.Height - node.BelowNode.Bottom; + node.Top = availableSize.Height - node.BelowNode.Bottom; } } if (node.AlignHorizontalCenterWith != null) { - var halfWidthLeft = (AvailableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; - var halfWidthRight = (AvailableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; + var halfWidthLeft = (availableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; + var halfWidthRight = (availableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; if (node.Left.IsNaN()) node.Left = halfWidthLeft; @@ -415,8 +417,8 @@ namespace Avalonia.Controls if (node.AlignVerticalCenterWith != null) { - var halfHeightTop = (AvailableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; - var halfHeightBottom = (AvailableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; + var halfHeightTop = (availableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; + var halfHeightBottom = (availableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; if (node.Top.IsNaN()) node.Top = halfHeightTop; @@ -431,7 +433,7 @@ namespace Avalonia.Controls if (GetAlignHorizontalCenterWithPanel(child)) { - var halfSubWidth = (AvailableSize.Width - childSize.Width) * 0.5; + var halfSubWidth = (availableSize.Width - childSize.Width) * 0.5; if (node.Left.IsNaN()) node.Left = halfSubWidth; @@ -446,7 +448,7 @@ namespace Avalonia.Controls if (GetAlignVerticalCenterWithPanel(child)) { - var halfSubHeight = (AvailableSize.Height - childSize.Height) * 0.5; + var halfSubHeight = (availableSize.Height - childSize.Height) * 0.5; if (node.Top.IsNaN()) node.Top = halfSubHeight; @@ -462,37 +464,37 @@ namespace Avalonia.Controls if (node.Left.IsNaN()) { if (!node.Right.IsNaN()) - node.Left = AvailableSize.Width - node.Right - childSize.Width; + node.Left = availableSize.Width - node.Right - childSize.Width; else { node.Left = 0; - node.Right = AvailableSize.Width - childSize.Width; + node.Right = availableSize.Width - childSize.Width; } } else if (!node.Left.IsNaN() && node.Right.IsNaN()) { - node.Right = AvailableSize.Width - node.Left - childSize.Width; + node.Right = availableSize.Width - node.Left - childSize.Width; } if (node.Top.IsNaN()) { if (!node.Bottom.IsNaN()) - node.Top = AvailableSize.Height - node.Bottom - childSize.Height; + node.Top = availableSize.Height - node.Bottom - childSize.Height; else { node.Top = 0; - node.Bottom = AvailableSize.Height - childSize.Height; + node.Bottom = availableSize.Height - childSize.Height; } } else if (!node.Top.IsNaN() && node.Bottom.IsNaN()) { - node.Bottom = AvailableSize.Height - node.Top - childSize.Height; + node.Bottom = availableSize.Height - node.Top - childSize.Height; } node.Measured = true; } - public Size GetBoundingSize(bool calcWidth, bool calcHeight) + public Size GetBoundingSize(bool calcWidth, bool calcHeight, Size availableSize) { var boundingSize = new Size(); @@ -503,8 +505,8 @@ namespace Avalonia.Controls boundingSize = boundingSize.WithHeight(Math.Max(boundingSize.Height, size.Height)); } - boundingSize = boundingSize.WithWidth(calcWidth ? boundingSize.Width : AvailableSize.Width); - boundingSize = boundingSize.WithHeight(calcHeight ? boundingSize.Height : AvailableSize.Height); + boundingSize = boundingSize.WithWidth(calcWidth ? Math.Max(availableSize.Width, boundingSize.Width) : availableSize.Width); + boundingSize = boundingSize.WithHeight(calcHeight ? Math.Max(availableSize.Height, boundingSize.Height) : availableSize.Height); return boundingSize; } } From 84bc8b682cd491ccd8e606699c29f495c4cf2fd3 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 19 Apr 2021 19:33:10 +0100 Subject: [PATCH 2/3] upstream fix https://github.com/HandyOrg/HandyControl/commit/916d3d12b2f04ea5115cc0088589741a64b62a0e --- src/Avalonia.Controls/RelativePanel.cs | 49 +++++++++++++------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Avalonia.Controls/RelativePanel.cs b/src/Avalonia.Controls/RelativePanel.cs index 8fe56d1fb2..2305d8fb9e 100644 --- a/src/Avalonia.Controls/RelativePanel.cs +++ b/src/Avalonia.Controls/RelativePanel.cs @@ -55,7 +55,10 @@ namespace Avalonia.Controls _childGraph.Measure(availableSize); _childGraph.Reset(false); - var boundingSize = _childGraph.GetBoundingSize(Width.IsNaN(), Height.IsNaN(), availableSize); + var calcWidth = Width.IsNaN() && HorizontalAlignment != HorizontalAlignment.Stretch; + var calcHeight = Height.IsNaN() && VerticalAlignment != VerticalAlignment.Stretch; + + var boundingSize = _childGraph.GetBoundingSize(calcWidth, calcHeight); _childGraph.Reset(); _childGraph.Measure(boundingSize); return boundingSize; @@ -286,8 +289,6 @@ namespace Avalonia.Controls private void MeasureChild(GraphNode node) { - var availableSize = AvailableSize; - var child = node.Element; child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); node.OriginDesiredSize = child.DesiredSize; @@ -330,10 +331,10 @@ namespace Avalonia.Controls : node.AlignBottomWithNode.Bottom * 0.5; } - var availableHeight = availableSize.Height - node.Top - node.Bottom; + var availableHeight = AvailableSize.Height - node.Top - node.Bottom; if (availableHeight.IsNaN()) { - availableHeight = availableSize.Height; + availableHeight = AvailableSize.Height; if (!node.Top.IsNaN() && node.Bottom.IsNaN()) { @@ -345,10 +346,10 @@ namespace Avalonia.Controls } } - var availableWidth = availableSize.Width - node.Left - node.Right; + var availableWidth = AvailableSize.Width - node.Left - node.Right; if (availableWidth.IsNaN()) { - availableWidth = availableSize.Width; + availableWidth = AvailableSize.Width; if (!node.Left.IsNaN() && node.Right.IsNaN()) { @@ -382,7 +383,7 @@ namespace Avalonia.Controls if (node.Left.IsNaN()) { - node.Left = availableSize.Width - node.RightOfNode.Right; + node.Left = AvailableSize.Width - node.RightOfNode.Right; } } @@ -395,14 +396,14 @@ namespace Avalonia.Controls if (node.Top.IsNaN()) { - node.Top = availableSize.Height - node.BelowNode.Bottom; + node.Top = AvailableSize.Height - node.BelowNode.Bottom; } } if (node.AlignHorizontalCenterWith != null) { - var halfWidthLeft = (availableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; - var halfWidthRight = (availableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; + var halfWidthLeft = (AvailableSize.Width + node.AlignHorizontalCenterWith.Left - node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; + var halfWidthRight = (AvailableSize.Width - node.AlignHorizontalCenterWith.Left + node.AlignHorizontalCenterWith.Right - childSize.Width) * 0.5; if (node.Left.IsNaN()) node.Left = halfWidthLeft; @@ -417,8 +418,8 @@ namespace Avalonia.Controls if (node.AlignVerticalCenterWith != null) { - var halfHeightTop = (availableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; - var halfHeightBottom = (availableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; + var halfHeightTop = (AvailableSize.Height + node.AlignVerticalCenterWith.Top - node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; + var halfHeightBottom = (AvailableSize.Height - node.AlignVerticalCenterWith.Top + node.AlignVerticalCenterWith.Bottom - childSize.Height) * 0.5; if (node.Top.IsNaN()) node.Top = halfHeightTop; @@ -433,7 +434,7 @@ namespace Avalonia.Controls if (GetAlignHorizontalCenterWithPanel(child)) { - var halfSubWidth = (availableSize.Width - childSize.Width) * 0.5; + var halfSubWidth = (AvailableSize.Width - childSize.Width) * 0.5; if (node.Left.IsNaN()) node.Left = halfSubWidth; @@ -448,7 +449,7 @@ namespace Avalonia.Controls if (GetAlignVerticalCenterWithPanel(child)) { - var halfSubHeight = (availableSize.Height - childSize.Height) * 0.5; + var halfSubHeight = (AvailableSize.Height - childSize.Height) * 0.5; if (node.Top.IsNaN()) node.Top = halfSubHeight; @@ -464,37 +465,37 @@ namespace Avalonia.Controls if (node.Left.IsNaN()) { if (!node.Right.IsNaN()) - node.Left = availableSize.Width - node.Right - childSize.Width; + node.Left = AvailableSize.Width - node.Right - childSize.Width; else { node.Left = 0; - node.Right = availableSize.Width - childSize.Width; + node.Right = AvailableSize.Width - childSize.Width; } } else if (!node.Left.IsNaN() && node.Right.IsNaN()) { - node.Right = availableSize.Width - node.Left - childSize.Width; + node.Right = AvailableSize.Width - node.Left - childSize.Width; } if (node.Top.IsNaN()) { if (!node.Bottom.IsNaN()) - node.Top = availableSize.Height - node.Bottom - childSize.Height; + node.Top = AvailableSize.Height - node.Bottom - childSize.Height; else { node.Top = 0; - node.Bottom = availableSize.Height - childSize.Height; + node.Bottom = AvailableSize.Height - childSize.Height; } } else if (!node.Top.IsNaN() && node.Bottom.IsNaN()) { - node.Bottom = availableSize.Height - node.Top - childSize.Height; + node.Bottom = AvailableSize.Height - node.Top - childSize.Height; } node.Measured = true; } - public Size GetBoundingSize(bool calcWidth, bool calcHeight, Size availableSize) + public Size GetBoundingSize(bool calcWidth, bool calcHeight) { var boundingSize = new Size(); @@ -505,8 +506,8 @@ namespace Avalonia.Controls boundingSize = boundingSize.WithHeight(Math.Max(boundingSize.Height, size.Height)); } - boundingSize = boundingSize.WithWidth(calcWidth ? Math.Max(availableSize.Width, boundingSize.Width) : availableSize.Width); - boundingSize = boundingSize.WithHeight(calcHeight ? Math.Max(availableSize.Height, boundingSize.Height) : availableSize.Height); + boundingSize = boundingSize.WithWidth(calcWidth ? boundingSize.Width : AvailableSize.Width); + boundingSize = boundingSize.WithHeight(calcHeight ? boundingSize.Height : AvailableSize.Height); return boundingSize; } } From c39fa50efc30769073ec8d37725c7dab53fd4b6c Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 19 Apr 2021 20:03:35 +0100 Subject: [PATCH 3/3] [osx] if app only has an app menu and no window menu, ensure its applied when window is first shown. --- native/Avalonia.Native/src/OSX/window.mm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/native/Avalonia.Native/src/OSX/window.mm b/native/Avalonia.Native/src/OSX/window.mm index b46655c7df..d7afbdaa3a 100644 --- a/native/Avalonia.Native/src/OSX/window.mm +++ b/native/Avalonia.Native/src/OSX/window.mm @@ -1936,6 +1936,10 @@ NSArray* AllLoopModes = [NSArray arrayWithObjects: NSDefaultRunLoopMode, NSEvent [NSApp setMenu:_menu]; } + else + { + [self showAppMenuOnly]; + } } -(void) showAppMenuOnly