25#ifndef TGUI_CONTAINER_HPP
26#define TGUI_CONTAINER_HPP
28#include <TGUI/Widget.hpp>
30#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
36TGUI_MODULE_EXPORT
namespace tgui
51 using Ptr = std::shared_ptr<Container>;
52 using ConstPtr = std::shared_ptr<const Container>;
61 Container(
const char* typeName,
bool initRenderer);
93 using Widget::setSize;
100 TGUI_NODISCARD
const std::vector<Widget::Ptr>&
getWidgets()
const
111 template<
typename Function>
114 std::sort(m_widgets.begin(), m_widgets.end(), std::forward<Function>(function));
157 template <
class W
idgetType>
158 TGUI_NODISCARD
typename WidgetType::Ptr
get(
const String& widgetName)
const
160 return std::dynamic_pointer_cast<WidgetType>(get(widgetName));
343#ifndef TGUI_REMOVE_DEPRECATED_CODE
353 TGUI_DEPRECATED(
"Use getWidgetAtPos instead") TGUI_NODISCARD virtual
Widget::
Ptr getWidgetAtPosition(
Vector2f pos) const;
459 void rightMousePressed(
Vector2f pos)
override;
464 void leftMouseReleased(
Vector2f pos)
override;
469 void rightMouseReleased(
Vector2f pos)
override;
474 void mouseMoved(
Vector2f pos)
override;
495 void textEntered(
char32_t key)
override;
505 void mouseNoLongerOnWidget()
override;
510 void leftMouseButtonNoLongerDown()
override;
515 void rightMouseButtonNoLongerDown()
override;
529 bool updateTime(
Duration elapsedTime)
override;
535 void setParent(
Container* parent)
override;
548 void updateChildrenWithAutoLayout();
571 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
576 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
598 TGUI_NODISCARD std::size_t getFocusedWidgetIndex()
const;
603 bool tryFocusWidget(
const Widget::Ptr &widget,
bool reverseWidgetOrder,
bool recursive);
618 void injectFormFilePath(
const std::unique_ptr<DataIO::Node>& node,
const String& path, std::map<String, bool>& checkedFilenames)
const;
623 void loadWidgetsImpl(
const std::unique_ptr<DataIO::Node>& rootNode,
bool replaceExisting);
628 std::vector<Widget::Ptr> m_widgets;
634 bool m_draggingWidget =
false;
639 bool m_isolatedFocus =
false;
653 using Ptr = std::shared_ptr<RootContainer>;
654 using ConstPtr = std::shared_ptr<const RootContainer>;
656 static constexpr const char StaticWidgetType[] =
"RootContainer";
665 RootContainer(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
687 void mouseNoLongerOnWidget()
override;
Base class for the Gui.
Definition BackendGui.hpp:47
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Container widget.
Definition Container.hpp:48
virtual bool remove(const Widget::Ptr &widget)
Removes a single widget that was added to the container.
bool processMousePressEvent(Event::MouseButton button, Vector2f pos)
Inform the container about a mouse press event.
Container(const Container ©)
Copy constructor.
TGUI_NODISCARD WidgetType::Ptr get(const String &widgetName) const
Returns a pointer to a widget that was added earlier.
Definition Container.hpp:158
bool processMouseReleaseEvent(Event::MouseButton button, Vector2f pos)
Inform the container about a mouse release event.
Container(Container &©) noexcept
Move constructor.
std::size_t moveWidgetBackward(const Widget::Ptr &widget)
Places a widget one step backward in the z-order.
virtual TGUI_NODISCARD Widget::Ptr getWidgetAtPos(Vector2f pos, bool recursive) const
Returns the widget that is located at the given position.
bool focusPreviousWidget(bool recursive=true)
Focuses the previous widget in this container.
~Container() override
Destructor.
TGUI_NODISCARD Widget::Ptr getFocusedLeaf() const
Returns the leaf child widget that is focused inside this container.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the child widgets to a render target.
std::shared_ptr< Container > Ptr
Shared widget pointer.
Definition Container.hpp:51
bool processScrollEvent(float delta, Vector2f pos, bool touch)
Inform the container about a scroll event (either mouse wheel or two finger scrolling on touchscreen)
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
TGUI_NODISCARD Widget::Ptr getFocusedChild() const
Returns the child widget that is focused inside this container.
virtual void add(const Widget::Ptr &widgetPtr, const String &widgetName="")
Adds a widget to the container.
virtual void removeAllWidgets()
Removes all widgets that were added to the 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.
void loadWidgetsFromStream(std::stringstream &&stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
TGUI_NODISCARD const std::vector< Widget::Ptr > & getWidgets() const
Returns a list of all the widgets in this container.
Definition Container.hpp:100
bool focusNextWidget(bool recursive=true)
Focuses the next widget in this container.
void loadWidgetsFromNodeTree(const std::unique_ptr< DataIO::Node > &rootNode, bool replaceExisting=true)
Loads the child widgets from a tree of nodes that contain all information about the widgets.
void sortWidgets(Function &&function)
Sorts a list of all the widgets in this container.
Definition Container.hpp:112
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void moveWidgetToFront(const Widget::Ptr &widget)
Places a widget before all other widgets, to the front of the z-order.
void loadWidgetsFromFile(const String &filename, bool replaceExisting=true)
Loads the child widgets from a text file.
void moveWidgetToBack(const Widget::Ptr &widget)
Places a widget behind all other widgets, to the back of the z-order.
virtual bool setWidgetIndex(const Widget::Ptr &widget, std::size_t index)
Changes the index of a widget in this container.
TGUI_NODISCARD Widget::Ptr get(const String &widgetName) const
Returns a pointer to a widget that was added earlier.
virtual TGUI_NODISCARD Vector2f getInnerSize() const
Returns the space available for widgets inside the container.
std::size_t moveWidgetForward(const Widget::Ptr &widget)
Places a widget one step forward in the z-order.
TGUI_NODISCARD int getWidgetIndex(const Widget::Ptr &widget) const
Returns the current index of a widget in this container.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
bool processTextEnteredEvent(char32_t key)
Inform the container about a key press event.
void setFocused(bool focused) override
Focus or unfocus the widget.
bool processKeyPressEvent(Event::KeyEvent event)
Inform the container about a key press event.
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 saveWidgetsToFile(const String &filename)
Saves the child widgets to a text file.
void saveWidgetsToStream(std::stringstream &stream, const String &rootDirectory="") const
Saves the child widgets to a text file.
void setSize(const Layout2d &size) override
Changes the size of the container.
void loadWidgetsFromStream(std::stringstream &stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
bool processMouseMoveEvent(Vector2f pos)
Inform the container about a mouse move event.
virtual TGUI_NODISCARD Vector2f getChildWidgetsOffset() const
Returns the distance between the position of the container and a widget that would be drawn inside th...
Definition Container.hpp:189
TGUI_NODISCARD std::unique_ptr< DataIO::Node > saveWidgetsToNodeTree(const String &rootDirectory="") const
Saves the child widgets to a tree of nodes that contain all information about the widgets.
std::shared_ptr< const Container > ConstPtr
Shared constant widget pointer.
Definition Container.hpp:52
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:313
Definition Container.hpp:650
std::shared_ptr< RootContainer > Ptr
Shared widget pointer.
Definition Container.hpp:653
std::shared_ptr< const RootContainer > ConstPtr
Shared constant widget pointer.
Definition Container.hpp:654
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...
void draw(BackendRenderTarget &target, RenderStates states) const override
Draws all widgets to a render target.
void setFocused(bool focused) override
Focus or unfocus the widget.
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
KeyPressed event parameters.
Definition Event.hpp:168
MouseButton
Mouse buttons.
Definition Event.hpp:149
States used for drawing.
Definition RenderStates.hpp:38