You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.4 KiB

  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. #include <widgets/button_row_panel.h>
  24. #include <widgets/ui_common.h>
  25. #include <wx/button.h>
  26. #include <wx/sizer.h>
  27. BUTTON_ROW_PANEL::BUTTON_ROW_PANEL( wxWindow* aWindow,
  28. const BTN_DEF_LIST& aLeftBtns,
  29. const BTN_DEF_LIST& aRightBtns ):
  30. wxPanel( aWindow, wxID_ANY )
  31. {
  32. m_sizer = new wxBoxSizer( wxHORIZONTAL );
  33. addButtons( true, aLeftBtns );
  34. // add the spacer
  35. m_sizer->Add( 0, 0, 1, wxEXPAND, KIUI::GetStdMargin() );
  36. addButtons( false, aRightBtns );
  37. SetSizer( m_sizer );
  38. Layout();
  39. }
  40. void BUTTON_ROW_PANEL::addButtons( bool aLeft, const BTN_DEF_LIST& aDefs )
  41. {
  42. const int btn_margin = KIUI::GetStdMargin();
  43. // No button expands to fill horizontally
  44. const int btn_proportion = 0;
  45. for( size_t i = 0; i < aDefs.size(); ++i )
  46. {
  47. const auto& def = aDefs[i];
  48. wxButton* btn = new wxButton( this, def.m_id, def.m_text );
  49. // Buttons expand to fill the size vertically
  50. long this_style = wxEXPAND;
  51. if( ( aLeft && i > 0 ) || ( !aLeft ) )
  52. this_style |= wxLEFT;
  53. if( ( aLeft ) || ( !aLeft && i < aDefs.size() - 1 ) )
  54. this_style |= wxRIGHT;
  55. btn->SetToolTip( def.m_tooltip );
  56. m_sizer->Add( btn, btn_proportion, this_style, btn_margin );
  57. btn->Bind( wxEVT_COMMAND_BUTTON_CLICKED, def.m_callback );
  58. }
  59. }