diff --git a/AvaloniaExtensions/CanvasControlExtensions.cs b/AvaloniaExtensions/CanvasControlExtensions.cs index 06bf5d7..eafe98c 100644 --- a/AvaloniaExtensions/CanvasControlExtensions.cs +++ b/AvaloniaExtensions/CanvasControlExtensions.cs @@ -49,6 +49,8 @@ public static T HotKey(this T control, string hotkey) where T : Button { public static double GetWidth(this Control ctrl) => double.IsNaN(ctrl.Width) ? ctrl.Bounds.Width : ctrl.Width; public static double GetHeight(this Control ctrl) => double.IsNaN(ctrl.Height) ? ctrl.Bounds.Height : ctrl.Height; + public static T SetWidth(this T ctrl, double width) where T : Control => ctrl.Width(Math.Max(width, 2)); + public static T SetHeight(this T ctrl, double height) where T : Control => ctrl.Height(Math.Max(height, 2)); // --- Position relative to other controls --- public static T RightOf(this T control) where T : Control => control.RightOf(PreviousControlFor(control)); @@ -209,26 +211,26 @@ public static T YBottomInPanel(this T control) where T : Control { public static T StretchRightTo(this T control, Control other) where T : Control { ThrowIfPositioningRelativeToYourself(control, other); return CanvasComponentBase.RegisterOnResizeAction(control, - () => control.Width(other.GetX() - control.GetX() - Math.Max(control.Margin.Right, other.Margin.Left))); + () => control.SetWidth(other.GetX() - control.GetX() - Math.Max(control.Margin.Right, other.Margin.Left))); } public static T StretchDownTo(this T control) where T : Control => control.StretchDownTo(PreviousControlFor(control)); public static T StretchDownTo(this T control, Control other) where T : Control { ThrowIfPositioningRelativeToYourself(control, other); return CanvasComponentBase.RegisterOnResizeAction(control, - () => control.Height(other.GetY() - control.GetY() - Math.Max(control.Margin.Bottom, other.Margin.Top))); + () => control.SetHeight(other.GetY() - control.GetY() - Math.Max(control.Margin.Bottom, other.Margin.Top))); } public static T StretchRightInPanel(this T control) where T : Control { return CanvasComponentBase.RegisterOnResizeAction(control, () => { var canvas = CanvasComponentBase.FindCanvas(control); - control.Width(canvas.GetWidth() - control.GetX() - control.Margin.Left - control.Margin.Right); + control.SetWidth(canvas.GetWidth() - control.GetX() - control.Margin.Left - control.Margin.Right); }); } public static T StretchDownInPanel(this T control) where T : Control { return CanvasComponentBase.RegisterOnResizeAction(control, () => { var canvas = CanvasComponentBase.FindCanvas(control); - control.Height(canvas.GetHeight() - control.GetY() - control.Margin.Top - control.Margin.Bottom); + control.SetHeight(canvas.GetHeight() - control.GetY() - control.Margin.Top - control.Margin.Bottom); }); } @@ -236,14 +238,14 @@ public static T StretchFractionRightInPanel(this T control, int numerator, in return CanvasComponentBase.RegisterOnResizeAction(control, () => { var canvas = CanvasComponentBase.FindCanvas(control); var fullWidth = canvas.GetWidth() - control.GetX() - control.Margin.Left - control.Margin.Right; - control.Width(fullWidth * numerator / denominator - control.Margin.Right * .5f); + control.SetWidth(fullWidth * numerator / denominator - control.Margin.Right * .5f); }); } public static T StretchFractionDownInPanel(this T control, int numerator, int denominator) where T : Control { return CanvasComponentBase.RegisterOnResizeAction(control, () => { var canvas = CanvasComponentBase.FindCanvas(control); var fullHeight = canvas.GetHeight() - control.GetY() - control.Margin.Top - control.Margin.Bottom; - control.Height(fullHeight * numerator / denominator - control.Margin.Bottom * .5f); + control.SetHeight(fullHeight * numerator / denominator - control.Margin.Bottom * .5f); }); } diff --git a/build-example-release.sh b/build-example-release.sh index 897914a..c2ab7ea 100755 --- a/build-example-release.sh +++ b/build-example-release.sh @@ -5,6 +5,6 @@ cd ExampleApp/ rm -rf publish-win-x64 rm -rf publish-linux-x64 -# Build application -dotnet publish -c Release -o ./publish-win-x64 -f net8.0 -r win-x64 --self-contained /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true -dotnet publish -c Release -o ./publish-linux-x64 -f net8.0 -r linux-x64 --self-contained /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true +# Build application (note that you might want to disable trimming, because it could cause problems) +dotnet publish -c Release -o ./publish-win-x64 -f net8.0 -r win-x64 --self-contained /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishTrimmed=true +dotnet publish -c Release -o ./publish-linux-x64 -f net8.0 -r linux-x64 --self-contained /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:PublishTrimmed=true