TGUI  0.8.0
Grid.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 Padding& padding = Padding{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 setWidgetPadding(const Widget::Ptr& widget, const Padding& padding = Padding(0, 0, 0, 0));
219 
220 
229  void setWidgetPadding(std::size_t row, std::size_t column, const Padding& padding = Padding(0, 0, 0, 0));
230 
231 
240  Padding getWidgetPadding(const Widget::Ptr& widget) const;
241 
242 
252  Padding getWidgetPadding(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(Vector2f pos) const override;
315 
316 
324  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
325 
326 
328  protected:
329 
333  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
334 
335 
339  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
340 
341 
343  // Returns the minimum size required by the grid to display correctly all widgets.
345  Vector2f getMinimumSize() const;
346 
347 
349  // Reposition all the widgets.
351  void updatePositionsOfAllWidgets();
352 
353 
355  // Updates the position and size of the widget
357  void updateWidgets();
358 
359 
361  // Makes a copy of the widget
363  Widget::Ptr clone() const override
364  {
365  return std::make_shared<Grid>(*this);
366  }
367 
368 
370  protected:
371 
372  bool m_autoSize = true;
373 
374  std::vector<std::vector<Widget::Ptr>> m_gridWidgets;
375  std::vector<std::vector<Padding>> m_objPadding;
376  std::vector<std::vector<Alignment>> m_objAlignment;
377 
378  std::vector<float> m_rowHeight;
379  std::vector<float> m_columnWidth;
380 
381  std::map<Widget::Ptr, unsigned int> m_connectedCallbacks;
382 
384  };
385 
387 }
388 
390 
391 #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:76
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:363