mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 13:19:21 +02:00
Cocoa: fix the issue of NSButton with NSRegularSquareBezelStyle
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
This commit is contained in:
parent
8590d1f811
commit
4150057274
@ -24,7 +24,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Types, Classes, SysUtils, Graphics,
|
Types, Classes, SysUtils, Graphics,
|
||||||
MacOSAll, CocoaAll, CocoaPrivate, CocoaCallback;
|
MacOSAll, CocoaAll, CocoaConst, CocoaPrivate, CocoaCallback;
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -120,8 +120,23 @@ type
|
|||||||
procedure lclClearCallback; override;
|
procedure lclClearCallback; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function adjustButtonSizeIfNecessary( button: NSButton; aSize: NSSize ): NSSize;
|
||||||
|
|
||||||
implementation
|
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 }
|
{ TCocoaStepper }
|
||||||
|
|
||||||
procedure TCocoaStepper.stepperAction(sender: NSObject);
|
procedure TCocoaStepper.stepperAction(sender: NSObject);
|
||||||
@ -215,6 +230,8 @@ procedure TCocoaButton.lclSetFrame(const r: TRect);
|
|||||||
var
|
var
|
||||||
lBtnHeight, lDiff: Integer;
|
lBtnHeight, lDiff: Integer;
|
||||||
lRoundBtnSize: NSSize;
|
lRoundBtnSize: NSSize;
|
||||||
|
newFrame: TRect;
|
||||||
|
size: NSSize;
|
||||||
begin
|
begin
|
||||||
// NSTexturedRoundedBezelStyle should be the preferred style, but it has a fixed height!
|
// NSTexturedRoundedBezelStyle should be the preferred style, but it has a fixed height!
|
||||||
// fittingSize is 10.7+
|
// fittingSize is 10.7+
|
||||||
@ -231,9 +248,17 @@ begin
|
|||||||
else
|
else
|
||||||
setBezelStyle(NSTexturedSquareBezelStyle);
|
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
|
if (miniHeight<>0) or (smallHeight<>0) then
|
||||||
SetNSControlSize(Self,r.Bottom-r.Top,miniHeight, smallHeight, adjustFontToControlSize);
|
SetNSControlSize(Self,newFrame.Bottom-newFrame.Top,miniHeight, smallHeight, adjustFontToControlSize);
|
||||||
inherited lclSetFrame(r);
|
inherited lclSetFrame(newFrame);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaButton.lclCheckMixedAllowance;
|
procedure TCocoaButton.lclCheckMixedAllowance;
|
||||||
|
@ -40,6 +40,12 @@ function NSSTR_EDIT_MENU_COPY: NSSTRING;
|
|||||||
function NSSTR_EDIT_MENU_PASTE: NSSTRING;
|
function NSSTR_EDIT_MENU_PASTE: NSSTRING;
|
||||||
function NSSTR_EDIT_MENU_SELECTALL: 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
|
implementation
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -98,15 +98,13 @@ begin
|
|||||||
if not AWinControl.HandleAllocated then Exit;
|
if not AWinControl.HandleAllocated then Exit;
|
||||||
|
|
||||||
lButtonHandle := TCocoaButton(AWinControl.Handle);
|
lButtonHandle := TCocoaButton(AWinControl.Handle);
|
||||||
// fittingSize is 10.7+
|
Size := lButtonHandle.fittingSize();
|
||||||
if lButtonHandle.respondsToSelector(objcselector('fittingSize')) then
|
if lButton.Glyph <> nil then
|
||||||
begin
|
Size.Height := Max(Size.Height, lButton.Glyph.Height + 6); // This nr is arbitrary
|
||||||
Size := lButtonHandle.fittingSize();
|
|
||||||
if lButton.Glyph <> nil then
|
Size:= adjustButtonSizeIfNecessary( lButtonHandle, Size );
|
||||||
Size.Height := Max(Size.Height, lButton.Glyph.Height + 6); // This nr is arbitrary
|
PreferredWidth := Round(Size.Width);
|
||||||
PreferredWidth := Round(Size.Width);
|
PreferredHeight := Round(Size.Height);
|
||||||
PreferredHeight := Round(Size.Height);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user