TGUI  0.8.1
Tabs.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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);
305 
306 
313  unsigned int getTextSize() const;
314 
315 
325  void setTabHeight(float height);
326 
327 
339  void setMaximumTabWidth(float maximumWidth);
340 
341 
353  float getMaximumTabWidth() const;
354 
355 
366  void setMinimumTabWidth(float minimumWidth);
367 
368 
379  float getMinimumTabWidth() const;
380 
381 
388  std::size_t getTabsCount() const;
389 
390 
397  bool mouseOnWidget(Vector2f pos) const override;
398 
402  void leftMousePressed(Vector2f pos) override;
403 
407  void mouseMoved(Vector2f pos) override;
408 
412  void mouseNoLongerOnWidget() override;
413 
414 
422  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
423 
424 
426  protected:
427 
437  Signal& getSignal(std::string signalName) override;
438 
439 
441  // Recalculates the size of each tab image.
443  void recalculateTabsWidth();
444 
445 
447  // Update the colors of the text that is drawn on the tabs
449  void updateTextColors();
450 
451 
458  void rendererChanged(const std::string& property) override;
459 
460 
464  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
465 
466 
470  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
471 
472 
474  // Makes a copy of the widget
476  Widget::Ptr clone() const override
477  {
478  return std::make_shared<Tabs>(*this);
479  }
480 
481 
483  public:
484 
485  SignalString onTabSelect = {"TabSelected"};
486 
487 
489  protected:
490  unsigned int m_requestedTextSize = 0;
491  unsigned int m_textSize = 22;
492  float m_maximumTabWidth = 0;
493  float m_minimumTabWidth = 0;
494  int m_selectedTab = -1;
495  int m_hoveringTab = -1;
496  bool m_autoSize = true;
497 
498  struct Tab
499  {
500  bool visible;
501  bool enabled;
502  float width;
503  Text text;
504  };
505  std::vector<Tab> m_tabs;
506 
507  Sprite m_spriteTab;
508  Sprite m_spriteTabHover;
509  Sprite m_spriteSelectedTab;
510  Sprite m_spriteSelectedTabHover;
511  Sprite m_spriteDisabledTab;
512 
513  // Cached renderer properties
514  Borders m_bordersCached;
515  Color m_borderColorCached;
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
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:43
Wrapper for colors.
Definition: Color.hpp:47
Class to store the position or size of a widget.
Definition: Layout.hpp:245
The parent class for every widget.
Definition: Widget.hpp:72
Definition: Vector2f.hpp:37
std::shared_ptr< const Tabs > ConstPtr
Shared constant widget pointer.
Definition: Tabs.hpp:46
Definition: Text.hpp:42
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
Definition: Outline.hpp:38
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Tabs.hpp:476
Definition: TabsRenderer.hpp:36
Tabs widget.
Definition: Tabs.hpp:41
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition: Tabs.hpp:45
Definition: Tabs.hpp:498