28#include <TGUI/Container.hpp>
30#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
31 #include <unordered_map>
36TGUI_MODULE_EXPORT
namespace tgui
44 using Ptr = std::shared_ptr<Grid>;
47 static constexpr const char StaticWidgetType[] =
"Grid";
75 Grid(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
124 using Widget::setSize;
207 TGUI_NODISCARD
const std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>>&
getWidgetLocations()
const;
286 TGUI_NODISCARD
const std::vector<std::vector<Widget::Ptr>>&
getGridWidgets()
const;
301 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
306 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
311 TGUI_NODISCARD
Vector2f getMinimumSize()
const;
316 void updatePositionsOfAllWidgets();
321 void updateWidgets();
326 void recalculateAutoSize();
336 bool m_autoSize =
true;
338 std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
339 std::vector<std::vector<Padding>> m_objPadding;
340 std::vector<std::vector<Alignment>> m_objAlignment;
342 std::vector<float> m_rowHeight;
343 std::vector<float> m_columnWidth;
345 std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>> m_widgetCells;
347 std::unordered_map<Widget::Ptr, unsigned int> m_connectedSizeCallbacks;
Container widget.
Definition Container.hpp:48
bool setWidgetCell(const Widget::Ptr &widget, std::size_t row, std::size_t column, Alignment alignment=Alignment::Center, const Padding &padding=Padding{0})
Chooses the row and column in which a widget should be placed.
const std::unordered_map< Widget::Ptr, std::pair< std::size_t, std::size_t > > & getWidgetLocations() const
Returns a list of widgets and the cell they are in.
void removeAllWidgets() override
Removes all widgets that were added to the container.
Grid(const Grid ©)
Copy constructor.
std::shared_ptr< const Grid > ConstPtr
Shared constant widget pointer.
Definition Grid.hpp:45
Widget::Ptr getWidget(std::size_t row, std::size_t column) const
Returns the widget in a specific cell of the grid.
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 setSize(const Layout2d &size) override
Changes the size of the grid.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< Grid > Ptr
Shared widget pointer.
Definition Grid.hpp:44
Alignment getWidgetAlignment(const Widget::Ptr &widget) const
Returns the alignment of a given widget.
Alignment getWidgetAlignment(std::size_t row, std::size_t column) const
Returns the alignment of a given widget in its cell.
Padding getWidgetPadding(std::size_t row, std::size_t column) const
Returns the padding around a widget in a specific cell of the grid.
void setWidgetPadding(const Widget::Ptr &widget, const Padding &padding={})
Changes padding of a given widget.
Alignment
The alignment of the widget in its cell.
Definition Grid.hpp:56
Padding getWidgetPadding(const Widget::Ptr &widget) const
Returns the padding around a widget.
bool getAutoSize() const
Returns whether the grid is auto-sized or not.
void addWidget(const Widget::Ptr &widget, std::size_t row, std::size_t column, Alignment alignment=Alignment::Center, const Padding &padding=Padding{0})
Adds a widget to the grid.
Grid(Grid &©) noexcept
Move constructor.
static Grid::Ptr create()
Creates a new grid widget.
void setWidgetPadding(std::size_t row, std::size_t column, const Padding &padding={})
Changes padding of a widget in a certain cell.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
bool remove(const Widget::Ptr &widget) override
Removes a single widget that was added to the container.
void setWidgetAlignment(std::size_t row, std::size_t column, Alignment alignment=Alignment::Center)
Changes the alignment of a given widget in its cell.
const std::vector< std::vector< Widget::Ptr > > & getGridWidgets() const
Returns the widgets and their positions in the grid.
void setWidgetAlignment(const Widget::Ptr &widget, Alignment alignment=Alignment::Center)
Changes the alignment of a given widget in its cell.
void setAutoSize(bool autoSize)
Changes whether the grid is auto-sized or not.
static Grid::Ptr copy(const Grid::ConstPtr &grid)
Makes a copy of another grid.
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition Outline.hpp:38
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38