KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <widgets/ui_common.h>
22
23#include <wx/button.h>
24#include <wx/sizer.h>
25
26
27BUTTON_ROW_PANEL::BUTTON_ROW_PANEL( wxWindow* aWindow, const BTN_DEF_LIST& aLeftBtns,
28 const BTN_DEF_LIST& aRightBtns ) :
29 wxPanel( aWindow, wxID_ANY )
30{
31 m_sizer = new wxBoxSizer( wxHORIZONTAL );
32
33 addButtons( true, aLeftBtns );
34
35 // add the spacer
36 m_sizer->Add( 0, 0, 1, wxEXPAND, KIUI::GetStdMargin() );
37
38 addButtons( false, aRightBtns );
39
40 SetSizer( m_sizer );
41 Layout();
42}
43
44
45void BUTTON_ROW_PANEL::addButtons( bool aLeft, const BTN_DEF_LIST& aDefs )
46{
47 // No button expands to fill horizontally
48 const int btn_proportion = 0;
49
50 for( size_t i = 0; i < aDefs.size(); ++i )
51 {
52 const auto& def = aDefs[i];
53 wxButton* btn = new wxButton( this, def.m_id, def.m_text );
54
55 int this_style = wxTOP | wxBOTTOM;
56
57 if( ( aLeft && i > 0 ) || ( !aLeft ) )
58 this_style |= wxLEFT;
59
60 if( ( aLeft ) || ( !aLeft && i < aDefs.size() - 1 ) )
61 this_style |= wxRIGHT;
62
63 btn->SetToolTip( def.m_tooltip );
64
65 m_sizer->Add( btn, btn_proportion, this_style, KIUI::GetStdMargin() );
66
67 btn->Bind( wxEVT_COMMAND_BUTTON_CLICKED, def.m_callback );
68 }
69}
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.
KICOMMON_API int GetStdMargin()
Get the standard margin around a widget in the KiCad UI.
Definition ui_common.cpp:49
Functions to provide common constants and other functions to assist in making a consistent UI.