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.

106 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2018 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. #ifndef SIMPLE_BUTTON_PANEL_H
  24. #define SIMPLE_BUTTON_PANEL_H
  25. #include "wx/panel.h"
  26. #include <vector>
  27. #include <functional>
  28. // Forward defs for private-only classes
  29. class wxBoxSizer;
  30. /**
  31. * A panel that contains buttons, arranged on the left and/or right sides.
  32. */
  33. class BUTTON_ROW_PANEL: public wxPanel
  34. {
  35. public:
  36. /**
  37. * Callback function definition. A callback of this type can be registered
  38. * to handle the button click event.
  39. */
  40. using BTN_CALLBACK = std::function< void( wxCommandEvent& ) >;
  41. /**
  42. * The information needed to instantiate a button on a BUTTON_ROW_PANEL.
  43. */
  44. struct BTN_DEF
  45. {
  46. /**
  47. * The button ID. Can be wxID_ANY, but should be unique if you
  48. * want to work out which button this was from an event handler.
  49. */
  50. wxWindowID m_id;
  51. /**
  52. * The button display text.
  53. */
  54. wxString m_text;
  55. /**
  56. * Button tooltip text - empty string for no tooltip
  57. */
  58. wxString m_tooltip;
  59. /**
  60. * The callback fired when the button is clicked. Can be nullptr,
  61. * but then the button is useless.
  62. */
  63. BTN_CALLBACK m_callback;
  64. };
  65. /**
  66. * A list of BTN_DEFs, used to group buttons into the left/right groups.
  67. */
  68. using BTN_DEF_LIST = std::vector<BTN_DEF>;
  69. /**
  70. * Construct a SIMPLE_BUTTON_PANEL with a set of buttons on each side.
  71. *
  72. * @param aLeftBtns: buttons on the left side, from left to right
  73. * @param aRightBtns: buttons on the right side, from left to right
  74. */
  75. BUTTON_ROW_PANEL( wxWindow* aWindow,
  76. const BTN_DEF_LIST& aLeftBtns,
  77. const BTN_DEF_LIST& aRightBtns );
  78. private:
  79. /**
  80. * Add a set of buttons to one side of the panel.
  81. *
  82. * @param aSizer the sizer to add them to
  83. * @param aLeft place on the left (false for right)
  84. * @param aDefs list of button defs, from left to right
  85. */
  86. void addButtons( bool aLeft, const BTN_DEF_LIST& aDefs );
  87. wxBoxSizer* m_sizer;
  88. };
  89. #endif // SIMPLE_BUTTON_PANEL_H