TGUI  1.3-dev
Loading...
Searching...
No Matches
Button.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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_BUTTON_HPP
27#define TGUI_BUTTON_HPP
28
29#include <TGUI/Widgets/ButtonBase.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
38 class TGUI_API Button : public ButtonBase
39 {
40 public:
41
42 using Ptr = std::shared_ptr<Button>;
43 using ConstPtr = std::shared_ptr<const Button>;
44
45 static constexpr const char StaticWidgetType[] = "Button";
46
47
55 Button(const char* typeName = StaticWidgetType, bool initRenderer = true);
56
57
66 TGUI_NODISCARD static Button::Ptr create(const String& text = "");
67
68
77 TGUI_NODISCARD static Button::Ptr copy(const Button::ConstPtr& button);
78
79
83 bool leftMousePressed(Vector2f pos) override;
84
88 void leftMouseReleased(Vector2f pos) override;
89
93 void leftMouseButtonNoLongerDown() override;
94
98 void keyPressed(const Event::KeyEvent& event) override;
99
109 bool canHandleKeyPress(const Event::KeyEvent& event) override;
110
111
113 protected:
114
116 // This function is called when the mouse enters the widget. If requested, a callback will be send.
118 void mouseEnteredWidget() override;
119
120
122 // This function is called when the mouse leaves the widget. If requested, a callback will be send.
124 void mouseLeftWidget() override;
125
126
136 TGUI_NODISCARD Signal& getSignal(String signalName) override;
137
138
140 // Makes a copy of the widget
142 TGUI_NODISCARD Widget::Ptr clone() const override;
143
144
146 public:
147
148 SignalString onPress = {"Pressed"};
149 };
150
152}
153
155
156#endif // TGUI_BUTTON_HPP
157
Base class for button widgets.
Definition ButtonBase.hpp:42
Button widget.
Definition Button.hpp:39
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< const Button > ConstPtr
Shared constant widget pointer.
Definition Button.hpp:43
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
static TGUI_NODISCARD Button::Ptr create(const String &text="")
Creates a new button widget.
static TGUI_NODISCARD Button::Ptr copy(const Button::ConstPtr &button)
Makes a copy of another button.
std::shared_ptr< Button > Ptr
Shared widget pointer.
Definition Button.hpp:42
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
KeyPressed event parameters.
Definition Event.hpp:169