TGUI  0.8-dev
BoxLayout.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_BOX_LAYOUT_HPP
27 #define TGUI_BOX_LAYOUT_HPP
28 
29 #include <TGUI/Widgets/Panel.hpp>
30 
32 
33 namespace tgui
34 {
39  class TGUI_API BoxLayout : public Panel
40  {
41  public:
42 
43  typedef std::shared_ptr<BoxLayout> Ptr;
44  typedef std::shared_ptr<const BoxLayout> ConstPtr;
45 
46 
51  BoxLayout();
52 
53 
60  virtual void setSize(const Layout2d& size) override;
62 
63 
78  bool insert(std::size_t index, const tgui::Widget::Ptr& widget, const sf::String& widgetName = "");
79 
80 
90  void add(const tgui::Widget::Ptr& widget, const sf::String& widgetName = "") override;
91 
92 
99  void addSpace(float ratio = 1);
100 
101 
113  bool insertSpace(std::size_t index, float ratio = 1);
114 
115 
124  bool remove(const tgui::Widget::Ptr& widget) override;
125 
126 
135  bool remove(std::size_t index);
136 
137 
146  Widget::Ptr get(std::size_t index);
147 
148 
162  bool setRatio(const Widget::Ptr& widget, float ratio);
163 
164 
179  bool setRatio(std::size_t index, float ratio);
180 
181 
194  float getRatio(const Widget::Ptr& widget);
195 
196 
209  float getRatio(std::size_t index);
210 
211 
224  bool setFixedSize(const Widget::Ptr& widget, float size);
225 
226 
239  bool setFixedSize(std::size_t index, float size);
240 
241 
253  float getFixedSize(const Widget::Ptr& widget);
254 
255 
267  float getFixedSize(std::size_t index);
268 
269 
274  void removeAllWidgets() override;
275 
276 
284  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
285 
286 
288  protected:
289 
291  // Repositions all the widgets.
293  virtual void updateWidgetPositions() = 0;
294 
295 
302  virtual void rendererChanged(const std::string& property) override;
303 
304 
306  protected:
307 
308  std::vector<float> m_widgetsRatio;
309  std::vector<float> m_widgetsFixedSizes;
310 
311 
313  };
314 
315 
317 }
318 
320 
321 #endif // TGUI_BOX_LAYOUT_HPP
std::vector< float > m_widgetsFixedSizes
The fixed size of each widget. 0 means a variable size.
Definition: BoxLayout.hpp:309
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Class to store the position or size of a widget.
Definition: Layout.hpp:263
std::shared_ptr< BoxLayout > Ptr
Shared widget pointer.
Definition: BoxLayout.hpp:43
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Group of widgets that has a background color and optional borders.
Definition: Panel.hpp:56
std::shared_ptr< const BoxLayout > ConstPtr
Shared constant widget pointer.
Definition: BoxLayout.hpp:44
Abstract class for box layout containers.
Definition: BoxLayout.hpp:39
std::vector< float > m_widgetsRatio
The ratio of each widget.
Definition: BoxLayout.hpp:308