TGUI 1.13
Loading...
Searching...
No Matches
ToggleButton.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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#ifndef TGUI_TOGGLE_BUTTON_HPP
26#define TGUI_TOGGLE_BUTTON_HPP
27
28#include <TGUI/Widgets/ButtonBase.hpp>
29
31
32namespace tgui
33{
37 class TGUI_API ToggleButton : public ButtonBase
38 {
39 public:
40 using Ptr = std::shared_ptr<ToggleButton>;
41 using ConstPtr = std::shared_ptr<const ToggleButton>;
42
43 static constexpr char StaticWidgetType[] = "ToggleButton";
44
52 explicit ToggleButton(const char* typeName = StaticWidgetType, bool initRenderer = true);
53
62 [[nodiscard]] static ToggleButton::Ptr create(const String& text = "", bool down = false);
63
71 [[nodiscard]] static ToggleButton::Ptr copy(const ToggleButton::ConstPtr& button);
72
78 void setDown(bool down);
79
85 [[nodiscard]] bool isDown() const;
86
90 void leftMouseReleased(Vector2f pos) override;
91
95 void keyPressed(const Event::KeyEvent& event) override;
96
106 bool canHandleKeyPress(const Event::KeyEvent& event) override;
107
109
110 protected:
120 [[nodiscard]] Signal& getSignal(String signalName) override;
121
125 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
126
130 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
131
133 // Makes a copy of the widget
135 [[nodiscard]] Widget::Ptr clone() const override;
136
138
139 public:
140 SignalBool onToggle = {"Toggled"};
141 };
142} // namespace tgui
143
144#endif // TGUI_TOGGLE_BUTTON_HPP
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
static ToggleButton::Ptr create(const String &text="", bool down=false)
Creates a new toggle button widget.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition ToggleButton.hpp:43
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
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.
SignalBool onToggle
Button state was toggled. Optional parameter: bool containing whether the button is down or not.
Definition ToggleButton.hpp:140
std::shared_ptr< const ToggleButton > ConstPtr
Shared constant widget pointer.
Definition ToggleButton.hpp:41
std::shared_ptr< ToggleButton > Ptr
Shared widget pointer.
Definition ToggleButton.hpp:40
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
static ToggleButton::Ptr copy(const ToggleButton::ConstPtr &button)
Makes a copy of another toggle button.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
SignalTyped< bool > SignalBool
Signal with one "bool" as optional unbound parameter.
Definition Signal.hpp:410
KeyPressed event parameters.
Definition Event.hpp:166