TGUI  1.6.1
Loading...
Searching...
No Matches
TabContainer.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_TAB_CONTAINER_HPP
26#define TGUI_TAB_CONTAINER_HPP
27
28#include <TGUI/SubwidgetContainer.hpp>
29#include <TGUI/Widgets/Tabs.hpp>
30#include <TGUI/Widgets/Panel.hpp>
31
33
34TGUI_MODULE_EXPORT namespace tgui
35{
44 class TGUI_API TabContainer : public Container
45 {
46 public:
47
48 using Ptr = std::shared_ptr<TabContainer>;
49 using ConstPtr = std::shared_ptr<const TabContainer>;
50
51 static constexpr const char StaticWidgetType[] = "TabContainer";
52
56 enum class TabAlign
57 {
58 Top = 0,
59 Bottom = 1 << 0
60 };
61
69 TabContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
70
75
79 TabContainer(TabContainer&& copy) noexcept;
80
84 TabContainer& operator= (const TabContainer& right);
85
89 TabContainer& operator= (TabContainer&& right) noexcept;
90
96 TGUI_NODISCARD static TabContainer::Ptr create(const Layout2d& size = { "100%", "100%" });
97
105 TGUI_NODISCARD static TabContainer::Ptr copy(const TabContainer::ConstPtr& tabContainer);
106
112 TGUI_NODISCARD const TabsRenderer* getTabsSharedRenderer() const;
113
119 TGUI_NODISCARD TabsRenderer* getTabsRenderer();
120
126 void setSize(const Layout2d& size) override;
127 using Container::setSize;
128
134 void setTabsHeight(const Layout& height);
135
144 Panel::Ptr addTab(const String& name, bool select = true);
145
155 Panel::Ptr insertTab(std::size_t index, const String& name, bool select = true);
156
166 bool removeTab(const String& text);
167
177 bool removeTab(std::size_t index);
178
184 void select(std::size_t index);
185
191 TGUI_NODISCARD std::size_t getPanelCount() const;
192
200 TGUI_NODISCARD int getIndex(const Panel::Ptr& panel);
201
207 TGUI_NODISCARD Panel::Ptr getSelected() const;
208
214 TGUI_NODISCARD int getSelectedIndex() const;
215
222 TGUI_NODISCARD Panel::Ptr getPanel(int index) const;
223
229 TGUI_NODISCARD Tabs::Ptr getTabs() const;
230
237 TGUI_NODISCARD String getTabText(std::size_t index) const;
238
247 bool changeTabText(std::size_t index, const String& text);
248
258
264 TGUI_NODISCARD TabAlign getTabAlignment() const;
265
275 void setTabFixedSize(float fixedSize);
276
282 TGUI_NODISCARD float getTabFixedSize() const;
283
289 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
290
292 protected:
293
303 TGUI_NODISCARD Signal& getSignal(String signalName) override;
304
308 TGUI_NODISCARD Widget::Ptr clone() const override;
309
313 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
314
318 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
319
321 private:
322
323 void init(); // Helper function that initializes the widget when constructing a new widget or loading one from a file
324
325 void layoutTabs(); // Helper function that sets position and size of the tabs according to the tab alignment
326
327 void layoutPanel(const Panel::Ptr& panel); // Helper function that sets position of a panel according to the tab alignment
328
330 public:
331
333 SignalInt onSelectionChange = {"SelectionChanged"};
334
337 SignalTyped2<int, bool*> onSelectionChanging = {"SelectionChanging"};
338
340 private:
341
342 std::vector<Panel::Ptr> m_panels; // Stores the tab panels.
343
344 Panel::Ptr m_selectedPanel = nullptr; // Stores the panel belonging to the selected tab
345
346 Tabs::Ptr m_tabs = Tabs::create(); // Stores the tabs.
347
348 TabAlign m_tabAlign = TabAlign::Top; // Stores the tab alignment.
349
350 float m_tabFixedSize = 0.0f; // Stores the tab fixed size for fixed size alignment, default is 0.0f.
351 };
352
354}
355
357
358#endif // TGUI_TAB_CONTAINER_HPP
Container widget.
Definition Container.hpp:48
Class to store the position or size of a widget.
Definition Layout.hpp:323
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:102
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:42
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:350
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
TabContainer widget.
Definition TabContainer.hpp:45
std::shared_ptr< TabContainer > Ptr
Shared widget pointer.
Definition TabContainer.hpp:48
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.
TabContainer(TabContainer &&copy) noexcept
Move constructor.
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.
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.
static TabContainer::Ptr create(const Layout2d &size={ "100%", "100%" })
Creates a new tab container widget.
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.
void setTabsHeight(const Layout &height)
Changes the height of tabs part of the widget.
TabContainer(const TabContainer &copy)
Copy constructor.
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.
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:49
Panel::Ptr getPanel(int index) const
Returns the panel with given index.
void select(std::size_t index)
Sets selection to panel.
void setSize(const Layout2d &size) override
Changes the size of the tab container.
TabAlign
Enumeration of the tab alignments for tabs.
Definition TabContainer.hpp:57
Tabs::Ptr getTabs() const
Returns internal tabs widget.
TabAlign getTabAlignment() const
Returns the alignment of the tabs.
Definition TabsRenderer.hpp:35
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition Tabs.hpp:46
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:86
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38