KiCad PCB EDA Suite
WX_AUI_TOOLBAR_ART Class Reference

wxWidgets 3.1 has support for dark mode detection, but 3.0 doesn't. More...

#include <wx_aui_art_providers.h>

Inheritance diagram for WX_AUI_TOOLBAR_ART:

Public Member Functions

 WX_AUI_TOOLBAR_ART ()
 
virtual ~WX_AUI_TOOLBAR_ART ()=default
 
void DrawButton (wxDC &aDc, wxWindow *aWindow, const wxAuiToolBarItem &aItem, const wxRect &aRect) override
 The same as wxAuiDefaultToolBarArt::DrawButton except with dark-mode awareness based on BITMAP_BUTTON. More...
 

Detailed Description

wxWidgets 3.1 has support for dark mode detection, but 3.0 doesn't.

The main purpose of this replacement art provider is to backport that functionality so that it is available in Linux systems that will likely be stuck on 3.0 for a while.

Definition at line 31 of file wx_aui_art_providers.h.

Constructor & Destructor Documentation

◆ WX_AUI_TOOLBAR_ART()

WX_AUI_TOOLBAR_ART::WX_AUI_TOOLBAR_ART ( )
inline

Definition at line 34 of file wx_aui_art_providers.h.

34 : wxAuiDefaultToolBarArt() {}

◆ ~WX_AUI_TOOLBAR_ART()

virtual WX_AUI_TOOLBAR_ART::~WX_AUI_TOOLBAR_ART ( )
virtualdefault

Member Function Documentation

◆ DrawButton()

void WX_AUI_TOOLBAR_ART::DrawButton ( wxDC &  aDc,
wxWindow *  aWindow,
const wxAuiToolBarItem &  aItem,
const wxRect &  aRect 
)
override

The same as wxAuiDefaultToolBarArt::DrawButton except with dark-mode awareness based on BITMAP_BUTTON.

Unfortunately, wx 3.0 does not provide any hooks that would make it possible to do this in a way other than just copy/pasting the upstream implementation and modifying it.

Definition at line 30 of file wx_aui_art_providers.cpp.

32 {
33  bool darkMode = KIPLATFORM::UI::IsDarkTheme();
34  int textWidth = 0;
35  int textHeight = 0;
36 
37  if( m_flags & wxAUI_TB_TEXT )
38  {
39  aDc.SetFont( m_font );
40 
41  int tx, ty;
42 
43  aDc.GetTextExtent( wxT( "ABCDHgj" ), &tx, &textHeight );
44  textWidth = 0;
45  aDc.GetTextExtent( aItem.GetLabel(), &textWidth, &ty );
46  }
47 
48  int bmpX = 0, bmpY = 0;
49  int textX = 0, textY = 0;
50 
51  if( m_textOrientation == wxAUI_TBTOOL_TEXT_BOTTOM )
52  {
53  bmpX = aRect.x + ( aRect.width / 2 ) - ( aItem.GetBitmap().GetWidth() / 2 );
54 
55  bmpY = aRect.y + ( ( aRect.height - textHeight ) / 2 ) -
56  ( aItem.GetBitmap().GetHeight() / 2 );
57 
58  textX = aRect.x + ( aRect.width / 2 ) - ( textWidth / 2 ) + 1;
59  textY = aRect.y + aRect.height - textHeight - 1;
60  }
61  else if( m_textOrientation == wxAUI_TBTOOL_TEXT_RIGHT )
62  {
63  bmpX = aRect.x + 3;
64 
65  bmpY = aRect.y + ( aRect.height / 2 ) - ( aItem.GetBitmap().GetHeight() / 2 );
66 
67  textX = bmpX + 3 + aItem.GetBitmap().GetWidth();
68  textY = aRect.y + ( aRect.height / 2 ) - ( textHeight / 2 );
69  }
70 
71  if( !( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED ) )
72  {
73  if( aItem.GetState() & wxAUI_BUTTON_STATE_PRESSED )
74  {
75  aDc.SetPen( wxPen( m_highlightColour ) );
76  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 20 : 150 ) ) );
77  aDc.DrawRectangle( aRect );
78  }
79  else if( ( aItem.GetState() & wxAUI_BUTTON_STATE_HOVER ) || aItem.IsSticky() )
80  {
81  aDc.SetPen( wxPen( m_highlightColour ) );
82  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 40 : 170 ) ) );
83 
84  // draw an even lighter background for checked aItem hovers (since
85  // the hover background is the same color as the check background)
86  if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
87  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 50 : 180 ) ) );
88 
89  aDc.DrawRectangle( aRect );
90  }
91  else if( aItem.GetState() & wxAUI_BUTTON_STATE_CHECKED )
92  {
93  // it's important to put this code in an else statement after the
94  // hover, otherwise hovers won't draw properly for checked aItems
95  aDc.SetPen( wxPen( m_highlightColour ) );
96  aDc.SetBrush( wxBrush( m_highlightColour.ChangeLightness( darkMode ? 40 : 170 ) ) );
97  aDc.DrawRectangle( aRect );
98  }
99  }
100 
101  wxBitmap bmp;
102 
103  if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
104  bmp = aItem.GetDisabledBitmap();
105  else
106  bmp = aItem.GetBitmap();
107 
108  if( bmp.IsOk() )
109  aDc.DrawBitmap( bmp, bmpX, bmpY, true );
110 
111  // set the aItem's text color based on if it is disabled
112  aDc.SetTextForeground( *wxBLACK );
113 
114  if( aItem.GetState() & wxAUI_BUTTON_STATE_DISABLED )
115  aDc.SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
116 
117  if( ( m_flags & wxAUI_TB_TEXT ) && !aItem.GetLabel().empty() )
118  {
119  aDc.DrawText( aItem.GetLabel(), textX, textY );
120  }
121 }
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:31

References KIPLATFORM::UI::IsDarkTheme().


The documentation for this class was generated from the following files: