TGUI  v0.7.5
Grid.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2017 Bruno Van de Velde (vdv_b@tgui.eu)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 
26 #ifndef TGUI_GRID_HPP
27 #define TGUI_GRID_HPP
28 
29 
30 #include <TGUI/Container.hpp>
31 
33 
34 namespace tgui
35 {
37 
38  class TGUI_API Grid : public Container
39  {
40  public:
41 
42  typedef std::shared_ptr<Grid> Ptr;
43  typedef std::shared_ptr<const Grid> ConstPtr;
44 
45 
53  enum class Alignment
54  {
55  UpperLeft,
56  Up,
57  UpperRight,
58  Right,
59  BottomRight,
60  Bottom,
61  BottomLeft,
62  Left,
63  Center
64  };
65 
66 
68  // Default constructor
70  Grid();
71 
72 
79  Grid(const Grid& copy);
80 
81 
90  Grid& operator= (const Grid& right);
91 
92 
99  static Grid::Ptr create();
100 
101 
110  static Grid::Ptr copy(Grid::ConstPtr grid);
111 
112 
123  virtual void setSize(const Layout2d& size) override;
125 
126 
133  virtual sf::Vector2f getSize() const override
134  {
135  return m_realSize;
136  }
137 
138 
147  virtual bool remove(const Widget::Ptr& widget) override;
148 
149 
154  virtual void removeAllWidgets() override;
155 
156 
167  void addWidget(const Widget::Ptr& widget,
168  unsigned int row,
169  unsigned int column,
170  const Borders& borders = Borders(0, 0, 0, 0),
171  Alignment alignment = Alignment::Center);
172 
173 
183  Widget::Ptr getWidget(unsigned int row, unsigned int column);
184 
185 
193  void updateWidgets();
194 
195 
203  void changeWidgetBorders(const Widget::Ptr& widget, const Borders& borders = Borders(0, 0, 0, 0));
204 
205 
213  void changeWidgetAlignment(const Widget::Ptr& widget, Alignment alignment = Alignment::Center);
214 
215 
219  virtual bool mouseOnWidget(float x, float y) const override;
220 
221 
223  protected:
224 
225 
227  // Returns the minimum size required by the grid to display correctly all widgets.
229  sf::Vector2f getMinSize();
230 
231 
233  // Reposition all the widgets.
235  void updatePositionsOfAllWidgets();
236 
237 
239  // Makes a copy of the widget
241  virtual Widget::Ptr clone() const override
242  {
243  return std::make_shared<Grid>(*this);
244  }
245 
246 
248  // Draws the widget on the render target.
250  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
251 
252 
254  protected:
255 
256  std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
257  std::vector<std::vector<Borders>> m_objBorders;
258  std::vector<std::vector<Alignment>> m_objAlignment;
259 
260  std::vector<float> m_rowHeight;
261  std::vector<float> m_columnWidth;
262 
263  std::map<Widget::Ptr, unsigned int> m_connectedCallbacks;
264 
265  sf::Vector2f m_realSize; // Actual size of the grid, while m_size contains the intended size
266 
268  };
269 
271 }
272 
274 
275 #endif // TGUI_GRID_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Alignment
The alignment of the widget in its cell.
Definition: Grid.hpp:53
std::shared_ptr< Grid > Ptr
Shared widget pointer.
Definition: Grid.hpp:42
std::shared_ptr< const Grid > ConstPtr
Shared constant widget pointer.
Definition: Grid.hpp:43
Class to store the position or size of a widget.
Definition: Layout.hpp:262
virtual sf::Vector2f getSize() const override
Returns the size of the grid.
Definition: Grid.hpp:133
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Grid.hpp:241
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Container widget.
Definition: Container.hpp:47
Definition: Borders.hpp:37
Definition: Grid.hpp:38