TGUI  0.8.7
Tabs.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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 
36 namespace tgui
37 {
41  class TGUI_API Tabs : public Widget
42  {
43  public:
44 
45  typedef std::shared_ptr<Tabs> Ptr;
46  typedef std::shared_ptr<const Tabs> ConstPtr;
47 
48 
50  // Default constructor
52  Tabs();
53 
54 
61  static Tabs::Ptr create();
62 
63 
72  static Tabs::Ptr copy(Tabs::ConstPtr tab);
73 
74 
79  TabsRenderer* getSharedRenderer();
80  const TabsRenderer* getSharedRenderer() const;
81 
87  TabsRenderer* getRenderer();
88  const TabsRenderer* getRenderer() const;
89 
90 
102  void setSize(const Layout2d& size) override;
103  using Widget::setSize;
104 
105 
113  void setEnabled(bool enabled) override;
114 
115 
127  void setAutoSize(bool autoSize);
128 
129 
136  bool getAutoSize() const;
137 
138 
150  std::size_t add(const sf::String& text, bool select = true);
151 
152 
161  void insert(std::size_t index, const sf::String& text, bool select = true);
162 
163 
172  sf::String getText(std::size_t index) const;
173 
174 
184  bool changeText(std::size_t index, const sf::String& text);
185 
186 
196  bool select(const sf::String& text);
197 
198 
207  bool select(std::size_t index);
208 
209 
214  void deselect();
215 
216 
223  bool remove(const sf::String& text);
224 
225 
233  bool remove(std::size_t index);
234 
235 
240  void removeAll();
241 
242 
250  sf::String getSelected() const;
251 
252 
262  int getSelectedIndex() const;
263 
264 
270  void setTabVisible(std::size_t index, bool visible);
271 
272 
278  bool getTabVisible(std::size_t index) const;
279 
280 
286  void setTabEnabled(std::size_t index, bool enabled);
287 
288 
294  bool getTabEnabled(std::size_t index) const;
295 
296 
304  void setTextSize(unsigned int size) override;
305 
306 
316  void setTabHeight(float height);
317 
318 
330  void setMaximumTabWidth(float maximumWidth);
331 
332 
344  float getMaximumTabWidth() const;
345 
346 
357  void setMinimumTabWidth(float minimumWidth);
358 
359 
370  float getMinimumTabWidth() const;
371 
372 
379  std::size_t getTabsCount() const;
380 
381 
388  bool mouseOnWidget(Vector2f pos) const override;
389 
393  void leftMousePressed(Vector2f pos) override;
394 
398  void mouseMoved(Vector2f pos) override;
399 
403  void mouseNoLongerOnWidget() override;
404 
405 
413  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
414 
415 
417  protected:
418 
428  Signal& getSignal(std::string signalName) override;
429 
430 
432  // Recalculates the size of each tab image.
434  void recalculateTabsWidth();
435 
436 
438  // Update the colors of the text that is drawn on the tabs
440  void updateTextColors();
441 
442 
449  void rendererChanged(const std::string& property) override;
450 
451 
455  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
456 
457 
461  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
462 
463 
465  // Makes a copy of the widget
467  Widget::Ptr clone() const override
468  {
469  return std::make_shared<Tabs>(*this);
470  }
471 
472 
474  public:
475 
476  SignalString onTabSelect = {"TabSelected"};
477 
478 
480  protected:
481  unsigned int m_requestedTextSize = 0;
482  float m_maximumTabWidth = 0;
483  float m_minimumTabWidth = 0;
484  int m_selectedTab = -1;
485  int m_hoveringTab = -1;
486  bool m_autoSize = true;
487 
488  struct Tab
489  {
490  bool visible;
491  bool enabled;
492  float width;
493  Text text;
494  };
495  std::vector<Tab> m_tabs;
496 
497  Sprite m_spriteTab;
498  Sprite m_spriteTabHover;
499  Sprite m_spriteSelectedTab;
500  Sprite m_spriteSelectedTabHover;
501  Sprite m_spriteDisabledTab;
502 
503  // Cached renderer properties
504  Borders m_bordersCached;
505  Color m_borderColorCached;
506  Color m_backgroundColorCached;
507  Color m_backgroundColorHoverCached;
508  Color m_backgroundColorDisabledCached;
509  Color m_selectedBackgroundColorCached;
510  Color m_selectedBackgroundColorHoverCached;
511  Color m_textColorCached;
512  Color m_textColorHoverCached;
513  Color m_textColorDisabledCached;
514  Color m_selectedTextColorCached;
515  Color m_selectedTextColorHoverCached;
516  float m_distanceToSideCached = 0;
517 
519  };
520 
522 }
523 
524 
526 
527 #endif // TGUI_TAB_HPP
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:220
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition: Tabs.hpp:45
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:77
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Text.hpp:42
Class to store the position or size of a widget.
Definition: Layout.hpp:258
Definition: TabsRenderer.hpp:36
Wrapper for colors.
Definition: Color.hpp:48
std::shared_ptr< const Tabs > ConstPtr
Shared constant widget pointer.
Definition: Tabs.hpp:46
Definition: Sprite.hpp:45
Definition: Vector2f.hpp:38
Definition: Outline.hpp:38
The parent class for every widget.
Definition: Widget.hpp:73
Definition: Tabs.hpp:488
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Tabs widget.
Definition: Tabs.hpp:41
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: Tabs.hpp:467