TGUI  0.9.5
Loading...
Searching...
No Matches
Tabs.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 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_HPP
27#define TGUI_TAB_HPP
28
29
30#include <TGUI/Widget.hpp>
31#include <TGUI/Renderers/TabsRenderer.hpp>
32#include <TGUI/Text.hpp>
33
35
36namespace tgui
37{
44 class TGUI_API Tabs : public Widget
45 {
46 public:
47
48 typedef std::shared_ptr<Tabs> Ptr;
49 typedef std::shared_ptr<const Tabs> ConstPtr;
50
51
59 Tabs(const char* typeName = "Tabs", bool initRenderer = true);
60
61
68 static Tabs::Ptr create();
69
70
80
81
87 const TabsRenderer* getSharedRenderer() const;
88
95 const TabsRenderer* getRenderer() const;
96
97
109 void setSize(const Layout2d& size) override;
110 using Widget::setSize;
111
112
120 void setEnabled(bool enabled) override;
121
122
134 void setAutoSize(bool autoSize);
135
136
143 bool getAutoSize() const;
144
145
157 std::size_t add(const String& text, bool select = true);
158
159
168 void insert(std::size_t index, const String& text, bool select = true);
169
170
179 String getText(std::size_t index) const;
180
181
191 bool changeText(std::size_t index, const String& text);
192
193
203 bool select(const String& text);
204
205
214 bool select(std::size_t index);
215
216
221 void deselect();
222
223
230 bool remove(const String& text);
231
232
240 bool remove(std::size_t index);
241
242
247 void removeAll();
248
249
258
259
269 int getSelectedIndex() const;
270
271
277 void setTabVisible(std::size_t index, bool visible);
278
279
285 bool getTabVisible(std::size_t index) const;
286
287
293 void setTabEnabled(std::size_t index, bool enabled);
294
295
301 bool getTabEnabled(std::size_t index) const;
302
303
311 void setTextSize(unsigned int size) override;
312
313
323 void setTabHeight(float height);
324
325
337 void setMaximumTabWidth(float maximumWidth);
338
339
351 float getMaximumTabWidth() const;
352
353
364 void setMinimumTabWidth(float minimumWidth);
365
366
377 float getMinimumTabWidth() const;
378
379
386 std::size_t getTabsCount() const;
387
388
395 bool isMouseOnWidget(Vector2f pos) const override;
396
400 void leftMousePressed(Vector2f pos) override;
401
405 void mouseMoved(Vector2f pos) override;
406
410 void mouseNoLongerOnWidget() override;
411
412
420 void draw(BackendRenderTargetBase& target, RenderStates states) const override;
421
422
424 protected:
425
435 Signal& getSignal(String signalName) override;
436
437
439 // Recalculates the size of each tab image.
441 void recalculateTabsWidth();
442
443
445 // Update the colors of the text that is drawn on the tabs
447 void updateTextColors();
448
449
456 void rendererChanged(const String& property) override;
457
458
462 std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
463
464
468 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
469
470
472 // Makes a copy of the widget
474 Widget::Ptr clone() const override
475 {
476 return std::make_shared<Tabs>(*this);
477 }
478
479
481 public:
482
483 SignalString onTabSelect = {"TabSelected"};
484
485
487 protected:
488 unsigned int m_requestedTextSize = 0;
489 float m_maximumTabWidth = 0;
490 float m_minimumTabWidth = 0;
491 int m_selectedTab = -1;
492 int m_hoveringTab = -1;
493 bool m_autoSize = true;
494
495 struct Tab
496 {
497 bool visible;
498 bool enabled;
499 float width;
500 Text text;
501 };
502 std::vector<Tab> m_tabs;
503
504 Sprite m_spriteTab;
505 Sprite m_spriteTabHover;
506 Sprite m_spriteSelectedTab;
507 Sprite m_spriteSelectedTabHover;
508 Sprite m_spriteDisabledTab;
509
510 // Cached renderer properties
511 Borders m_bordersCached;
512 Color m_borderColorCached;
513 Color m_borderColorHoverCached;
514 Color m_selectedBorderColorCached;
515 Color m_selectedBorderColorHoverCached;
516 Color m_backgroundColorCached;
517 Color m_backgroundColorHoverCached;
518 Color m_backgroundColorDisabledCached;
519 Color m_selectedBackgroundColorCached;
520 Color m_selectedBackgroundColorHoverCached;
521 Color m_textColorCached;
522 Color m_textColorHoverCached;
523 Color m_textColorDisabledCached;
524 Color m_selectedTextColorCached;
525 Color m_selectedTextColorHoverCached;
526 float m_distanceToSideCached = 0;
527
529 };
530
532}
533
534
536
537#endif // TGUI_TAB_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:63
Class to store the position or size of a widget.
Definition Layout.hpp:262
Definition Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Definition Sprite.hpp:49
Wrapper class to store strings.
Definition String.hpp:79
Definition TabsRenderer.hpp:37
Tabs widget.
Definition Tabs.hpp:45
TabsRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setAutoSize(bool autoSize)
Changes whether the tabs are auto-sized or not.
static Tabs::Ptr create()
Creates a new tabs widget.
std::size_t add(const String &text, bool select=true)
Adds a new tab.
void insert(std::size_t index, const String &text, bool select=true)
Inserts a new tab somewhere between the other tabs.
bool select(std::size_t index)
Selects the tab with a given index.
bool getTabEnabled(std::size_t index) const
Returns whether the tab is enabled or disabled.
void setTabEnabled(std::size_t index, bool enabled)
Changes whether a tab is enabled.
void setEnabled(bool enabled) override
Enables or disables the widget.
String getSelected() const
Gets the text that is drawn on the currently selected tab.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
std::shared_ptr< const Tabs > ConstPtr
Shared constant widget pointer.
Definition Tabs.hpp:49
bool select(const String &text)
Selects the tab with a given text.
bool changeText(std::size_t index, const String &text)
Changes the text of one of the tabs.
static Tabs::Ptr copy(Tabs::ConstPtr tab)
Makes a copy of another tab.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
TabsRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
float getMinimumTabWidth() const
Returns the minimum tab width of the tabs.
void setMaximumTabWidth(float maximumWidth)
Changes the maximum tab width of the tabs.
bool remove(std::size_t index)
Removes a tab with a given index.
void deselect()
Deselects the selected tab.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void setTabHeight(float height)
Changes the height of the tabs.
void setMinimumTabWidth(float minimumWidth)
Changes the minimum tab width of the tabs.
void setSize(const Layout2d &size) override
Changes the area used by the tabs.
int getSelectedIndex() const
Gets the index of the currently selected tab.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition Tabs.hpp:474
bool getAutoSize() const
Returns whether the tabs are auto-sized or not.
std::size_t getTabsCount() const
Returns the amount of tabs.
void draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
bool remove(const String &text)
Removes a tab with a given text.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
void removeAll()
Removes all tabs.
void setTabVisible(std::size_t index, bool visible)
Changes whether a tab is visible.
void setTextSize(unsigned int size) override
Changes the character size of the text.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition Tabs.hpp:48
String getText(std::size_t index) const
Gets the text of one of the tabs.
bool getTabVisible(std::size_t index) const
Returns whether the tab is shown or hidden.
float getMaximumTabWidth() const
Returns the maximum tab width of the tabs.
Definition Text.hpp:44
The parent class for every widget.
Definition Widget.hpp:70
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition Widget.hpp:73
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
States used for drawing.
Definition RenderStates.hpp:39
Definition Tabs.hpp:496