28#include <TGUI/Container.hpp>
30#include <unordered_map>
38 class TGUI_API Grid :
public Container
41 using Ptr = std::shared_ptr<Grid>;
72 explicit Grid(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
89 Grid(Grid&& other)
noexcept;
169 const Padding& padding = Padding{0});
186 const Padding& padding = Padding{0});
204 [[nodiscard]]
const std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>>&
getWidgetLocations()
const;
283 [[nodiscard]]
const std::vector<std::vector<Widget::Ptr>>&
getGridWidgets()
const;
298 [[nodiscard]] std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
303 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
308 [[nodiscard]] Vector2f getMinimumSize()
const;
313 void updatePositionsOfAllWidgets();
318 void updateWidgets();
323 void recalculateAutoSize();
333 bool m_autoSize =
true;
335 std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
336 std::vector<std::vector<Padding>> m_objPadding;
337 std::vector<std::vector<Alignment>> m_objAlignment;
339 std::vector<float> m_rowHeight;
340 std::vector<float> m_columnWidth;
342 std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>> m_widgetCells;
344 std::unordered_map<Widget::Ptr, unsigned int> m_connectedSizeCallbacks;
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.
Grid & operator=(Grid &&other) noexcept
Overload of move assignment operator.
std::shared_ptr< const Grid > ConstPtr
Shared constant widget pointer.
Definition Grid.hpp:42
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:41
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.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition Grid.hpp:44
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.
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.
Grid & operator=(const Grid &other)
Overload of assignment operator.
const std::vector< std::vector< Widget::Ptr > > & getGridWidgets() const
Returns the widgets and their positions in the grid.
Grid(Grid &&other) noexcept
Move constructor.
Alignment
The alignment of the widget in its cell.
Definition Grid.hpp:53
@ Center
Center the widget in the cell.
Definition Grid.hpp:54
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:320
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37