TGUI  1.6.1
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#ifndef TGUI_CUSTOM_WIDGET_FOR_BINDINGS_HPP
26#define TGUI_CUSTOM_WIDGET_FOR_BINDINGS_HPP
27
28#ifndef TGUI_REMOVE_DEPRECATED_CODE
29
31
32#include <TGUI/Widget.hpp>
33
35
36TGUI_MODULE_EXPORT namespace tgui
37{
43 class TGUI_API CustomWidgetForBindings : public Widget
44 {
45 public:
46
47 using Ptr = std::shared_ptr<CustomWidgetForBindings>;
48 using ConstPtr = std::shared_ptr<const CustomWidgetForBindings>;
49
50 static constexpr const char StaticWidgetType[] = "CustomWidget";
51
59 CustomWidgetForBindings(const char* typeName = StaticWidgetType, bool initRenderer = true);
60
65 TGUI_NODISCARD static CustomWidgetForBindings::Ptr create();
66
90 void setPosition(const Layout2d& position) override;
91
109 void setSize(const Layout2d& size) override;
110
119 TGUI_NODISCARD Vector2f getFullSize() const override;
120
128 TGUI_NODISCARD Vector2f getWidgetOffset() const override;
129
137 void setVisible(bool visible) override;
138
146 void setEnabled(bool enabled) override;
147
156 void setFocused(bool focused) override;
157
162 TGUI_NODISCARD bool canGainFocus() const override;
163
168 bool updateTime(Duration elapsedTime) override;
169
174 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
175
179 bool leftMousePressed(Vector2f pos) override;
180
184 void leftMouseReleased(Vector2f pos) override;
185
189 void rightMousePressed(Vector2f pos) override;
190
194 void rightMouseReleased(Vector2f pos) override;
195
199 void mouseMoved(Vector2f pos) override;
200
204 void keyPressed(const Event::KeyEvent& event) override;
205
209 void textEntered(char32_t key) override;
210
215 bool scrolled(float delta, Vector2f pos, bool touch) override;
216
220 void mouseNoLongerOnWidget() override;
221
225 void leftMouseButtonNoLongerDown() override;
226
232 void draw(BackendRenderTarget& target, RenderStates states) const override;
233
244 TGUI_NODISCARD Widget::Ptr clone() const override;
245
247 protected:
248
254 void rendererChanged(const String& property) override;
255
259 void mouseEnteredWidget() override;
260
264 void mouseLeftWidget() override;
265
266 public:
267
268 std::function<void(Vector2f)> implPositionChanged;
269 std::function<void(Vector2f)> implSizeChanged;
270 std::function<void(bool)> implVisibleChanged;
271 std::function<void(bool)> implEnableChanged;
272 std::function<void(bool)> implFocusChanged;
273 std::function<bool()> implCanGainFocus;
274 std::function<Vector2f()> implGetFullSize;
275 std::function<Vector2f()> implGetWidgetOffset;
276 std::function<bool(Duration)> implUpdateTimeFunction;
277 std::function<bool(Vector2f)> implMouseOnWidget;
278 std::function<bool(Vector2f)> implLeftMousePressed;
279 std::function<void(Vector2f)> implLeftMouseReleased;
280 std::function<void(Vector2f)> implRightMousePressed;
281 std::function<void(Vector2f)> implRightMouseReleased;
282 std::function<void(Vector2f)> implMouseMoved;
283 std::function<void(const Event::KeyEvent&)> implKeyPressed;
284 std::function<void(char32_t)> implTextEntered;
285 std::function<bool(float, Vector2f, bool)> implScrolled;
286 std::function<void()> implMouseNoLongerOnWidget;
287 std::function<void()> implLeftMouseButtonNoLongerDown;
288 std::function<void()> implMouseEnteredWidget;
289 std::function<void()> implMouseLeftWidget;
290 std::function<bool(const String&)> implRendererChanged;
291 std::function<void(BackendRenderTarget&, RenderStates)> implDrawFunction;
292
294 };
295
297}
298
299#endif // TGUI_REMOVE_DEPRECATED_CODE
300
302
303#endif // TGUI_WIDGET_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Class used by bindings to implement custom widgets withing these bindings (e.g. a custom C# widget in...
Definition CustomWidgetForBindings.hpp:44
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:48
std::shared_ptr< CustomWidgetForBindings > Ptr
Shared widget pointer.
Definition CustomWidgetForBindings.hpp:47
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.
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:55
Class to store the position or size of a widget.
Definition Layout.hpp:323
Wrapper class to store strings.
Definition String.hpp:96
The parent class for every widget.
Definition Widget.hpp:83
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
KeyPressed event parameters.
Definition Event.hpp:168
States used for drawing.
Definition RenderStates.hpp:38