TGUI  1.3-dev
Loading...
Searching...
No Matches
CustomWidgetForBindings.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_CUSTOM_WIDGET_FOR_BINDINGS_HPP
27#define TGUI_CUSTOM_WIDGET_FOR_BINDINGS_HPP
28
30
31#include <TGUI/Widget.hpp>
32
34
35TGUI_MODULE_EXPORT namespace tgui
36{
42 class TGUI_API CustomWidgetForBindings : public Widget
43 {
44 public:
45
46 using Ptr = std::shared_ptr<CustomWidgetForBindings>;
47 using ConstPtr = std::shared_ptr<const CustomWidgetForBindings>;
48
49 static constexpr const char StaticWidgetType[] = "CustomWidget";
50
51
59 CustomWidgetForBindings(const char* typeName = StaticWidgetType, bool initRenderer = true);
60
61
66 TGUI_NODISCARD static CustomWidgetForBindings::Ptr create();
67
68
92 void setPosition(const Layout2d& position) override;
93
94
112 void setSize(const Layout2d& size) override;
113
114
123 TGUI_NODISCARD Vector2f getFullSize() const override;
124
125
133 TGUI_NODISCARD Vector2f getWidgetOffset() const override;
134
135
143 void setVisible(bool visible) override;
144
145
153 void setEnabled(bool enabled) override;
154
155
164 void setFocused(bool focused) override;
165
166
171 TGUI_NODISCARD bool canGainFocus() const override;
172
173
178 bool updateTime(Duration elapsedTime) override;
179
180
185 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
186
190 bool leftMousePressed(Vector2f pos) override;
191
195 void leftMouseReleased(Vector2f pos) override;
196
200 void rightMousePressed(Vector2f pos) override;
201
205 void rightMouseReleased(Vector2f pos) override;
206
210 void mouseMoved(Vector2f pos) override;
211
215 void keyPressed(const Event::KeyEvent& event) override;
216
220 void textEntered(char32_t key) override;
221
226 bool scrolled(float delta, Vector2f pos, bool touch) override;
227
231 void mouseNoLongerOnWidget() override;
232
236 void leftMouseButtonNoLongerDown() override;
237
238
244 void draw(BackendRenderTarget& target, RenderStates states) const override;
245
246
257 TGUI_NODISCARD Widget::Ptr clone() const override;
258
259
261 protected:
262
268 void rendererChanged(const String& property) override;
269
270
274 void mouseEnteredWidget() override;
275
276
280 void mouseLeftWidget() override;
281
282
283 public:
284
285 std::function<void(Vector2f)> implPositionChanged;
286 std::function<void(Vector2f)> implSizeChanged;
287 std::function<void(bool)> implVisibleChanged;
288 std::function<void(bool)> implEnableChanged;
289 std::function<void(bool)> implFocusChanged;
290 std::function<bool()> implCanGainFocus;
291 std::function<Vector2f()> implGetFullSize;
292 std::function<Vector2f()> implGetWidgetOffset;
293 std::function<bool(Duration)> implUpdateTimeFunction;
294 std::function<bool(Vector2f)> implMouseOnWidget;
295 std::function<bool(Vector2f)> implLeftMousePressed;
296 std::function<void(Vector2f)> implLeftMouseReleased;
297 std::function<void(Vector2f)> implRightMousePressed;
298 std::function<void(Vector2f)> implRightMouseReleased;
299 std::function<void(Vector2f)> implMouseMoved;
300 std::function<void(const Event::KeyEvent&)> implKeyPressed;
301 std::function<void(char32_t)> implTextEntered;
302 std::function<bool(float, Vector2f, bool)> implScrolled;
303 std::function<void()> implMouseNoLongerOnWidget;
304 std::function<void()> implLeftMouseButtonNoLongerDown;
305 std::function<void()> implMouseEnteredWidget;
306 std::function<void()> implMouseLeftWidget;
307 std::function<bool(const String&)> implRendererChanged;
308 std::function<void(BackendRenderTarget&, RenderStates)> implDrawFunction;
309
311 };
312
314}
315
317
318#endif // TGUI_WIDGET_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Class used by bindings to implement custom widgets withing these bindings (e.g. a custom C# widget in...
Definition CustomWidgetForBindings.hpp:43
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies 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.
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:47
std::shared_ptr< CustomWidgetForBindings > Ptr
Shared widget pointer.
Definition CustomWidgetForBindings.hpp:46
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.
TGUI_NODISCARD Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
TGUI_NODISCARD bool canGainFocus() const override
Returns whether the widget can gain focus.
static TGUI_NODISCARD CustomWidgetForBindings::Ptr create()
Creates a new widget.
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.
TGUI_NODISCARD Vector2f getFullSize() const override
Returns the entire size that the widget is using.
Wrapper for durations.
Definition Duration.hpp:56
Class to store the position or size of a widget.
Definition Layout.hpp:305
Wrapper class to store strings.
Definition String.hpp:101
The parent class for every widget.
Definition Widget.hpp:84
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
States used for drawing.
Definition RenderStates.hpp:39