KiCad PCB EDA Suite
BITMAP_TOGGLE Class Reference

A checkbox control except with custom bitmaps for the checked and unchecked states. More...

#include <bitmap_toggle.h>

Inheritance diagram for BITMAP_TOGGLE:

Public Member Functions

 BITMAP_TOGGLE ()
 
 BITMAP_TOGGLE (wxWindow *aParent, wxWindowID aId, const wxBitmap &aCheckedBitmap, const wxBitmap &aUncheckedBitmap, bool aChecked=false)
 
void SetValue (bool aValue)
 

Set the checkbox state

More...
 
bool GetValue () const
 

Read the checkbox state

More...
 

Private Attributes

bool m_checked
 
wxStaticBitmap * m_bitmap
 
wxBitmap m_unchecked_bitmap
 

Bitmap to display in unchecked state

More...
 
wxBitmap m_checked_bitmap
 

Bitmap to display in checked state

More...
 

Detailed Description

A checkbox control except with custom bitmaps for the checked and unchecked states.

This is useful in space-constrained situations where native toggle button controls are too big

Definition at line 41 of file bitmap_toggle.h.

Constructor & Destructor Documentation

◆ BITMAP_TOGGLE() [1/2]

BITMAP_TOGGLE::BITMAP_TOGGLE ( )
inline

Definition at line 44 of file bitmap_toggle.h.

44 {}

◆ BITMAP_TOGGLE() [2/2]

BITMAP_TOGGLE::BITMAP_TOGGLE ( wxWindow *  aParent,
wxWindowID  aId,
const wxBitmap &  aCheckedBitmap,
const wxBitmap &  aUncheckedBitmap,
bool  aChecked = false 
)

Definition at line 31 of file bitmap_toggle.cpp.

32  :
33  wxPanel( aParent, aId ),
34  m_checked( aChecked ),
35  m_unchecked_bitmap( aUncheckedBitmap ),
36  m_checked_bitmap( aCheckedBitmap )
37 {
38  wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
39  SetSizer( sizer );
40 
41  const wxBitmap& bitmap = aChecked ? m_checked_bitmap : m_unchecked_bitmap;
42 
43  m_bitmap = new wxStaticBitmap( this, aId, bitmap, wxDefaultPosition, bitmap.GetSize() );
44 
45  sizer->Add( m_bitmap, 0, 0 );
46 
47  m_bitmap->Bind( wxEVT_LEFT_UP,
48  [&]( wxMouseEvent& )
49  {
50  SetValue( !GetValue() );
51  wxCommandEvent event( TOGGLE_CHANGED );
52  event.SetInt( m_checked );
53  event.SetEventObject( this );
54  wxPostEvent( this, event );
55  } );
56 
57  auto passOnEvent =
58  [&]( wxEvent& aEvent )
59  {
60  wxPostEvent( this, aEvent );
61  };
62 
63  m_bitmap->Bind( wxEVT_RIGHT_DOWN, passOnEvent );
64  m_bitmap->Bind( wxEVT_RIGHT_UP, passOnEvent );
65 }
void SetValue(bool aValue)
Set the checkbox state
wxStaticBitmap * m_bitmap
Definition: bitmap_toggle.h:58
wxBitmap m_checked_bitmap
Bitmap to display in checked state
Definition: bitmap_toggle.h:64
wxBitmap m_unchecked_bitmap
Bitmap to display in unchecked state
Definition: bitmap_toggle.h:61
bool GetValue() const
Read the checkbox state
Definition: bitmap_toggle.h:53

References GetValue(), m_bitmap, m_checked, m_checked_bitmap, m_unchecked_bitmap, and SetValue().

Member Function Documentation

◆ GetValue()

bool BITMAP_TOGGLE::GetValue ( ) const
inline

Read the checkbox state

Definition at line 53 of file bitmap_toggle.h.

53 { return m_checked; }

References m_checked.

Referenced by BITMAP_TOGGLE().

◆ SetValue()

void BITMAP_TOGGLE::SetValue ( bool  aValue)

Set the checkbox state

Definition at line 68 of file bitmap_toggle.cpp.

69 {
70  m_checked = aValue;
71  m_bitmap->SetBitmap( aValue ? m_checked_bitmap : m_unchecked_bitmap );
72 }
wxStaticBitmap * m_bitmap
Definition: bitmap_toggle.h:58
wxBitmap m_checked_bitmap
Bitmap to display in checked state
Definition: bitmap_toggle.h:64
wxBitmap m_unchecked_bitmap
Bitmap to display in unchecked state
Definition: bitmap_toggle.h:61

References m_bitmap, m_checked, m_checked_bitmap, and m_unchecked_bitmap.

Referenced by BITMAP_TOGGLE(), and APPEARANCE_CONTROLS::SetObjectVisible().

Member Data Documentation

◆ m_bitmap

wxStaticBitmap* BITMAP_TOGGLE::m_bitmap
private

Definition at line 58 of file bitmap_toggle.h.

Referenced by BITMAP_TOGGLE(), and SetValue().

◆ m_checked

bool BITMAP_TOGGLE::m_checked
private

Definition at line 56 of file bitmap_toggle.h.

Referenced by BITMAP_TOGGLE(), GetValue(), and SetValue().

◆ m_checked_bitmap

wxBitmap BITMAP_TOGGLE::m_checked_bitmap
private

Bitmap to display in checked state

Definition at line 64 of file bitmap_toggle.h.

Referenced by BITMAP_TOGGLE(), and SetValue().

◆ m_unchecked_bitmap

wxBitmap BITMAP_TOGGLE::m_unchecked_bitmap
private

Bitmap to display in unchecked state

Definition at line 61 of file bitmap_toggle.h.

Referenced by BITMAP_TOGGLE(), and SetValue().


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