KiCad PCB EDA Suite
button_row_panel.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 1992-2021 Kicad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <widgets/ui_common.h>
26
27#include <wx/button.h>
28#include <wx/sizer.h>
29
30
32 const BTN_DEF_LIST& aLeftBtns,
33 const BTN_DEF_LIST& aRightBtns ):
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 SetSizer( m_sizer );
46 Layout();
47}
48
49
50void BUTTON_ROW_PANEL::addButtons( bool aLeft, const BTN_DEF_LIST& aDefs )
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}
wxBoxSizer * m_sizer
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.
void addButtons(bool aLeft, const BTN_DEF_LIST &aDefs)
Add a set of buttons to one side of the panel.
std::vector< BTN_DEF > BTN_DEF_LIST
A list of BTN_DEFs, used to group buttons into the left/right groups.
int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition: ui_common.cpp:41
Functions to provide common constants and other functions to assist in making a consistent UI.