26#ifndef TGUI_WIDGET_HPP
27#define TGUI_WIDGET_HPP
31#include <TGUI/Signal.hpp>
32#include <TGUI/Font.hpp>
33#include <TGUI/Sprite.hpp>
34#include <TGUI/Layout.hpp>
35#include <TGUI/String.hpp>
36#include <TGUI/Vector2.hpp>
37#include <TGUI/Duration.hpp>
38#include <TGUI/Cursor.hpp>
39#include <TGUI/Event.hpp>
40#include <TGUI/Any.hpp>
41#include <TGUI/Backend/Renderer/BackendRenderTarget.hpp>
42#include <TGUI/Loading/Theme.hpp>
43#include <TGUI/Loading/DataIO.hpp>
44#include <TGUI/Loading/Serializer.hpp>
45#include <TGUI/Loading/Deserializer.hpp>
46#include <TGUI/Renderers/WidgetRenderer.hpp>
47#include <TGUI/extlibs/Aurora/SmartPtr/CopiedPtr.hpp>
48#include <TGUI/extlibs/Aurora/Tools/Downcast.hpp>
50#include <unordered_set>
69 class TGUI_API
Widget :
public std::enable_shared_from_this<Widget>
73 typedef std::shared_ptr<Widget>
Ptr;
74 typedef std::shared_ptr<const Widget>
ConstPtr;
84 Widget(
const char* typeName,
bool initRenderer);
179 setPosition({std::move(x), std::move(y)});
190 return m_position.getValue();
224 setSize({std::move(width), std::move(height)});
238 setSize({std::move(width), m_size.y});
252 setSize({m_size.x, std::move(height)});
263 return m_size.getValue();
383 setScale({scaleFactor, scaleFactor});
402 setScale({scaleFactor, scaleFactor}, origin);
413 return m_scaleFactors;
458 return m_rotationDeg;
666 m_userData = std::move(userData);
674 template <
typename T>
677 return AnyCast<T>(m_userData);
865 virtual void setParent(
Container* parent);
872 virtual bool updateTime(
Duration elapsedTime);
884 virtual void leftMousePressed(
Vector2f pos);
889 virtual void leftMouseReleased(
Vector2f pos);
894 virtual void rightMousePressed(
Vector2f pos);
899 virtual void rightMouseReleased(
Vector2f pos);
914 virtual void mouseMoved(
Vector2f pos);
924 virtual void textEntered(
char32_t key);
930 virtual bool mouseWheelScrolled(
float delta,
Vector2f pos);
935 virtual void mouseNoLongerOnWidget();
940 virtual void leftMouseButtonNoLongerDown();
945 virtual void rightMouseButtonNoLongerDown();
961 const Layout2d& getPositionLayout()
const
971 const Layout2d& getSizeLayout()
const
981 void bindPositionLayout(Layout* layout);
988 void unbindPositionLayout(Layout* layout);
995 void bindSizeLayout(Layout* layout);
1002 void unbindSizeLayout(Layout* layout);
1019 template <
typename W
idgetType>
1020 std::shared_ptr<const WidgetType>
cast()
const
1022 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1029 template <
typename W
idgetType>
1032 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1050 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1051 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1065 virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1071 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1098 void rendererChangedCallback(
const String& property);
1128 unsigned int m_textSize = 0;
1131 Optional<Vector2f> m_rotationOrigin;
1132 Optional<Vector2f> m_scaleOrigin;
1134 float m_rotationDeg = 0;
1138 Vector2f m_prevPosition;
1139 Vector2f m_prevSize;
1142 std::unordered_set<Layout*> m_boundPositionLayouts;
1143 std::unordered_set<Layout*> m_boundSizeLayouts;
1146 bool m_enabled =
true;
1149 bool m_visible =
true;
1152 Container* m_parent =
nullptr;
1153 BackendGui* m_parentGui =
nullptr;
1156 bool m_mouseHover =
false;
1157 bool m_mouseDown =
false;
1160 bool m_focused =
false;
1163 bool m_focusable =
true;
1166 Duration m_animationTimeElapsed;
1169 bool m_draggableWidget =
false;
1172 bool m_containerWidget =
false;
1178 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1181 std::vector<std::shared_ptr<priv::Animation>> m_showAnimations;
1184 Font m_inheritedFont;
1185 float m_inheritedOpacity = 1;
1189 float m_opacityCached = 1;
1190 bool m_transparentTextureCached =
false;
1191 unsigned int m_textSizeCached = 0;
1196 std::function<void(
const String& property)> m_rendererChangedCallback = [
this](
const String& property){ rendererChangedCallback(property); };
1201 friend class Container;
Base class for the Gui.
Definition: BackendGui.hpp:45
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Container widget.
Definition: Container.hpp:47
Type
List of available cursors.
Definition: Cursor.hpp:48
@ Arrow
Arrow cursor (default)
Wrapper for durations.
Definition: Duration.hpp:52
static Font getGlobalFont()
Returns the global font that is used for all new widgets.
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Class to store the left, top, width or height of a widget.
Definition: Layout.hpp:50
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:779
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:669
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
ShowEffectType
Type of effect to show/hide widget.
Definition: Animation.hpp:44
KeyPressed event parameters.
Definition: Event.hpp:167
MouseButton
Mouse buttons.
Definition: Event.hpp:148
States used for drawing.
Definition: RenderStates.hpp:39