TGUI  0.8-dev
Grid.hpp
1 //
3 // TGUI - Texus' 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  Center,
56  UpperLeft,
57  Up,
58  UpperRight,
59  Right,
60  BottomRight,
61  Bottom,
62  BottomLeft,
63  Left
64  };
65 
66 
68  // Default constructor
70  Grid();
71 
72 
79  static Grid::Ptr create();
80 
81 
85  Grid(const Grid& copy);
86 
87 
91  Grid(Grid&& copy);
92 
93 
97  Grid& operator= (const Grid& right);
98 
99 
103  Grid& operator= (Grid&& right);
104 
105 
114  static Grid::Ptr copy(Grid::ConstPtr grid);
115 
116 
127  void setSize(const Layout2d& size) override;
128  using Widget::setSize;
129 
130 
141  void setAutoSize(bool autoSize);
142 
143 
151  bool getAutoSize() const;
152 
153 
162  bool remove(const Widget::Ptr& widget) override;
163 
164 
169  void removeAllWidgets() override;
170 
171 
182  void addWidget(const Widget::Ptr& widget,
183  std::size_t row,
184  std::size_t column,
185  const Borders& borders = Borders{0},
186  Alignment alignment = Alignment::Center);
187 
188 
198  Widget::Ptr getWidget(std::size_t row, std::size_t column) const;
199 
200 
208  std::map<Widget::Ptr, std::pair<std::size_t, std::size_t>> getWidgetLocations() const;
209 
210 
218  void setWidgetBorders(const Widget::Ptr& widget, const Borders& borders = Borders(0, 0, 0, 0));
219 
220 
229  void setWidgetBorders(std::size_t row, std::size_t column, const Borders& borders = Borders(0, 0, 0, 0));
230 
231 
240  Borders getWidgetBorders(const Widget::Ptr& widget) const;
241 
242 
252  Borders getWidgetBorders(std::size_t row, std::size_t column) const;
253 
254 
262  void setWidgetAlignment(const Widget::Ptr& widget, Alignment alignment = Alignment::Center);
263 
264 
273  void setWidgetAlignment(std::size_t row, std::size_t column, Alignment alignment = Alignment::Center);
274 
275 
284  Alignment getWidgetAlignment(const Widget::Ptr& widget) const;
285 
286 
296  Alignment getWidgetAlignment(std::size_t row, std::size_t column) const;
297 
298 
305  const std::vector<std::vector<Widget::Ptr>>& getGridWidgets() const;
306 
307 
314  bool mouseOnWidget(sf::Vector2f pos) const override;
315 
316 
324  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
325 
326 
328  protected:
329 
330 
332  // Returns the minimum size required by the grid to display correctly all widgets.
334  sf::Vector2f getMinimumSize() const;
335 
336 
338  // Reposition all the widgets.
340  void updatePositionsOfAllWidgets();
341 
342 
344  // Updates the position and size of the widget
346  void updateWidgets();
347 
348 
350  // Makes a copy of the widget
352  Widget::Ptr clone() const override
353  {
354  return std::make_shared<Grid>(*this);
355  }
356 
357 
359  protected:
360 
361  bool m_autoSize = true;
362 
363  std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
364  std::vector<std::vector<Borders>> m_objBorders;
365  std::vector<std::vector<Alignment>> m_objAlignment;
366 
367  std::vector<float> m_rowHeight;
368  std::vector<float> m_columnWidth;
369 
370  std::map<Widget::Ptr, unsigned int> m_connectedCallbacks;
371 
373  };
374 
376 }
377 
379 
380 #endif // TGUI_GRID_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
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:243
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Container widget.
Definition: Container.hpp:47
Definition: Outline.hpp:38
Definition: Grid.hpp:38
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Grid.hpp:352