26#ifndef TGUI_CONTAINER_HPP
27#define TGUI_CONTAINER_HPP
32#include <TGUI/Widget.hpp>
51 typedef std::shared_ptr<Container>
Ptr;
52 typedef std::shared_ptr<const Container>
ConstPtr;
117 template<
typename Function>
120 std::sort(m_widgets.begin(), m_widgets.end(), std::forward<Function>(
function));
123#ifndef TGUI_REMOVE_DEPRECATED_CODE
130 TGUI_DEPRECATED(
"Use getWidgets() and Widget::getWidgetName instead") const std::vector<sf::
String> getWidgetNames()
const
132 std::vector<sf::String> m_widgetNames;
133 m_widgetNames.reserve(m_widgets.size());
134 for (std::size_t i = 0; i < m_widgets.size(); ++i)
135 m_widgetNames.emplace_back(m_widgets[i]->getWidgetName());
137 return m_widgetNames;
150 virtual void add(
const Widget::Ptr& widgetPtr,
const sf::String& widgetName =
"");
184 typename T::Ptr
get(
const sf::String& widgetName)
const
186 return std::dynamic_pointer_cast<T>(get(widgetName));
207#ifndef TGUI_REMOVE_DEPRECATED_CODE
217 TGUI_DEPRECATED(
"Use Widget::setWidgetName instead") bool setWidgetName(const
Widget::
Ptr& widget, const std::
string& name);
218 using
Widget::setWidgetName;
229 TGUI_DEPRECATED("Use
Widget::getWidgetName instead") std::
string getWidgetName(const
Widget::
ConstPtr& widget) const;
433 void leftMousePressed(
Vector2f pos)
override;
438 void leftMouseReleased(
Vector2f pos)
override;
443 void rightMousePressed(
Vector2f pos)
override;
448 void rightMouseReleased(
Vector2f pos)
override;
453 void mouseMoved(
Vector2f pos)
override;
458 void keyPressed(
const sf::Event::KeyEvent& event)
override;
463 void textEntered(std::uint32_t key)
override;
468 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
473 void mouseNoLongerOnWidget()
override;
478 void leftMouseButtonNoLongerDown()
override;
483 void rightMouseButtonNoLongerDown()
override;
499 bool update(sf::Time elapsedTime)
override;
506 bool handleEvent(sf::Event& event);
525 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
531 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
544 virtual void drawWidgetContainer(sf::RenderTarget* target,
const sf::RenderStates& states = sf::RenderStates::Default)
const;
550 std::size_t getFocusedWidgetIndex()
const;
556 bool tryFocusWidget(
const tgui::Widget::Ptr &widget,
bool reverseWidgetOrder,
bool recursive);
562 std::vector<Widget::Ptr> m_widgets;
570 bool m_handingMouseReleased =
false;
573 bool m_isolatedFocus =
false;
585 class TGUI_API GuiContainer :
public Container
589 typedef std::shared_ptr<GuiContainer> Ptr;
590 typedef std::shared_ptr<const GuiContainer> ConstPtr;
608 void setSize(
const Layout2d& size)
override;
618 void setFocused(
bool focused)
override;
629 bool mouseOnWidget(
Vector2f pos)
const override;
639 void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
Container widget.
Definition: Container.hpp:48
virtual bool remove(const Widget::Ptr &widget)
Removes a single widget that was added to the container.
Container(const Container ©)
Copy constructor.
virtual Widget::Ptr getWidgetAtPosition(sf::Vector2f pos) const
Returns the leaf child widget that is located at the given position.
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:51
virtual void removeAllWidgets()
Removes all widgets that were added to the container.
void loadWidgetsFromStream(std::stringstream &&stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
virtual Vector2f getInnerSize() const
Returns the space available for widgets inside the container.
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:105
void sortWidgets(Function &&function)
Sorts a list of all the widgets in this container.
Definition: Container.hpp:118
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 rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
void moveWidgetToBack(const Widget::Ptr &widget)
Places a widget behind all other widgets, to the back of the z-order.
void saveWidgetsToFile(const std::string &filename)
Saves the child widgets to a text file.
virtual void add(const Widget::Ptr &widgetPtr, const sf::String &widgetName="")
Adds a widget to the container.
Widget::Ptr get(const sf::String &widgetName) const
Returns a pointer to a widget that was added earlier.
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:253
void loadWidgetsFromFile(const std::string &filename, bool replaceExisting=true)
Loads the child widgets from a text file.
T::Ptr get(const sf::String &widgetName) const
Returns a pointer to a widget that was added earlier.
Definition: Container.hpp:184
Container(Container &©)
Move constructor.
void setFocused(bool focused) override
Focus or unfocus the widget.
void uncheckRadioButtons()
Unchecks all the radio buttons.
void setSize(const Layout2d &size) override
Changes the size of the container.
void saveWidgetsToStream(std::stringstream &stream) const
Saves the child widgets to a text file.
void loadWidgetsFromStream(std::stringstream &stream, bool replaceExisting=true)
Loads the child widgets from a string stream.
std::shared_ptr< const Container > ConstPtr
Shared constant widget pointer.
Definition: Container.hpp:52
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.
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Wrapper class to store strings.
Definition: String.hpp:119
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37