30#include <TGUI/Container.hpp>
31#include <unordered_map>
43 using Ptr = std::shared_ptr<Grid>;
46 static constexpr const char StaticWidgetType[] =
"Grid";
77 Grid(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
135 using Widget::setSize;
229 const std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>>&
getWidgetLocations()
const;
344 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
350 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
362 void updatePositionsOfAllWidgets();
368 void updateWidgets();
380 bool m_autoSize =
true;
382 std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
383 std::vector<std::vector<Padding>> m_objPadding;
384 std::vector<std::vector<Alignment>> m_objAlignment;
386 std::vector<float> m_rowHeight;
387 std::vector<float> m_columnWidth;
389 std::unordered_map<Widget::Ptr, std::pair<std::size_t, std::size_t>> m_widgetCells;
391 std::unordered_map<Widget::Ptr, unsigned int> m_connectedSizeCallbacks;
Container widget.
Definition: Container.hpp:47
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:44
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:43
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.
Alignment
The alignment of the widget in its cell.
Definition: Grid.hpp:57
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(const Widget::Ptr &widget, const Padding &padding=Padding(0, 0, 0, 0))
Changes padding of a given widget.
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 setWidgetPadding(std::size_t row, std::size_t column, const Padding &padding=Padding(0, 0, 0, 0))
Changes padding of a widget in a certain cell.
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:284
Definition: Outline.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36