26#ifndef TGUI_WIDGET_HPP
27#define TGUI_WIDGET_HPP
31#include <TGUI/Global.hpp>
32#include <TGUI/Signal.hpp>
33#include <TGUI/Sprite.hpp>
34#include <TGUI/Layout.hpp>
35#include <TGUI/String.hpp>
36#include <TGUI/Vector2f.hpp>
37#include <TGUI/Loading/Theme.hpp>
38#include <TGUI/Loading/DataIO.hpp>
39#include <TGUI/Loading/Serializer.hpp>
40#include <TGUI/Loading/Deserializer.hpp>
41#include <TGUI/Renderers/WidgetRenderer.hpp>
42#include <TGUI/Aurora/SmartPtr/CopiedPtr.hpp>
43#include <TGUI/Aurora/Tools/Downcast.hpp>
45#include <SFML/System/Time.hpp>
46#include <SFML/Window/Event.hpp>
47#include <SFML/Graphics/RenderTarget.hpp>
49#include <unordered_set>
51#if TGUI_COMPILED_WITH_CPP_VER >= 17
54 #include <TGUI/Any.hpp>
77 typedef std::shared_ptr<Widget>
Ptr;
78 typedef std::shared_ptr<const Widget>
ConstPtr;
178 setPosition({std::move(x), std::move(y)});
189 return m_position.getValue();
223 setSize({std::move(width), std::move(height)});
234 return m_size.getValue();
435#if TGUI_COMPILED_WITH_CPP_VER >= 17
441 m_userData = std::move(userData);
449 template <
typename T>
452#if TGUI_COMPILED_WITH_CPP_VER >= 17
453 return std::any_cast<T>(m_userData);
455 return m_userData.as<T>();
583 virtual void setParent(
Container* parent);
590 virtual bool update(sf::Time elapsedTime);
602 virtual void leftMousePressed(
Vector2f pos);
607 virtual void leftMouseReleased(
Vector2f pos);
612 virtual void rightMousePressed(
Vector2f pos);
617 virtual void rightMouseReleased(
Vector2f pos);
622 virtual void mousePressed(sf::Mouse::Button button,
Vector2f pos);
627 virtual void mouseReleased(sf::Mouse::Button button,
Vector2f pos);
632 virtual void mouseMoved(
Vector2f pos);
637 virtual void keyPressed(
const sf::Event::KeyEvent& event);
642 virtual void textEntered(std::uint32_t key);
648 virtual bool mouseWheelScrolled(
float delta,
Vector2f pos);
653 virtual void mouseNoLongerOnWidget();
655#ifndef TGUI_REMOVE_DEPRECATED_CODE
659 TGUI_DEPRECATED(
"Use leftMouseButtonNoLongerDown instead") virtual
void mouseNoLongerDown();
664 virtual void leftMouseButtonNoLongerDown();
669 virtual void rightMouseButtonNoLongerDown();
685 const Layout2d& getPositionLayout()
const
695 const Layout2d& getSizeLayout()
const
705 void bindPositionLayout(Layout* layout);
712 void unbindPositionLayout(Layout* layout);
719 void bindSizeLayout(Layout* layout);
726 void unbindSizeLayout(Layout* layout);
749 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const = 0;
755 template <
typename W
idgetType>
756 std::shared_ptr<const WidgetType>
cast()
const
758 return std::dynamic_pointer_cast<const WidgetType>(shared_from_this());
765 template <
typename W
idgetType>
766 std::shared_ptr<WidgetType>
cast()
768 return std::dynamic_pointer_cast<WidgetType>(shared_from_this());
786 using SavingRenderersMap = std::map<const Widget*, std::pair<std::unique_ptr<DataIO::Node>, std::string>>;
787 using LoadingRenderersMap = std::map<std::string, std::shared_ptr<RendererData>>;
801 virtual std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const;
807 virtual void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers);
825 void drawRectangleShape(sf::RenderTarget& target,
826 const sf::RenderStates& states,
834 void drawBorders(sf::RenderTarget& target,
835 const sf::RenderStates& states,
847 void rendererChangedCallback(
const std::string& property);
853 SignalVector2f onPositionChange = {
"PositionChanged"};
854 SignalVector2f onSizeChange = {
"SizeChanged"};
870 unsigned int m_textSize = 0;
878 std::unordered_set<Layout*> m_boundPositionLayouts;
879 std::unordered_set<Layout*> m_boundSizeLayouts;
882 bool m_enabled =
true;
885 bool m_visible =
true;
891 bool m_mouseHover =
false;
892 bool m_mouseDown =
false;
895 bool m_focused =
false;
898 bool m_focusable =
true;
901 sf::Time m_animationTimeElapsed;
904 bool m_draggableWidget =
false;
907 bool m_containerWidget =
false;
913 aurora::CopiedPtr<WidgetRenderer> m_renderer = aurora::makeCopied<WidgetRenderer>();
916 std::vector<std::shared_ptr<priv::Animation>> m_showAnimations;
919 Font m_inheritedFont;
920 float m_inheritedOpacity = 1;
924 float m_opacityCached = 1;
925 bool m_transparentTextureCached =
false;
927#if TGUI_COMPILED_WITH_CPP_VER >= 17
933 std::function<void(
const std::string& property)> m_rendererChangedCallback = [
this](
const std::string& property){ rendererChangedCallback(property); };
938 friend class Container;
Wrapper for colors.
Definition: Color.hpp:49
Container widget.
Definition: Container.hpp:48
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Class to store the left, top, width or height of a widget.
Definition: Layout.hpp:50
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:695
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37
ShowAnimationType
Type of animation to show/hide widget.
Definition: Animation.hpp:44
TGUI_API Font getGlobalFont()
Retrieves the default font used for all new widgets.