TGUI  1.6.1
Loading...
Searching...
No Matches
BoxLayoutRatios.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 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#ifndef TGUI_BOX_LAYOUT_RATIOS_HPP
26#define TGUI_BOX_LAYOUT_RATIOS_HPP
27
28#include <TGUI/Widgets/BoxLayout.hpp>
29
31
32TGUI_MODULE_EXPORT namespace tgui
33{
38 class TGUI_API BoxLayoutRatios : public BoxLayout
39 {
40 public:
41
42 using Ptr = std::shared_ptr<BoxLayoutRatios>;
43 using ConstPtr = std::shared_ptr<const BoxLayoutRatios>;
44
52 BoxLayoutRatios(const char* typeName, bool initRenderer);
53
67 void add(const Widget::Ptr& widget, const String& widgetName = "") override;
68
81 void add(const Widget::Ptr& widget, float ratio, const String& widgetName = "");
82
99 void insert(std::size_t index, const Widget::Ptr& widget, const String& widgetName = "") override;
100
119 void insert(std::size_t index, const Widget::Ptr& widget, float ratio, const String& widgetName = "");
120
128 bool remove(std::size_t index) override;
129 using BoxLayout::remove;
130
134 void removeAllWidgets() override;
135
143 void addSpace(float ratio);
144
153 void insertSpace(std::size_t index, float ratio);
154
166 bool setRatio(const Widget::Ptr& widget, float ratio);
167
179 bool setRatio(std::size_t index, float ratio);
180
188 TGUI_NODISCARD float getRatio(const Widget::Ptr& widget) const;
189
197 TGUI_NODISCARD float getRatio(std::size_t index) const;
198
200 protected:
201
205 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
206
210 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
211
213 protected:
214
215 std::vector<float> m_ratios;
216
218 };
219
221}
222
224
225#endif // TGUI_BOX_LAYOUT_RATIOS_HPP
Abstract class for box layout containers.
Definition BoxLayoutRatios.hpp:39
bool remove(std::size_t index) override
Removes a single widget that was added to the container.
float getRatio(const Widget::Ptr &widget) const
Returns the ratio of a widget at a certain index.
bool setRatio(std::size_t index, float ratio)
Changes the ratio of a widget at a certain index.
void add(const Widget::Ptr &widget, float ratio, const String &widgetName="")
Adds a widget at the end of the layout.
bool setRatio(const Widget::Ptr &widget, float ratio)
Changes the ratio of a widget.
void insert(std::size_t index, const Widget::Ptr &widget, const String &widgetName="") override
Inserts a widget to the layout.
std::shared_ptr< BoxLayoutRatios > Ptr
Shared widget pointer.
Definition BoxLayoutRatios.hpp:42
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.
void insert(std::size_t index, const Widget::Ptr &widget, float ratio, const String &widgetName="")
Inserts a widget to the layout.
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.
std::shared_ptr< const BoxLayoutRatios > ConstPtr
Shared constant widget pointer.
Definition BoxLayoutRatios.hpp:43
void add(const Widget::Ptr &widget, const String &widgetName="") override
Adds a widget at the end of the layout.
Abstract class for box layout containers.
Definition BoxLayout.hpp:40
Wrapper class to store strings.
Definition String.hpp:96
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38