TGUI 1.x-dev
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/Widgets/Panel.hpp>
29#include <TGUI/Widgets/Tabs.hpp>
30
32
33namespace tgui
34{
43 class TGUI_API TabContainer : public Container
44 {
45 public:
46 using Ptr = std::shared_ptr<TabContainer>;
47 using ConstPtr = std::shared_ptr<const TabContainer>;
48
49 static constexpr char StaticWidgetType[] = "TabContainer";
50
54 enum class TabAlign : std::uint8_t
55 {
56 Top = 0,
57 Bottom = 1 << 0
58 };
59
67 explicit TabContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
68
72 TabContainer(const TabContainer& other);
73
77 TabContainer(TabContainer&& other) noexcept;
78
82 TabContainer& operator=(const TabContainer& other);
83
87 TabContainer& operator=(TabContainer&& other) noexcept;
88
94 [[nodiscard]] static TabContainer::Ptr create(const Layout2d& size = {"100%", "100%"});
95
103 [[nodiscard]] static TabContainer::Ptr copy(const TabContainer::ConstPtr& tabContainer);
104
110 [[nodiscard]] const TabsRenderer* getTabsSharedRenderer() const;
111
118
124 void setSize(const Layout2d& size) override;
125 using Container::setSize;
126
132 void setTabsHeight(const Layout& height);
133
142 Panel::Ptr addTab(const String& name, bool select = true);
143
153 Panel::Ptr insertTab(std::size_t index, const String& name, bool select = true);
154
164 bool removeTab(const String& text);
165
175 bool removeTab(std::size_t index);
176
182 void select(std::size_t index);
183
189 [[nodiscard]] std::size_t getPanelCount() const;
190
198 [[nodiscard]] int getIndex(const Panel::Ptr& panel);
199
205 [[nodiscard]] Panel::Ptr getSelected() const;
206
212 [[nodiscard]] int getSelectedIndex() const;
213
220 [[nodiscard]] Panel::Ptr getPanel(int index) const;
221
227 [[nodiscard]] Tabs::Ptr getTabs() const;
228
235 [[nodiscard]] String getTabText(std::size_t index) const;
236
245 bool changeTabText(std::size_t index, const String& text);
246
256
262 [[nodiscard]] TabAlign getTabAlignment() const;
263
273 void setTabFixedSize(float fixedSize);
274
280 [[nodiscard]] float getTabFixedSize() const;
281
287 [[nodiscard]] bool isMouseOnWidget(Vector2f pos) const override;
288
290
291 protected:
301 [[nodiscard]] Signal& getSignal(String signalName) override;
302
306 [[nodiscard]] Widget::Ptr clone() const override;
307
311 [[nodiscard]] std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
312
316 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
317
319
320 private:
321 void init(); // Helper function that initializes the widget when constructing a new widget or loading one from a file
322
323 void layoutTabs(); // Helper function that sets position and size of the tabs according to the tab alignment
324
325 void layoutPanel(const Panel::Ptr& panel); // Helper function that sets position of a panel according to the tab alignment
326
328
329 public:
331 SignalInt onSelectionChange = {"SelectionChanged"};
332
336
338
339 private:
340 std::vector<Panel::Ptr> m_panels; // Stores the tab panels.
341
342 Panel::Ptr m_selectedPanel = nullptr; // Stores the panel belonging to the selected tab
343
344 Tabs::Ptr m_tabs = Tabs::create(); // Stores the tabs.
345
346 TabAlign m_tabAlign = TabAlign::Top; // Stores the tab alignment.
347
348 float m_tabFixedSize = 0.0f; // Stores the tab fixed size for fixed size alignment, default is 0.0f.
349 };
350} // namespace tgui
351
352#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:44
SignalTyped2< int, bool * > onSelectionChanging
Definition TabContainer.hpp:335
std::shared_ptr< TabContainer > Ptr
Shared widget pointer.
Definition TabContainer.hpp:46
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:331
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:47
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:49
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:55
Definition TabsRenderer.hpp:35
static Tabs::Ptr create()
Creates a new tabs widget.
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition Tabs.hpp:45
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