26#ifndef TGUI_CONTAINER_HPP
27#define TGUI_CONTAINER_HPP
29#include <TGUI/Widget.hpp>
50 typedef std::shared_ptr<Container>
Ptr;
51 typedef std::shared_ptr<const Container>
ConstPtr;
61 Container(
const char* typeName,
bool initRenderer);
99 using Widget::setSize;
121 template<
typename Function>
124 std::sort(m_widgets.begin(), m_widgets.end(), std::forward<Function>(function));
173 return std::dynamic_pointer_cast<T>(get(widgetName));
491 void leftMousePressed(
Vector2f pos)
override;
496 void rightMousePressed(
Vector2f pos)
override;
501 void leftMouseReleased(
Vector2f pos)
override;
506 void rightMouseReleased(
Vector2f pos)
override;
511 void mouseMoved(
Vector2f pos)
override;
521 void textEntered(
char32_t key)
override;
526 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
531 void mouseNoLongerOnWidget()
override;
536 void leftMouseButtonNoLongerDown()
override;
541 void rightMouseButtonNoLongerDown()
override;
557 bool updateTime(
Duration elapsedTime)
override;
564 void setParent(
Container* parent)
override;
571 void setParentGui(
GuiBase* gui);
599 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
605 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
625 std::size_t getFocusedWidgetIndex()
const;
631 bool tryFocusWidget(
const tgui::Widget::Ptr &widget,
bool reverseWidgetOrder,
bool recursive);
649 void injectFormFilePath(
const std::unique_ptr<DataIO::Node>& node,
const String& path, std::map<String, bool>& checkedFilenames)
const;
655 void loadWidgetsImpl(
const std::unique_ptr<DataIO::Node>& rootNode,
bool replaceExisting);
661 std::vector<Widget::Ptr> m_widgets;
671 bool m_isolatedFocus =
false;
687 typedef std::shared_ptr<RootContainer>
Ptr;
688 typedef std::shared_ptr<const RootContainer>
ConstPtr;
698 RootContainer(
const char* typeName =
"RootContainer",
bool initRenderer =
true);
708 using Widget::setSize;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Container widget.
Definition Container.hpp:47
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.
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.
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.
bool focusPreviousWidget(bool recursive=true)
Focuses the previous widget in this container.
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.
std::shared_ptr< Container > Ptr
Shared widget pointer.
Definition Container.hpp:50
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the child widgets to a render target.
void loadWidgetsFromStream(std::stringstream &&stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
bool processMouseWheelScrollEvent(float delta, Vector2f pos)
Inform the container about a mouse wheel scroll event.
virtual Vector2f getInnerSize() const
Returns the space available for widgets inside the container.
Widget::Ptr get(const String &widgetName) const
Returns a pointer to a widget that was added earlier.
bool focusNextWidget(bool recursive=true)
Focuses the next widget in this container.
const std::vector< Widget::Ptr > & getWidgets() const
Returns a list of all the widgets in this container.
Definition Container.hpp:108
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.
bool setWidgetIndex(const Widget::Ptr &widget, std::size_t index)
Changes the index of a widget in this container.
void sortWidgets(Function &&function)
Sorts a list of all the widgets in this container.
Definition Container.hpp:122
void setTextSize(unsigned int size) override
Changes the character size of all existing and future child widgets.
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.
T::Ptr get(const String &widgetName) const
Returns a pointer to a widget that was added earlier.
Definition Container.hpp:171
std::size_t moveWidgetForward(const Widget::Ptr &widget)
Places a widget one step forward in the z-order.
virtual Vector2f getChildWidgetsOffset() const
Returns the distance between the position of the container and a widget that would be drawn inside th...
Definition Container.hpp:209
int getWidgetIndex(const Widget::Ptr &widget) const
Returns the current index of a widget in this container.
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.
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.
std::shared_ptr< const Container > ConstPtr
Shared constant widget pointer.
Definition Container.hpp:51
virtual Widget::Ptr getWidgetAtPosition(Vector2f pos) const
Returns the leaf child widget that is located at the given position.
Widget::Ptr getFocusedChild() const
Returns the child widget that is focused inside this container.
Widget::Ptr getFocusedLeaf() const
Returns the leaf child widget that is focused inside this container.
Wrapper for durations.
Definition Duration.hpp:52
Base class for the Gui.
Definition GuiBase.hpp:45
Class to store the position or size of a widget.
Definition Layout.hpp:262
Definition Container.hpp:684
std::shared_ptr< const RootContainer > ConstPtr
Shared constant widget pointer.
Definition Container.hpp:688
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 setFocused(bool focused) override
Focus or unfocus the widget.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draws all widgets to a render target.
std::shared_ptr< RootContainer > Ptr
Shared widget pointer.
Definition Container.hpp:687
void setSize(const Layout2d &size) override
Changes the size of the container.
Wrapper class to store strings.
Definition String.hpp:79
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition Event.hpp:167
MouseButton
Mouse buttons.
Definition Event.hpp:148
States used for drawing.
Definition RenderStates.hpp:39