diff --git a/lcl/interfaces/cocoa/cocoabuttons.pas b/lcl/interfaces/cocoa/cocoabuttons.pas index 2cc6c7b680..83109ab67e 100644 --- a/lcl/interfaces/cocoa/cocoabuttons.pas +++ b/lcl/interfaces/cocoa/cocoabuttons.pas @@ -24,7 +24,7 @@ interface uses Types, Classes, SysUtils, Graphics, - MacOSAll, CocoaAll, CocoaPrivate, CocoaCallback; + MacOSAll, CocoaAll, CocoaConst, CocoaPrivate, CocoaCallback; const @@ -120,8 +120,23 @@ type procedure lclClearCallback; override; end; +function adjustButtonSizeIfNecessary( button: NSButton; aSize: NSSize ): NSSize; + implementation +function adjustButtonSizeIfNecessary(button: NSButton; aSize: NSSize): NSSize; +begin + Result:= aSize; + if button.bezelStyle = NSRegularSquareBezelStyle then begin + // if the height of NSButton with NSRegularSquareBezelStyle is too small, + // a strange rectangular color block will be shown in the Button, + // in dark mode. + // FYI: https://github.com/doublecmd/doublecmd/issues/1775 + if Result.Height < BUTTON_MIN_HEIGHT_NSRegularSquareBezelStyle then + Result.Height:= BUTTON_MIN_HEIGHT_NSRegularSquareBezelStyle; + end; +end; + { TCocoaStepper } procedure TCocoaStepper.stepperAction(sender: NSObject); @@ -215,6 +230,8 @@ procedure TCocoaButton.lclSetFrame(const r: TRect); var lBtnHeight, lDiff: Integer; lRoundBtnSize: NSSize; + newFrame: TRect; + size: NSSize; begin // NSTexturedRoundedBezelStyle should be the preferred style, but it has a fixed height! // fittingSize is 10.7+ @@ -231,9 +248,17 @@ begin else setBezelStyle(NSTexturedSquareBezelStyle); } + Size.width:= r.Width; + Size.height:= r.Height; + Size:= adjustButtonSizeIfNecessary( self, Size ); + + newFrame:= r; + newFrame.Width:= Round( Size.width ); + newFrame.Height:= Round( Size.height ); + if (miniHeight<>0) or (smallHeight<>0) then - SetNSControlSize(Self,r.Bottom-r.Top,miniHeight, smallHeight, adjustFontToControlSize); - inherited lclSetFrame(r); + SetNSControlSize(Self,newFrame.Bottom-newFrame.Top,miniHeight, smallHeight, adjustFontToControlSize); + inherited lclSetFrame(newFrame); end; procedure TCocoaButton.lclCheckMixedAllowance; diff --git a/lcl/interfaces/cocoa/cocoaconst.pas b/lcl/interfaces/cocoa/cocoaconst.pas index 1fb4208c42..2711d6c768 100644 --- a/lcl/interfaces/cocoa/cocoaconst.pas +++ b/lcl/interfaces/cocoa/cocoaconst.pas @@ -40,6 +40,12 @@ function NSSTR_EDIT_MENU_COPY: NSSTRING; function NSSTR_EDIT_MENU_PASTE: NSSTRING; function NSSTR_EDIT_MENU_SELECTALL: NSSTRING; +const + // if the height of NSButton with NSRegularSquareBezelStyle is too small, + // a strange rectangular color block will be shown in the Button, + // in dark mode. + BUTTON_MIN_HEIGHT_NSRegularSquareBezelStyle = 26; + implementation const diff --git a/lcl/interfaces/cocoa/cocoawsbuttons.pas b/lcl/interfaces/cocoa/cocoawsbuttons.pas index b57761121f..95bce1f62a 100644 --- a/lcl/interfaces/cocoa/cocoawsbuttons.pas +++ b/lcl/interfaces/cocoa/cocoawsbuttons.pas @@ -98,15 +98,13 @@ begin if not AWinControl.HandleAllocated then Exit; lButtonHandle := TCocoaButton(AWinControl.Handle); - // fittingSize is 10.7+ - if lButtonHandle.respondsToSelector(objcselector('fittingSize')) then - begin - Size := lButtonHandle.fittingSize(); - if lButton.Glyph <> nil then - Size.Height := Max(Size.Height, lButton.Glyph.Height + 6); // This nr is arbitrary - PreferredWidth := Round(Size.Width); - PreferredHeight := Round(Size.Height); - end; + Size := lButtonHandle.fittingSize(); + if lButton.Glyph <> nil then + Size.Height := Max(Size.Height, lButton.Glyph.Height + 6); // This nr is arbitrary + + Size:= adjustButtonSizeIfNecessary( lButtonHandle, Size ); + PreferredWidth := Round(Size.Width); + PreferredHeight := Round(Size.Height); end; {------------------------------------------------------------------------------