KiCad PCB EDA Suite
BUTTON_ROW_PANEL Class Reference

A panel that contains buttons, arranged on the left and/or right sides. More...

#include <button_row_panel.h>

Inheritance diagram for BUTTON_ROW_PANEL:

Classes

struct  BTN_DEF
 The information needed to instantiate a button on a BUTTON_ROW_PANEL. More...
 

Public Types

using BTN_CALLBACK = std::function< void(wxCommandEvent &) >
 Callback function definition. More...
 
using BTN_DEF_LIST = std::vector< BTN_DEF >
 A list of BTN_DEFs, used to group buttons into the left/right groups. More...
 

Public Member Functions

 BUTTON_ROW_PANEL (wxWindow *aWindow, const BTN_DEF_LIST &aLeftBtns, const BTN_DEF_LIST &aRightBtns)
 Construct a SIMPLE_BUTTON_PANEL with a set of buttons on each side. More...
 

Private Member Functions

void addButtons (bool aLeft, const BTN_DEF_LIST &aDefs)
 Add a set of buttons to one side of the panel. More...
 

Private Attributes

wxBoxSizer * m_sizer
 

Detailed Description

A panel that contains buttons, arranged on the left and/or right sides.

Definition at line 40 of file button_row_panel.h.

Member Typedef Documentation

using BUTTON_ROW_PANEL::BTN_CALLBACK = std::function< void( wxCommandEvent& ) >

Callback function definition.

A callback of this type can be registered to handle the button click event.

Definition at line 48 of file button_row_panel.h.

A list of BTN_DEFs, used to group buttons into the left/right groups.

Definition at line 81 of file button_row_panel.h.

Constructor & Destructor Documentation

BUTTON_ROW_PANEL::BUTTON_ROW_PANEL ( wxWindow *  aWindow,
const BTN_DEF_LIST aLeftBtns,
const BTN_DEF_LIST aRightBtns 
)

Construct a SIMPLE_BUTTON_PANEL with a set of buttons on each side.

Parameters
aLeftBtnsbuttons on the left side, from left to right
aRightBtnsbuttons on the right side, from left to right

Definition at line 31 of file button_row_panel.cpp.

References addButtons(), KIUI::GetStdMargin(), and m_sizer.

33  :
34  wxPanel( aWindow, wxID_ANY )
35 {
36  m_sizer = new wxBoxSizer( wxHORIZONTAL );
37 
38  addButtons( true, aLeftBtns );
39 
40  // add the spacer
41  m_sizer->Add( 0, 0, 1, wxEXPAND, KIUI::GetStdMargin() );
42 
43  addButtons( false, aRightBtns );
44 
45  this->SetSizer( m_sizer );
46  this->Layout();
47 }
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:23
wxBoxSizer * m_sizer
void addButtons(bool aLeft, const BTN_DEF_LIST &aDefs)
Add a set of buttons to one side of the panel.

Member Function Documentation

void BUTTON_ROW_PANEL::addButtons ( bool  aLeft,
const BTN_DEF_LIST aDefs 
)
private

Add a set of buttons to one side of the panel.

Parameters
aSizerthe sizer to add them to
aLeftplace on the left (false for right)
aDefslist of button defs, from left to right

Definition at line 50 of file button_row_panel.cpp.

References KIUI::GetStdMargin(), i, and m_sizer.

Referenced by BUTTON_ROW_PANEL().

51 {
52  const int btn_margin = KIUI::GetStdMargin();
53  // No button expands to fill horizontally
54  const int btn_proportion = 0;
55 
56  for( size_t i = 0; i < aDefs.size(); ++i )
57  {
58  const auto& def = aDefs[i];
59  wxButton* btn = new wxButton( this, def.m_id, def.m_text );
60 
61  // Buttons expand to fill the size vertically
62  long this_style = wxEXPAND;
63 
64  if( ( aLeft && i > 0 ) || ( !aLeft ) )
65  this_style |= wxLEFT;
66 
67  if( ( aLeft ) || ( !aLeft && i < aDefs.size() - 1 ) )
68  this_style |= wxRIGHT;
69 
70  btn->SetToolTip( def.m_tooltip );
71 
72  m_sizer->Add( btn, btn_proportion, this_style, btn_margin );
73 
74  btn->Bind( wxEVT_COMMAND_BUTTON_CLICKED, def.m_callback );
75  }
76 }
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:23
wxBoxSizer * m_sizer
size_t i
Definition: json11.cpp:597

Member Data Documentation

wxBoxSizer* BUTTON_ROW_PANEL::m_sizer
private

Definition at line 104 of file button_row_panel.h.

Referenced by addButtons(), and BUTTON_ROW_PANEL().


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