TGUI  0.8.9
BoxLayoutRatios.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2020 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_RATIOS_HPP
27#define TGUI_BOX_LAYOUT_RATIOS_HPP
28
29#include <TGUI/Widgets/BoxLayout.hpp>
30
32
33namespace tgui
34{
39 class TGUI_API BoxLayoutRatios : public BoxLayout
40 {
41 public:
42
43 typedef std::shared_ptr<BoxLayoutRatios> Ptr;
44 typedef std::shared_ptr<const BoxLayoutRatios> ConstPtr;
45
46
48 // Default constructor
50 BoxLayoutRatios(const Layout2d& size = {"100%", "100%"});
51
52
61 void add(const Widget::Ptr& widget, const sf::String& widgetName = "") override;
62
63
71 void add(const Widget::Ptr& widget, float ratio, const sf::String& widgetName = "");
72
73
85 void insert(std::size_t index, const Widget::Ptr& widget, const sf::String& widgetName = "") override;
86
87
101 void insert(std::size_t index, const Widget::Ptr& widget, float ratio, const sf::String& widgetName = "");
102
103
111 bool remove(std::size_t index) override;
112 using BoxLayout::remove;
113
114
118 void removeAllWidgets() override;
119
120
128 void addSpace(float ratio);
129
130
139 void insertSpace(std::size_t index, float ratio);
140
141
153 bool setRatio(Widget::Ptr widget, float ratio);
154
155
167 bool setRatio(std::size_t index, float ratio);
168
169
177 float getRatio(Widget::Ptr widget) const;
178
179
187 float getRatio(std::size_t index) const;
188
189
191 protected:
192
196 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
197
198
202 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
203
204
206 protected:
207
208 std::vector<float> m_ratios;
209
210
212 };
213
214
216}
217
219
220#endif // TGUI_BOX_LAYOUT_RATIOS_HPP
Abstract class for box layout containers.
Definition: BoxLayoutRatios.hpp:40
bool remove(std::size_t index) override
Removes a single widget that was added to the container.
void add(const Widget::Ptr &widget, const sf::String &widgetName="") override
Adds a widget at the end of the layout.
bool setRatio(std::size_t index, float ratio)
Changes the ratio of a widget at a certain index.
void insert(std::size_t index, const Widget::Ptr &widget, const sf::String &widgetName="") override
Inserts a widget to the layout.
bool setRatio(Widget::Ptr widget, float ratio)
Changes the ratio of a widget.
float getRatio(Widget::Ptr widget) const
Returns the ratio of a widget at a certain index.
std::shared_ptr< BoxLayoutRatios > Ptr
Shared widget pointer.
Definition: BoxLayoutRatios.hpp:43
void add(const Widget::Ptr &widget, float ratio, const sf::String &widgetName="")
Adds a widget at the end of the layout.
void insert(std::size_t index, const Widget::Ptr &widget, float ratio, const sf::String &widgetName="")
Inserts a widget to the layout.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void removeAllWidgets() override
Removes all widgets that were added to the container.
void addSpace(float ratio)
Add an extra space after the last widget.
std::shared_ptr< const BoxLayoutRatios > ConstPtr
Shared constant widget pointer.
Definition: BoxLayoutRatios.hpp:44
float getRatio(std::size_t index) const
Returns the ratio of a widget at a certain index.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
void insertSpace(std::size_t index, float ratio)
Insert an extra space between widgets.
Abstract class for box layout containers.
Definition: BoxLayout.hpp:41
bool remove(const Widget::Ptr &widget) override
Removes a single widget that was added to the container.
Class to store the position or size of a widget.
Definition: Layout.hpp:260
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37