From c19364e80db9f5b46f8579b0b56d9db7f48fcd71 Mon Sep 17 00:00:00 2001 From: Curtis Wensley Date: Mon, 16 Aug 2021 13:00:44 -0700 Subject: [PATCH] Mac: Fix CheckBox alignment when the title is blank on Big Sur --- src/Eto.Mac/Forms/Controls/CheckBoxHandler.cs | 10 ++++++++-- test/Eto.Test/Sections/Controls/CheckBoxSection.cs | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Eto.Mac/Forms/Controls/CheckBoxHandler.cs b/src/Eto.Mac/Forms/Controls/CheckBoxHandler.cs index b2e28bc0fb..18296a7920 100644 --- a/src/Eto.Mac/Forms/Controls/CheckBoxHandler.cs +++ b/src/Eto.Mac/Forms/Controls/CheckBoxHandler.cs @@ -61,12 +61,18 @@ public override NSControlSize ControlSize nfloat GetButtonOffset(CGRect rect) { + var titleSize = AttributedTitle.Size; // big sur and later calculate the position a wee differently.. if (MacVersion.IsAtLeast(10, 16)) - return (nfloat)Math.Ceiling((rect.Height - AttributedTitle.Size.Height) / 2); + { + if (AttributedTitle.Length > 0) + return (nfloat)Math.Ceiling((rect.Height - titleSize.Height) / 2); + else + return 0; + } // catalina and older - return (nfloat)Math.Max(0, Math.Ceiling((AttributedTitle.Size.Height - defaultHeight) / 2 - 1)) + Offset; + return (nfloat)Math.Max(0, Math.Ceiling((titleSize.Height - defaultHeight) / 2 - 1)) + Offset; } diff --git a/test/Eto.Test/Sections/Controls/CheckBoxSection.cs b/test/Eto.Test/Sections/Controls/CheckBoxSection.cs index b26092be79..09e6ed80e6 100644 --- a/test/Eto.Test/Sections/Controls/CheckBoxSection.cs +++ b/test/Eto.Test/Sections/Controls/CheckBoxSection.cs @@ -25,6 +25,13 @@ public CheckBoxSection() layout.AddSeparateRow(new CheckBox { Text = "Should be aligned with text" }, new Panel { Size = new Size(50, 50), BackgroundColor = Colors.Green }); + layout.AddSeparateRow(new CheckBox(), new Panel + { + Size = new Size(50, 50), + BackgroundColor = Colors.Green, + Content = new Label { VerticalAlignment = VerticalAlignment.Center, Text = "Should be aligned with text" } + }); + layout.Add(null, false, true);