TGUI  1.3-dev
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
26#ifndef TGUI_TAB_CONTAINER_HPP
27#define TGUI_TAB_CONTAINER_HPP
28
29
30#include <TGUI/SubwidgetContainer.hpp>
31#include <TGUI/Widgets/Tabs.hpp>
32#include <TGUI/Widgets/Panel.hpp>
33
35
36TGUI_MODULE_EXPORT namespace tgui
37{
46 class TGUI_API TabContainer : public Container
47 {
48 public:
49
50 using Ptr = std::shared_ptr<TabContainer>;
51 using ConstPtr = std::shared_ptr<const TabContainer>;
52
53 static constexpr const char StaticWidgetType[] = "TabContainer";
54
55
60 {
61 Top = 0,
62 Bottom = 1 << 0
63 };
64
65
73 TabContainer(const char* typeName = StaticWidgetType, bool initRenderer = true);
74
75
80
81
85 TabContainer(TabContainer&& copy) noexcept;
86
87
91 TabContainer& operator= (const TabContainer& right);
92
93
97 TabContainer& operator= (TabContainer&& right) noexcept;
98
99
105 TGUI_NODISCARD static TabContainer::Ptr create(const Layout2d& size = { "100%", "100%" });
106
107
115 TGUI_NODISCARD static TabContainer::Ptr copy(const TabContainer::ConstPtr& tabContainer);
116
117
123 TGUI_NODISCARD const TabsRenderer* getTabsSharedRenderer() const;
124
130 TGUI_NODISCARD TabsRenderer* getTabsRenderer();
131
132
138 void setSize(const Layout2d& size) override;
139 using Container::setSize;
140
141
147 void setTabsHeight(const Layout& height);
148
149
158 Panel::Ptr addTab(const String& name, bool select = true);
159
160
170 Panel::Ptr insertTab(std::size_t index, const String& name, bool select = true);
171
172
182 bool removeTab(const String& text);
183
184
194 bool removeTab(std::size_t index);
195
196
202 void select(std::size_t index);
203
204
210 TGUI_NODISCARD std::size_t getPanelCount() const;
211
212
220 TGUI_NODISCARD int getIndex(const Panel::Ptr& panel);
221
222
228 TGUI_NODISCARD Panel::Ptr getSelected();
229
230
236 TGUI_NODISCARD int getSelectedIndex() const;
237
238
245 TGUI_NODISCARD Panel::Ptr getPanel(int index);
246
247
253 TGUI_NODISCARD Tabs::Ptr getTabs();
254
255
262 TGUI_NODISCARD String getTabText(std::size_t index) const;
263
264
273 bool changeTabText(std::size_t index, const String& text);
274
275
285
286
293
294
304 void setTabFixedSize(float fixedSize);
305
306
312 TGUI_NODISCARD float getTabFixedSize() const;
313
314
320 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
321
322
324 protected:
325
335 TGUI_NODISCARD Signal& getSignal(String signalName) override;
336
337
341 TGUI_NODISCARD Widget::Ptr clone() const override;
342
343
347 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
348
349
353 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
354
355
357 private:
358
359 void init(); // Helper function that initializes the widget when constructing a new widget or loading one from a file
360
361 void layoutTabs(); // Helper function that sets position and size of the tabs according to the tab alignment
362
363 void layoutPanel(const Panel::Ptr& panel); // Helper function that sets position of a panel according to the tab alignment
364
365
367 public:
368
370 SignalInt onSelectionChange = {"SelectionChanged"};
371
374 SignalTyped2<int, bool*> onSelectionChanging = {"SelectionChanging"};
375
376
378 private:
379
380 std::vector<Panel::Ptr> m_panels; // Stores the tab panels.
381
382 Panel::Ptr m_selectedPanel = nullptr; // Stores the panel belonging to the selected tab
383
384 Tabs::Ptr m_tabs = Tabs::create(); // Stores the tabs.
385
386 TabContainer::TabAlign m_tabAlign = TabContainer::TabAlign::Top; // Stores the tab alignment.
387
388 float m_tabFixedSize = 0.0f; // Stores the tab fixed size for fixed size alignment, default is 0.0f.
389 };
390
392}
393
395
396#endif // TGUI_TAB_CONTAINER_HPP
Container widget.
Definition Container.hpp:49
Class to store the position or size of a widget.
Definition Layout.hpp:305
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:70
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:44
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:375
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
TabContainer widget.
Definition TabContainer.hpp:47
static TGUI_NODISCARD TabContainer::Ptr create(const Layout2d &size={ "100%", "100%" })
Creates a new tab container widget.
std::shared_ptr< TabContainer > Ptr
Shared widget pointer.
Definition TabContainer.hpp:50
TGUI_NODISCARD int getSelectedIndex() const
Returns index of the selected panel.
bool changeTabText(std::size_t index, const String &text)
Changes the text of one of the tabs.
TGUI_NODISCARD 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.
TabContainer(TabContainer &&copy) noexcept
Move constructor.
bool removeTab(std::size_t index)
Removes a tab and its corresponding panel with a given index.
TGUI_NODISCARD String getTabText(std::size_t index) const
Gets the text of one of the tabs.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the 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.
TGUI_NODISCARD TabContainer::TabAlign getTabAlignment() const
Returns the alignment of the tabs.
TabContainer(const TabContainer &copy)
Copy constructor.
TGUI_NODISCARD TabsRenderer * getTabsSharedRenderer()
Returns the renderer of tabs part of widget.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget.
void setTabFixedSize(float fixedSize)
Changes the tab fixed size for fixed size alignment.
TGUI_NODISCARD TabsRenderer * getTabsRenderer()
Returns the renderer of tabs part of widget.
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.
static TGUI_NODISCARD TabContainer::Ptr copy(const TabContainer::ConstPtr &tabContainer)
Makes a copy of another tab container.
Panel::Ptr insertTab(std::size_t index, const String &name, bool select=true)
Inserts a new tab and panel somewhere between the existing ones.
TGUI_NODISCARD int getIndex(const Panel::Ptr &panel)
Returns index of the specified panel.
std::shared_ptr< const TabContainer > ConstPtr
Shared constant widget pointer.
Definition TabContainer.hpp:51
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
TGUI_NODISCARD Panel::Ptr getPanel(int index)
Returns the panel with given index.
void select(std::size_t index)
Sets selection to panel.
TGUI_NODISCARD Panel::Ptr getSelected()
Returns the selected panel or nullptr.
void setSize(const Layout2d &size) override
Changes the size of the tab container.
void setTabAlignment(TabContainer::TabAlign align)
Changes the alignment of the tabs.
TabAlign
Enumeration of the tab alignments for tabs.
Definition TabContainer.hpp:60
TGUI_NODISCARD float getTabFixedSize() const
Returns the tab fixed size for fixed size alignment, default is 0.0f.
TGUI_NODISCARD Tabs::Ptr getTabs()
Returns internal tabs widget.
TGUI_NODISCARD std::size_t getPanelCount() const
Returns the number of holded panels.
Definition TabsRenderer.hpp:37
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition Tabs.hpp:48
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:87
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39