TGUI  v0.6.10
Grid.hpp
1 //
3 // TGUI - Texus's Graphical User Interface
4 // Copyright (C) 2012-2015 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 SharedWidgetPtr<Grid> Ptr;
43 
44 
52  struct Layout
53  {
55  enum Layouts
56  {
58  Up,
64  Left,
65  Center
66  };
67  };
68 
69 
74  Grid();
75 
76 
83  Grid(const Grid& copy);
84 
85 
90  virtual ~Grid();
91 
92 
101  Grid& operator= (const Grid& right);
102 
103 
105  // Makes a copy of the widget by calling the copy constructor.
106  // This function calls new and if you use this function then you are responsible for calling delete.
108  virtual Grid* clone();
109 
110 
122  virtual void setSize(float width, float height);
123 
124 
131  virtual sf::Vector2f getSize() const;
132 
133 
150  virtual void remove(const Widget::Ptr& widget);
151 
152 
164  virtual void remove(Widget* widget);
165 
166 
171  virtual void removeAllWidgets();
172 
173 
184  void addWidget(const Widget::Ptr& widget,
185  unsigned int row,
186  unsigned int column,
187  const Borders& borders = Borders(0, 0, 0, 0),
188  Layout::Layouts layout = Layout::Center);
189 
190 
200  Widget::Ptr getWidget(unsigned int row, unsigned int column);
201 
202 
209  void updateWidgets();
210 
211 
219  void changeWidgetBorders(const Widget::Ptr& widget, const Borders& borders = Borders(0, 0, 0, 0));
220 
221 
229  void changeWidgetLayout(const Widget::Ptr& widget, Layout::Layouts layout = Layout::Center);
230 
231 
235  virtual bool mouseOnWidget(float x, float y);
236 
237 
239  protected:
240 
241 
243  // Returns the minimum size required by the grid to display correctly all widgets.
245  sf::Vector2f getMinSize();
246 
247 
249  // Reposition all the widgets.
251  void updatePositionsOfAllWidgets();
252 
253 
255  // Draws the widget on the render target.
257  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
258 
259 
261  public:
262 
267  {
268  AllGridCallbacks = WidgetCallbacksCount - 1,
269  GridCallbacksCount = WidgetCallbacksCount
270  };
271 
272 
274  protected:
275 
276  std::vector< std::vector<Widget::Ptr> > m_GridWidgets;
277  std::vector< std::vector<Borders> > m_ObjBorders;
278  std::vector< std::vector<Layout::Layouts> > m_ObjLayout;
279 
280  std::vector<unsigned int> m_RowHeight;
281  std::vector<unsigned int> m_ColumnWidth;
282 
283  sf::Vector2f m_Size; // Real (optimal) size of the grid
284  sf::Vector2f m_IntendedSize; // Intended size that the grid should have if it is possible
285 
286 
288  };
289 
291 }
292 
294 
295 #endif // TGUI_GRID_HPP
Namespace that contains all TGUI functions and classes.
Definition: AnimatedPicture.hpp:33
Draw the widget in the bottom left corner of the cell.
Definition: Grid.hpp:63
Draw the widget at the upper side of the cell (horizontally centered)
Definition: Grid.hpp:58
The parent class for every widget.
Definition: Widget.hpp:45
Draw the widget in the upper left corner of the cell.
Definition: Grid.hpp:57
Draw the widget at the bottom of the cell (horizontally centered)
Definition: Grid.hpp:62
The layout of the widget.
Definition: Grid.hpp:52
Draw the widget in the upper right corner of the cell.
Definition: Grid.hpp:59
Parent class for widgets that store multiple widgets.
Definition: Container.hpp:43
GridCallbacks
Defines specific triggers to Grid.
Definition: Grid.hpp:266
Definition: Borders.hpp:35
Draw the widget at the right side of the cell (vertically centered)
Definition: Grid.hpp:60
Draw the widget in the bottom right corner of the cell.
Definition: Grid.hpp:61
Layouts
The layout of the widget.
Definition: Grid.hpp:55
Definition: Grid.hpp:38
Definition: SharedWidgetPtr.hpp:44
Draw the widget at the left side of the cell (vertically centered)
Definition: Grid.hpp:64