TGUI  0.9-beta
TabContainer.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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 
36 namespace tgui
37 {
44  class TGUI_API TabContainer : public SubwidgetContainer
45  {
46  public:
47 
48  typedef std::shared_ptr<TabContainer> Ptr;
49  typedef std::shared_ptr<const TabContainer> ConstPtr;
50 
51 
53  // Default constructor
55  TabContainer(const tgui::Layout2d& size = { "100%", "100%" });
56 
57 
63  static TabContainer::Ptr create(const tgui::Layout2d& size = { "100%", "100%" });
64 
65 
74 
75 
81  const TabsRenderer* getTabsSharedRenderer() const;
82 
89  const TabsRenderer* getTabsRenderer() const;
90 
91 
97  void setSize(const Layout2d& size) override;
99 
100 
106  void setTabsHeight(Layout height);
107 
108 
116  void addPanel(tgui::Panel::Ptr ptr, const tgui::String& name, bool select = true);
117 
118 
128  bool insertPanel(tgui::Panel::Ptr ptr, const tgui::String& name, std::size_t index, bool select = true);
129 
130 
137 
138 
145  void select(std::size_t index, bool genEvents = true);
146 
147 
153  std::size_t getPanelCount() const;
154 
155 
163 
164 
171 
172 
178  int getSelectedIndex() const;
179 
180 
188 
189 
196 
197 
204  tgui::String getTabText(std::size_t index) const;
205 
206 
215  bool changeTabText(std::size_t index, const tgui::String& text);
216 
218  protected:
219 
221  // Makes a copy of the widget
223  Widget::Ptr clone() const override
224  {
225  return std::make_shared<TabContainer>(*this);
226  }
227 
228 
232  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
233 
234 
236  private:
237 
239  // Helper function that initializes the widget when constructing a new widget or loading one from a file
241  void init();
242 
244  public:
245 
247  SignalInt onSelectionChanged = { "SelectionChanged" };
248 
251  SignalTyped2<int, bool*> onSelectionChanging = { "SelectionChanging" };
252 
253 
255  private:
256  std::vector<tgui::Panel::Ptr> m_panels;
257  int m_index;
258 
259  tgui::Tabs::Ptr m_tabs;
260  };
261 
263 }
264 
266 
267 #endif // TGUI_TAB_CONTAINER_HPP
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
std::size_t getPanelCount() const
Returns the number of holded panels.
tgui::Panel::Ptr getPanel(int index)
Returns the panel with given index.
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition: Tabs.hpp:48
tgui::Panel::Ptr getSelected()
Returns the selected panel or nullptr.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Base class for widgets that consist of subwidgets that act together as if they are a single widget.
Definition: SubwidgetContainer.hpp:43
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: TabContainer.hpp:223
bool insertPanel(tgui::Panel::Ptr ptr, const tgui::String &name, std::size_t index, bool select=true)
Adds a new panel.
tgui::String getTabText(std::size_t index) const
Gets the text of one of the tabs.
std::shared_ptr< const TabContainer > ConstPtr
Shared constant widget pointer.
Definition: TabContainer.hpp:49
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: TabsRenderer.hpp:37
TabsRenderer * getTabsRenderer()
Returns the renderer of tabs part of widget.
std::shared_ptr< TabContainer > Ptr
Shared widget pointer.
Definition: TabContainer.hpp:48
int getSelectedIndex() const
Returns index of the selected panel.
void select(std::size_t index, bool genEvents=true)
Sets selection to panel.
void setTabsHeight(Layout height)
Changes the height of tabs part of the widget.
int getIndex(tgui::Panel::Ptr ptr)
Returns index of the specified panel.
tgui::Tabs::Ptr getTabs()
Returns internal tabs widget.
Wrapper class to store strings.
Definition: String.hpp:74
static TabContainer::Ptr copy(TabContainer::ConstPtr tabContainer)
Makes a copy of another tab container.
TabContainer widget.
Definition: TabContainer.hpp:45
TabsRenderer * getTabsSharedRenderer()
Returns the renderer of tabs part of widget.
void addPanel(tgui::Panel::Ptr ptr, const tgui::String &name, bool select=true)
Adds a new panel.
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition: Panel.hpp:44
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
void removePanel(tgui::Panel::Ptr ptr)
Remove panel specified by pointer.
Class to store the left, top, width or height of a widget.
Definition: Layout.hpp:50
bool changeTabText(std::size_t index, const tgui::String &text)
Changes the text of one of the tabs.
void setSize(const Layout2d &size) override
Changes the size of the tab container.
static TabContainer::Ptr create(const tgui::Layout2d &size={ "100%", "100%" })
Creates a new tab container widget.