TGUI 1.13
Loading...
Searching...
No Matches
TabContainer.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 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_TAB_CONTAINER_HPP
26#define TGUI_TAB_CONTAINER_HPP
27
28#include <TGUI/SubwidgetContainer.hpp>
29#include <TGUI/Widgets/Panel.hpp>
30#include <TGUI/Widgets/Tabs.hpp>
31
33
34namespace tgui
35{
44 class TGUI_API TabContainer : public Container
45 {
46 public:
47 using Ptr = std::shared_ptr<TabContainer>;
48 using ConstPtr = std::shared_ptr<const TabContainer>;
49
50 static constexpr char StaticWidgetType[] = "TabContainer";
51
55 enum class TabAlign : std::uint8_t
56 {
57 Top = 0,
58 Bottom = 1 << 0
59 };
60
68 explicit TabContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
69
73 TabContainer(const TabContainer& other);
74
78 TabContainer(TabContainer&& other) noexcept;
79
83 TabContainer& operator=(const TabContainer& other);
84
88 TabContainer& operator=(TabContainer&& other) noexcept;
89
95 [[nodiscard]] static TabContainer::Ptr create(const Layout2d& size = {"100%", "100%"});
96
104 [[nodiscard]] static TabContainer::Ptr copy(const TabContainer::ConstPtr& tabContainer);
105
111 [[nodiscard]] const TabsRenderer* getTabsSharedRenderer() const;
112
119
125 void setSize(const Layout2d& size) override;
126 using Container::setSize;
127
133 void setTabsHeight(const Layout& height);
134
143 Panel::Ptr addTab(const String& name, bool select = true);
144
154 Panel::Ptr insertTab(std::size_t index, const String& name, bool select = true);
155
165 bool removeTab(const String& text);
166
176 bool removeTab(std::size_t index);
177
183 void select(std::size_t index);
184
190 [[nodiscard]] std::size_t getPanelCount() const;
191
199 [[nodiscard]] int getIndex(const Panel::Ptr& panel);
200
206 [[nodiscard]] Panel::Ptr getSelected() const;
207
213 [[nodiscard]] int getSelectedIndex() const;
214
221 [[nodiscard]] Panel::Ptr getPanel(int index) const;
222
228 [[nodiscard]] Tabs::Ptr getTabs() const;
229
236 [[nodiscard]] String getTabText(std::size_t index) const;
237
246 bool changeTabText(std::size_t index, const String& text);
247
257
263 [[nodiscard]] TabAlign getTabAlignment() const;
264
274 void setTabFixedSize(float fixedSize);
275
281 [[nodiscard]] float getTabFixedSize() const;
282
288 [[nodiscard]] bool isMouseOnWidget(Vector2f pos) const override;
289
291
292 protected:
302 [[nodiscard]] Signal& getSignal(String signalName) override;
303
307 [[nodiscard]] Widget::Ptr clone() const override;
308
312 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
313
317 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
318
320
321 private:
322 void init(); // Helper function that initializes the widget when constructing a new widget or loading one from a file
323
324 void layoutTabs(); // Helper function that sets position and size of the tabs according to the tab alignment
325
326 void layoutPanel(const Panel::Ptr& panel); // Helper function that sets position of a panel according to the tab alignment
327
329
330 public:
332 SignalInt onSelectionChange = {"SelectionChanged"};
333
337
339
340 private:
341 std::vector<Panel::Ptr> m_panels; // Stores the tab panels.
342
343 Panel::Ptr m_selectedPanel = nullptr; // Stores the panel belonging to the selected tab
344
345 Tabs::Ptr m_tabs = Tabs::create(); // Stores the tabs.
346
347 TabAlign m_tabAlign = TabAlign::Top; // Stores the tab alignment.
348
349 float m_tabFixedSize = 0.0f; // Stores the tab fixed size for fixed size alignment, default is 0.0f.
350 };
351} // namespace tgui
352
353#endif // TGUI_TAB_CONTAINER_HPP
void setSize(const Layout2d &size) override
Changes the size of the container.
Class to store the position or size of a widget.
Definition Layout.hpp:320
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:100
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:41
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:332
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
TabContainer widget.
Definition TabContainer.hpp:45
SignalTyped2< int, bool * > onSelectionChanging
Definition TabContainer.hpp:336
std::shared_ptr< TabContainer > Ptr
Shared widget pointer.
Definition TabContainer.hpp:47
TabContainer & operator=(const TabContainer &other)
Overload of copy assignment operator.
TabContainer & operator=(TabContainer &&other) noexcept
Overload of move assignment operator.
Panel::Ptr getSelected() const
Returns the selected panel or nullptr.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
bool changeTabText(std::size_t index, const String &text)
Changes the text of one of the tabs.
int getSelectedIndex() const
Returns index of the selected panel.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
static TabContainer::Ptr create(const Layout2d &size={"100%", "100%"})
Creates a new tab container widget.
TabsRenderer * getTabsRenderer()
Returns the renderer of tabs part of widget.
bool removeTab(std::size_t index)
Removes a tab and its corresponding panel with a given index.
TabContainer(const TabContainer &other)
Copy constructor.
std::size_t getPanelCount() const
Returns the number of holded panels.
String getTabText(std::size_t index) const
Gets the text of one of the tabs.
TabsRenderer * getTabsSharedRenderer()
Returns the renderer of tabs part of widget.
Panel::Ptr addTab(const String &name, bool select=true)
Adds a new tab and corresponding panel.
TabContainer(TabContainer &&other) noexcept
Move constructor.
void setTabsHeight(const Layout &height)
Changes the height of tabs part of the widget.
void setTabAlignment(TabAlign align)
Changes the alignment of the tabs.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree of nodes in order to save it to a file.
static TabContainer::Ptr copy(const TabContainer::ConstPtr &tabContainer)
Makes a copy of another tab container.
float getTabFixedSize() const
Returns the tab fixed size for fixed size alignment, default is 0.0f.
Widget::Ptr clone() const override
Makes a copy of the widget.
void setTabFixedSize(float fixedSize)
Changes the tab fixed size for fixed size alignment.
int getIndex(const Panel::Ptr &panel)
Returns index of the specified panel.
bool removeTab(const String &text)
Removes a tab and its corresponding panel, given the text of the tab.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
SignalInt onSelectionChange
Selection of the tab container changed. Optional parameter: index of panel with selection.
Definition TabContainer.hpp:332
Panel::Ptr insertTab(std::size_t index, const String &name, bool select=true)
Inserts a new tab and panel somewhere between the existing ones.
std::shared_ptr< const TabContainer > ConstPtr
Shared constant widget pointer.
Definition TabContainer.hpp:48
Panel::Ptr getPanel(int index) const
Returns the panel with given index.
void select(std::size_t index)
Sets selection to panel.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition TabContainer.hpp:50
void setSize(const Layout2d &size) override
Changes the size of the tab container.
Tabs::Ptr getTabs() const
Returns internal tabs widget.
TabAlign getTabAlignment() const
Returns the alignment of the tabs.
TabAlign
Enumeration of the tab alignments for tabs.
Definition TabContainer.hpp:56
Definition TabsRenderer.hpp:35
static Tabs::Ptr create()
Creates a new tabs widget.
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition Tabs.hpp:46
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:85
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
SignalTyped< int > SignalInt
Signal with one "int" as optional unbound parameter.
Definition Signal.hpp:408