TGUI  0.9.1
ToggleButton.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2021 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_TOGGLE_BUTTON_HPP
27 #define TGUI_TOGGLE_BUTTON_HPP
28 
29 
30 #include <TGUI/Widgets/ButtonBase.hpp>
31 
33 
34 namespace tgui
35 {
39  class TGUI_API ToggleButton : public ButtonBase
40  {
41  public:
42 
43  typedef std::shared_ptr<ToggleButton> Ptr;
44  typedef std::shared_ptr<const ToggleButton> ConstPtr;
45 
46 
54  ToggleButton(const char* typeName = "ToggleButton", bool initRenderer = true);
55 
56 
65  static ToggleButton::Ptr create(const String& text = "", bool down = false);
66 
67 
76 
77 
83  void setDown(bool down);
84 
85 
91  bool isDown() const;
92 
93 
97  void leftMouseReleased(Vector2f pos) override;
98 
102  void keyPressed(const Event::KeyEvent& event) override;
103 
104 
106  protected:
107 
117  Signal& getSignal(String signalName) override;
118 
119 
121  // Makes a copy of the widget
123  Widget::Ptr clone() const override
124  {
125  return std::make_shared<ToggleButton>(*this);
126  }
127 
128 
130  public:
131 
132  SignalBool onToggle = {"Checked"};
133  };
134 
136 }
137 
139 
140 #endif // TGUI_TOGGLE_BUTTON_HPP
141 
Base class for button widgets.
Definition: ButtonBase.hpp:42
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:74
ToggleButton widget.
Definition: ToggleButton.hpp:40
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ToggleButton.hpp:123
static ToggleButton::Ptr create(const String &text="", bool down=false)
Creates a new toggle button widget.
bool isDown() const
Returns whether the button is in down or up state.
void setDown(bool down)
Sets whether the button is in down or up state.
static ToggleButton::Ptr copy(ToggleButton::ConstPtr button)
Makes a copy of another toggle button.
std::shared_ptr< const ToggleButton > ConstPtr
Shared constant widget pointer.
Definition: ToggleButton.hpp:44
std::shared_ptr< ToggleButton > Ptr
Shared widget pointer.
Definition: ToggleButton.hpp:43
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition: Event.hpp:167