mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 10:13:19 +02:00
Dark mode hacks for SPLIT_BUTTON on OSX.
This commit is contained in:
parent
3fbc6ac29a
commit
064e7f0f2c
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (C) 2016 Anil8735(https://stackoverflow.com/users/3659387/anil8753)
|
* Copyright (C) 2016 Anil8735(https://stackoverflow.com/users/3659387/anil8753)
|
||||||
* from https://stackoverflow.com/a/37274011
|
* from https://stackoverflow.com/a/37274011
|
||||||
* Copyright (C) 2020-2021 Kicad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 2020-2022 Kicad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
@ -29,16 +29,14 @@
|
|||||||
#include <wx/dcmemory.h>
|
#include <wx/dcmemory.h>
|
||||||
#include <wx/menu.h>
|
#include <wx/menu.h>
|
||||||
#include <wx/renderer.h>
|
#include <wx/renderer.h>
|
||||||
|
#include <wx/settings.h>
|
||||||
|
#include <kiplatform/ui.h>
|
||||||
|
|
||||||
SPLIT_BUTTON::SPLIT_BUTTON( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
|
SPLIT_BUTTON::SPLIT_BUTTON( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
|
||||||
const wxPoint& aPos, const wxSize& aSize ) :
|
const wxPoint& aPos, const wxSize& aSize ) :
|
||||||
wxPanel( aParent, aId, aPos, aSize, wxBORDER_NONE | wxTAB_TRAVERSAL, "DropDownButton" ),
|
wxPanel( aParent, aId, aPos, aSize, wxBORDER_NONE | wxTAB_TRAVERSAL, "DropDownButton" ),
|
||||||
m_label( aLabel )
|
m_label( aLabel )
|
||||||
{
|
{
|
||||||
m_colorNormal = GetForegroundColour();
|
|
||||||
m_colorDisabled = GetForegroundColour().MakeDisabled();
|
|
||||||
|
|
||||||
if( aSize == wxDefaultSize )
|
if( aSize == wxDefaultSize )
|
||||||
{
|
{
|
||||||
wxSize defaultSize = wxButton::GetDefaultSize();
|
wxSize defaultSize = wxButton::GetDefaultSize();
|
||||||
@ -54,6 +52,9 @@ SPLIT_BUTTON::SPLIT_BUTTON( wxWindow* aParent, wxWindowID aId, const wxString& a
|
|||||||
Bind( wxEVT_LEAVE_WINDOW, &SPLIT_BUTTON::OnMouseLeave, this );
|
Bind( wxEVT_LEAVE_WINDOW, &SPLIT_BUTTON::OnMouseLeave, this );
|
||||||
Bind( wxEVT_ENTER_WINDOW, &SPLIT_BUTTON::OnMouseEnter, this );
|
Bind( wxEVT_ENTER_WINDOW, &SPLIT_BUTTON::OnMouseEnter, this );
|
||||||
|
|
||||||
|
Bind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( SPLIT_BUTTON::onThemeChanged ),
|
||||||
|
this );
|
||||||
|
|
||||||
m_pMenu = new wxMenu();
|
m_pMenu = new wxMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +66,12 @@ SPLIT_BUTTON::~SPLIT_BUTTON()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SPLIT_BUTTON::onThemeChanged( wxSysColourChangedEvent &aEvent )
|
||||||
|
{
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SPLIT_BUTTON::SetMinSize( const wxSize& aSize )
|
void SPLIT_BUTTON::SetMinSize( const wxSize& aSize )
|
||||||
{
|
{
|
||||||
m_unadjustedMinSize = aSize;
|
m_unadjustedMinSize = aSize;
|
||||||
@ -202,6 +209,37 @@ void SPLIT_BUTTON::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
|
|||||||
wxSize size = GetSize();
|
wxSize size = GetSize();
|
||||||
const int width = size.GetWidth() - m_arrowButtonWidth;
|
const int width = size.GetWidth() - m_arrowButtonWidth;
|
||||||
|
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
auto drawBackground =
|
||||||
|
[&]( wxRect aRect )
|
||||||
|
{
|
||||||
|
// wxWidgets doesn't have much support for dark mode on OSX; none of the
|
||||||
|
// system colours return the right values, nor does wxRendererNative draw
|
||||||
|
// the borders correctly. So we add some empirically chosen hacks here.
|
||||||
|
|
||||||
|
wxColor bg = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE );
|
||||||
|
|
||||||
|
if( KIPLATFORM::UI::IsDarkTheme() )
|
||||||
|
{
|
||||||
|
aRect.width += 1;
|
||||||
|
aRect.height += 1;
|
||||||
|
bg = bg.ChangeLightness( m_bIsEnable ? 130 : 120 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aRect.x += 1;
|
||||||
|
aRect.y += 1;
|
||||||
|
aRect.width -= 1;
|
||||||
|
aRect.height -= 1;
|
||||||
|
bg = bg.ChangeLightness( m_bIsEnable ? 200 : 160 );
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.SetBrush( bg );
|
||||||
|
dc.SetPen( bg );
|
||||||
|
dc.DrawRectangle( aRect );
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
// Draw first part of button
|
// Draw first part of button
|
||||||
wxRect r1;
|
wxRect r1;
|
||||||
r1.x = 0;
|
r1.x = 0;
|
||||||
@ -211,7 +249,13 @@ void SPLIT_BUTTON::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
|
|||||||
|
|
||||||
wxRendererNative::Get().DrawPushButton( this, dc, r1, m_stateButton );
|
wxRendererNative::Get().DrawPushButton( this, dc, r1, m_stateButton );
|
||||||
|
|
||||||
SetForegroundColour( m_bIsEnable ? m_colorNormal : m_colorDisabled );
|
#ifdef __WXMAC__
|
||||||
|
// wxRendereNative doesn't handle dark mode on OSX. Repaint the background.
|
||||||
|
drawBackground( r1 );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SetForegroundColour( m_bIsEnable ? wxSystemSettings::GetColour( wxSYS_COLOUR_BTNTEXT )
|
||||||
|
: wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
||||||
|
|
||||||
if( m_bitmap.IsOk() )
|
if( m_bitmap.IsOk() )
|
||||||
{
|
{
|
||||||
@ -240,6 +284,12 @@ void SPLIT_BUTTON::OnPaint( wxPaintEvent& WXUNUSED( aEvent ) )
|
|||||||
r2.height = size.GetHeight();
|
r2.height = size.GetHeight();
|
||||||
|
|
||||||
wxRendererNative::Get().DrawPushButton( this, dc, r2, m_stateMenu );
|
wxRendererNative::Get().DrawPushButton( this, dc, r2, m_stateMenu );
|
||||||
|
|
||||||
|
#ifdef __WXMAC__
|
||||||
|
// wxRendereNative doesn't handle dark mode on OSX. Repaint the background.
|
||||||
|
drawBackground( r2 );
|
||||||
|
#endif
|
||||||
|
|
||||||
wxRendererNative::Get().DrawDropArrow( this, dc, r2, m_stateMenu );
|
wxRendererNative::Get().DrawDropArrow( this, dc, r2, m_stateMenu );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ protected:
|
|||||||
void OnLeftButtonUp( wxMouseEvent& aEvent );
|
void OnLeftButtonUp( wxMouseEvent& aEvent );
|
||||||
void OnLeftButtonDown( wxMouseEvent& aEvent );
|
void OnLeftButtonDown( wxMouseEvent& aEvent );
|
||||||
void OnPaint( wxPaintEvent& WXUNUSED( aEvent ) );
|
void OnPaint( wxPaintEvent& WXUNUSED( aEvent ) );
|
||||||
|
void onThemeChanged( wxSysColourChangedEvent &aEvent );
|
||||||
|
|
||||||
bool Enable( bool aEnable = true ) override;
|
bool Enable( bool aEnable = true ) override;
|
||||||
|
|
||||||
@ -59,8 +60,6 @@ private:
|
|||||||
int m_stateButton = 0;
|
int m_stateButton = 0;
|
||||||
int m_stateMenu = 0;
|
int m_stateMenu = 0;
|
||||||
bool m_bIsEnable = true;
|
bool m_bIsEnable = true;
|
||||||
wxColor m_colorNormal;
|
|
||||||
wxColor m_colorDisabled;
|
|
||||||
const int m_arrowButtonWidth = 20;
|
const int m_arrowButtonWidth = 20;
|
||||||
int m_widthPadding = 20;
|
int m_widthPadding = 20;
|
||||||
bool m_bLButtonDown = false;
|
bool m_bLButtonDown = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user