TGUI 1.13
Loading...
Searching...
No Matches
CustomWidgetForBindings.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_CUSTOM_WIDGET_FOR_BINDINGS_HPP
26#define TGUI_CUSTOM_WIDGET_FOR_BINDINGS_HPP
27
28#ifndef TGUI_REMOVE_DEPRECATED_CODE
29
30 #include <TGUI/Widget.hpp>
31
33
34namespace tgui
35{
41 class TGUI_API CustomWidgetForBindings : public Widget
42 {
43 public:
44 using Ptr = std::shared_ptr<CustomWidgetForBindings>;
45 using ConstPtr = std::shared_ptr<const CustomWidgetForBindings>;
46
47 static constexpr char StaticWidgetType[] = "CustomWidget";
48
56 explicit CustomWidgetForBindings(const char* typeName = StaticWidgetType, bool initRenderer = true);
57
62 [[nodiscard]] static CustomWidgetForBindings::Ptr create();
63
87 void setPosition(const Layout2d& position) override;
88
106 void setSize(const Layout2d& size) override;
107
116 [[nodiscard]] Vector2f getFullSize() const override;
117
125 [[nodiscard]] Vector2f getWidgetOffset() const override;
126
134 void setVisible(bool visible) override;
135
143 void setEnabled(bool enabled) override;
144
153 void setFocused(bool focused) override;
154
159 [[nodiscard]] bool canGainFocus() const override;
160
165 bool updateTime(Duration elapsedTime) override;
166
171 [[nodiscard]] bool isMouseOnWidget(Vector2f pos) const override;
172
176 bool leftMousePressed(Vector2f pos) override;
177
181 void leftMouseReleased(Vector2f pos) override;
182
186 void rightMousePressed(Vector2f pos) override;
187
191 void rightMouseReleased(Vector2f pos) override;
192
196 void mouseMoved(Vector2f pos) override;
197
201 void keyPressed(const Event::KeyEvent& event) override;
202
206 void textEntered(char32_t key) override;
207
212 bool scrolled(float delta, Vector2f pos, bool touch) override;
213
217 void mouseNoLongerOnWidget() override;
218
222 void leftMouseButtonNoLongerDown() override;
223
229 void draw(BackendRenderTarget& target, RenderStates states) const override;
230
241 [[nodiscard]] Widget::Ptr clone() const override;
242
244
245 protected:
251 void rendererChanged(const String& property) override;
252
256 void mouseEnteredWidget() override;
257
261 void mouseLeftWidget() override;
262
263 public:
264 std::function<void(Vector2f)> implPositionChanged;
265 std::function<void(Vector2f)> implSizeChanged;
266 std::function<void(bool)> implVisibleChanged;
267 std::function<void(bool)> implEnableChanged;
268 std::function<void(bool)> implFocusChanged;
269 std::function<bool()> implCanGainFocus;
270 std::function<Vector2f()> implGetFullSize;
271 std::function<Vector2f()> implGetWidgetOffset;
272 std::function<bool(Duration)> implUpdateTimeFunction;
273 std::function<bool(Vector2f)> implMouseOnWidget;
274 std::function<bool(Vector2f)> implLeftMousePressed;
275 std::function<void(Vector2f)> implLeftMouseReleased;
276 std::function<void(Vector2f)> implRightMousePressed;
277 std::function<void(Vector2f)> implRightMouseReleased;
278 std::function<void(Vector2f)> implMouseMoved;
279 std::function<void(const Event::KeyEvent&)> implKeyPressed;
280 std::function<void(char32_t)> implTextEntered;
281 std::function<bool(float, Vector2f, bool)> implScrolled;
282 std::function<void()> implMouseNoLongerOnWidget;
283 std::function<void()> implLeftMouseButtonNoLongerDown;
284 std::function<void()> implMouseEnteredWidget;
285 std::function<void()> implMouseLeftWidget;
286 std::function<bool(const String&)> implRendererChanged;
287 std::function<void(BackendRenderTarget&, RenderStates)> implDrawFunction;
288 };
289} // namespace tgui
290
291#endif // TGUI_REMOVE_DEPRECATED_CODE
292
293#endif // TGUI_WIDGET_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void setPosition(const Layout2d &position) override
sets the position of the widget
void setEnabled(bool enabled) override
Enables or disables the widget.
void setSize(const Layout2d &size) override
Changes the size of the widget.
std::shared_ptr< const CustomWidgetForBindings > ConstPtr
Shared constant widget pointer.
Definition CustomWidgetForBindings.hpp:45
std::shared_ptr< CustomWidgetForBindings > Ptr
Shared widget pointer.
Definition CustomWidgetForBindings.hpp:44
void setFocused(bool focused) override
Focus or unfocus the widget.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition CustomWidgetForBindings.hpp:47
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
bool scrolled(float delta, Vector2f pos, bool touch) override
Called by the parent on scroll event (either from mouse wheel of from two finger scrolling on a touch...
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
void setVisible(bool visible) override
Shows or hides a widget.
Vector2f getFullSize() const override
Returns the entire size that the widget is using.
bool canGainFocus() const override
Returns whether the widget can gain focus.
static CustomWidgetForBindings::Ptr create()
Creates a new widget.
Wrapper for durations.
Definition Duration.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:320
Wrapper class to store strings.
Definition String.hpp:94
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
KeyPressed event parameters.
Definition Event.hpp:166
States used for drawing.
Definition RenderStates.hpp:38