TGUI  0.7.8
BoxLayout.hpp
1
2//
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_BOX_LAYOUT_HPP
27#define TGUI_BOX_LAYOUT_HPP
28
29#include <TGUI/Widgets/Panel.hpp>
30
32
33namespace 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
52
53
60 virtual void setSize(const Layout2d& size) override;
62
63
72 virtual void setFont(const Font& font) override;
73
74
89 bool insert(std::size_t index, const tgui::Widget::Ptr& widget, const sf::String& widgetName = "");
90
91
101 void add(const tgui::Widget::Ptr& widget, const sf::String& widgetName = "") override;
102
103
110 void addSpace(float ratio = 1);
111
112
124 bool insertSpace(std::size_t index, float ratio = 1);
125
126
135 bool remove(const tgui::Widget::Ptr& widget) override;
136
137
146 bool remove(std::size_t index);
147
148
157 Widget::Ptr get(std::size_t index);
158
159
172 bool setRatio(const Widget::Ptr& widget, float ratio);
173
174
188 bool setRatio(std::size_t index, float ratio);
189
190
202 float getRatio(const Widget::Ptr& widget);
203
204
216 float getRatio(std::size_t index);
217
218
231 bool setFixedSize(const Widget::Ptr& widget, float size);
232
233
246 bool setFixedSize(std::size_t index, float size);
247
248
260 float getFixedSize(const Widget::Ptr& widget);
261
262
274 float getFixedSize(std::size_t index);
275
276
281 void removeAllWidgets() override;
282
283
285 protected:
286
288 // Reposition all the widgets.
290 virtual void updateWidgetPositions() = 0;
291
292
294 // Draws the widget on the render target.
296 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
297
298
300 protected:
301
302 std::vector<float> m_widgetsRatio;
303 std::vector<float> m_widgetsFixedSizes;
304
305
307 };
308
309
311}
312
314
315#endif // TGUI_BOX_LAYOUT_HPP
Abstract class for box layout containers.
Definition: BoxLayout.hpp:40
float getFixedSize(const Widget::Ptr &widget)
Returns the size of a widget when it has a constant value.
std::shared_ptr< BoxLayout > Ptr
Shared widget pointer.
Definition: BoxLayout.hpp:43
bool insertSpace(std::size_t index, float ratio=1)
Insert a space to the layout and immediately set its ratio.
bool setFixedSize(const Widget::Ptr &widget, float size)
Set the size of a widget to a constant value.
float getRatio(const Widget::Ptr &widget)
Returns the ratio of a widget.
std::vector< float > m_widgetsFixedSizes
The fixed size for each widget. 0 means a variable size.
Definition: BoxLayout.hpp:303
bool remove(const tgui::Widget::Ptr &widget) override
Removes a single widget that was added to the container.
bool insert(std::size_t index, const tgui::Widget::Ptr &widget, const sf::String &widgetName="")
Insert a widget to the layout.
BoxLayout()
Default constructor.
virtual void setFont(const Font &font) override
Changes the font the child widgets.
void removeAllWidgets() override
Removes all widgets that were added to the container.
float getRatio(std::size_t index)
Returns the ratio of a widget.
bool setRatio(const Widget::Ptr &widget, float ratio)
Change the ratio of a widget.
Widget::Ptr get(std::size_t index)
Returns the widget at the given index in the layout.
bool setRatio(std::size_t index, float ratio)
Change the ratio of a widget. The ratio is the size that will have a widget relatively to others....
float getFixedSize(std::size_t index)
Returns the size of a widget when it has a constant value.
std::vector< float > m_widgetsRatio
The ratio of each widget.
Definition: BoxLayout.hpp:302
bool setFixedSize(std::size_t index, float size)
Set the size of a widget to a constant value.
void addSpace(float ratio=1)
Adds a space at the end of the layout and immediately set its ratio.
void add(const tgui::Widget::Ptr &widget, const sf::String &widgetName="") override
Adds a widget at the end of the layout.
std::shared_ptr< const BoxLayout > ConstPtr
Shared constant widget pointer.
Definition: BoxLayout.hpp:44
virtual void setSize(const Layout2d &size) override
Changes the size of the layout.
bool remove(std::size_t index)
Removes a single widget that was added to the container.
Definition: Font.hpp:38
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Panel widget.
Definition: Panel.hpp:61
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:75
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34