TGUI  1.4.0
Loading...
Searching...
No Matches
SubwidgetContainer.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_SUBWIDGET_CONTAINER_HPP
26#define TGUI_SUBWIDGET_CONTAINER_HPP
27
28#include <TGUI/Widgets/Group.hpp>
29#include <TGUI/CopiedSharedPtr.hpp>
30
32
33TGUI_MODULE_EXPORT namespace tgui
34{
40 class TGUI_API SubwidgetContainer : public Widget
41 {
42 public:
43
44 using Ptr = std::shared_ptr<SubwidgetContainer>;
45 using ConstPtr = std::shared_ptr<const SubwidgetContainer>;
46
54 SubwidgetContainer(const char* typeName, bool initRenderer);
55
60 void setSize(const Layout2d& size) override;
61 using Widget::setSize;
62
71 void setFocused(bool focused) override;
72
80 void setEnabled(bool enabled) override;
81
86 TGUI_NODISCARD Container* getContainer();
87
92 TGUI_NODISCARD const Container* getContainer() const;
93
97 bool leftMousePressed(Vector2f pos) override;
98
102 void leftMouseReleased(Vector2f pos) override;
103
107 void rightMousePressed(Vector2f pos) override;
108
112 void rightMouseReleased(Vector2f pos) override;
113
117 void mouseMoved(Vector2f pos) override;
118
122 void keyPressed(const Event::KeyEvent& event) override;
123
127 void textEntered(char32_t key) override;
128
132 bool scrolled(float delta, Vector2f pos, bool touch) override;
133
137 void mouseNoLongerOnWidget() override;
138
142 void leftMouseButtonNoLongerDown() override;
143
147 void rightMouseButtonNoLongerDown() override;
148
151 // Shows the tool tip when the widget is located below the mouse.
152 // Returns its tool tip or the tool tip from a child widget if the mouse is on top of the widget.
153 // A nullptr is returned when the mouse is not on top of the widget or when the tool tip is empty.
155 TGUI_NODISCARD Widget::Ptr askToolTip(Vector2f mousePos) override;
156
159 // This function is called every frame with the time passed since the last frame.
161 bool updateTime(Duration elapsedTime) override;
162
167 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
168
173 void setParent(Container* parent) override;
174
176 protected:
177
183 void rendererChanged(const String& property) override;
184
188 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
189
193 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
194
198 void updateTextSize() override;
199
206 void draw(BackendRenderTarget& target, RenderStates states) const override;
207
209 protected:
210
211 CopiedSharedPtr<Group> m_container;
212
214 };
215
217}
218
220
221#endif // TGUI_SUBWIDGET_CONTAINER_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Container widget.
Definition Container.hpp:48
Definition CopiedSharedPtr.hpp:42
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:313
Wrapper class to store strings.
Definition String.hpp:96
Base class for widgets that consist of subwidgets that act together as if they are a single widget.
Definition SubwidgetContainer.hpp:41
void setFocused(bool focused) override
Focus or unfocus the widget.
void setSize(const Layout2d &size) override
Changes the size of the widget.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the subwidgets to a render target.
std::shared_ptr< SubwidgetContainer > Ptr
Shared widget pointer.
Definition SubwidgetContainer.hpp:44
void setEnabled(bool enabled) override
Enables or disables the widget.
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 const Container * getContainer() const
Returns a const pointer to the internal container.
std::shared_ptr< const SubwidgetContainer > ConstPtr
Shared constant widget pointer.
Definition SubwidgetContainer.hpp:45
TGUI_NODISCARD Container * getContainer()
Returns a pointer to the internal container.
TGUI_NODISCARD 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.
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 load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
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