Improve wxSpinCtrl sizing and appearance on macOS

Multiple improvements to wxSpinCtrl/wxSpinButton appearance:

- fixes broken rendering on macOS 26 (clipped borders)

- corrects wxSpinButton sizes (note that NSStepper doesn't dynamically
  adjust to the size it is set to, but renders at a constant size)

- adds typically used margin between the stepper and the text field

- removes unreachable code in wxWindowMac::DoGetBestSize
This commit is contained in:
Václav Slavík
2025-09-08 14:17:17 +02:00
parent 40830d3bbd
commit cc0fd2c1da
3 changed files with 21 additions and 12 deletions
+12 -4
View File
@@ -49,11 +49,15 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSpinDoubleEvent, wxNotifyEvent);
// ----------------------------------------------------------------------------
// The margin between the text control and the spin: the value here is the same
// as the margin between the spin button and its "buddy" text control in wxMSW
// so the generic control looks similarly to the native one there, we might
// need to use different value for the other platforms (and maybe even
// determine it dynamically?).
// as the margin between the spin button and its "buddy" text control in wxMSW,
// and the commonly used spacing on macOS, so the generic control looks
// similarly to the native one there, we might need to use different value for
// other platforms (and maybe even determine it dynamically?).
#ifdef __WXOSX__
static const wxCoord MARGIN = 4;
#else
static const wxCoord MARGIN = 1;
#endif
#define SPINCTRLBUT_MAX 32000 // large to avoid wrap around trouble
@@ -241,6 +245,10 @@ bool wxSpinCtrlGenericBase::Create(wxWindow *parent,
m_value = AdjustAndSnap(d);
}
#ifdef __WXOSX__
MacClipsToBounds(false);
#endif
m_textCtrl = new wxSpinCtrlTextGeneric(this, DoValueToText(m_value), style);
m_spinButton = new wxSpinCtrlButtonGeneric(this, style);
+9 -1
View File
@@ -13,6 +13,7 @@
#include "wx/spinbutt.h"
#include "wx/osx/private.h"
#include "wx/osx/private/available.h"
wxSpinButton::wxSpinButton()
@@ -80,7 +81,14 @@ bool wxSpinButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
wxSize wxSpinButton::DoGetBestSize() const
{
return wxSize( 16, 24 );
if ( WX_IS_MACOS_AVAILABLE(26, 0) )
{
return wxSize(21, 28);
}
else
{
return wxSize(13, 22);
}
}
void wxSpinButton::TriggerScrollEvent(wxEventType scrollEvent)
-7
View File
@@ -1061,13 +1061,6 @@ wxSize wxWindowMac::DoGetBestSize() const
r.height = 16 ;
}
else
#endif
#if wxUSE_SPINBTN
if ( IsKindOf( CLASSINFO( wxSpinButton ) ) )
{
r.height = 24 ;
}
else
#endif
{
// return wxWindowBase::DoGetBestSize() ;