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/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;
648 m_userData = std::move(userData);
656 template <
typename T>
659 return AnyCast<T>(m_userData);
836 virtual void setParent(
Container* parent);
843 virtual bool updateTime(
Duration elapsedTime);
855 virtual void leftMousePressed(
Vector2f pos);
860 virtual void leftMouseReleased(
Vector2f pos);
865 virtual void rightMousePressed(
Vector2f pos);
870 virtual void rightMouseReleased(
Vector2f pos);
885 virtual void mouseMoved(
Vector2f pos);
895 virtual void textEntered(char32_t key);
901 virtual bool mouseWheelScrolled(
float delta,
Vector2f pos);
906 virtual void mouseNoLongerOnWidget();
911 virtual void leftMouseButtonNoLongerDown();
916 virtual void rightMouseButtonNoLongerDown();
932 const Layout2d& getPositionLayout()
const
942 const Layout2d& getSizeLayout()
const
952 void bindPositionLayout(Layout* layout);
959 void unbindPositionLayout(Layout* layout);
966 void bindSizeLayout(Layout* layout);
973 void unbindSizeLayout(Layout* layout);
990 template <
typename W
idgetType>
991 std::shared_ptr<const WidgetType>
cast()
const
993 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
1000 template <
typename W
idgetType>
1003 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
1021 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>,
String>>;
1022 using LoadingRenderersMap = std::map<String, std::shared_ptr<RendererData>>;
1036 virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
1042 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
1063 void rendererChangedCallback(
const String& property);
1086 unsigned int m_textSize = 0;
1089 Optional<Vector2f> m_rotationOrigin;
1090 Optional<Vector2f> m_scaleOrigin;
1092 float m_rotationDeg = 0;
1096 Vector2f m_prevPosition;
1097 Vector2f m_prevSize;
1100 std::unordered_set<Layout*> m_boundPositionLayouts;
1101 std::unordered_set<Layout*> m_boundSizeLayouts;
1104 bool m_enabled =
true;
1107 bool m_visible =
true;
1110 Container* m_parent =
nullptr;
1111 GuiBase* m_parentGui =
nullptr;
1114 bool m_mouseHover =
false;
1115 bool m_mouseDown =
false;
1118 bool m_focused =
false;
1121 bool m_focusable =
true;
1124 Duration m_animationTimeElapsed;
1127 bool m_draggableWidget =
false;
1130 bool m_containerWidget =
false;
1136 aurora::CopiedPtr<WidgetRenderer> m_renderer =
nullptr;
1139 std::vector<std::shared_ptr<priv::Animation>> m_showAnimations;
1142 Font m_inheritedFont;
1143 float m_inheritedOpacity = 1;
1147 float m_opacityCached = 1;
1148 bool m_transparentTextureCached =
false;
1153 std::function<void(
const String& property)> m_rendererChangedCallback = [
this](
const String& property){ rendererChangedCallback(property); };
1158 friend class Container;
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.
Base class for the Gui.
Definition: GuiBase.hpp:45
Class to store the position or size of a widget.
Definition: Layout.hpp:262
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:669
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Wrapper class to store strings.
Definition: String.hpp:74
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
ShowAnimationType
Type of animation 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