TGUI  0.8-alpha
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 
198  void select(const sf::String& text);
199 
200 
211  void select(std::size_t index);
212 
213 
218  void deselect();
219 
220 
231  void remove(const sf::String& text);
232 
233 
244  void remove(std::size_t index);
245 
246 
251  void removeAll();
252 
253 
261  sf::String getSelected() const;
262 
263 
273  int getSelectedIndex() const;
274 
275 
281  void setTabVisible(std::size_t index, bool visible);
282 
283 
289  bool getTabVisible(std::size_t index) const;
290 
291 
297  void setTabEnabled(std::size_t index, bool enabled);
298 
299 
305  bool getTabEnabled(std::size_t index) const;
306 
307 
315  void setTextSize(unsigned int size);
316 
317 
324  unsigned int getTextSize() const;
325 
326 
336  void setTabHeight(float height);
337 
338 
350  void setMaximumTabWidth(float maximumWidth);
351 
352 
364  float getMaximumTabWidth() const;
365 
366 
377  void setMinimumTabWidth(float minimumWidth);
378 
379 
390  float getMinimumTabWidth() const;
391 
392 
399  std::size_t getTabsCount() const;
400 
401 
408  bool mouseOnWidget(Vector2f pos) const override;
409 
413  void leftMousePressed(Vector2f pos) override;
414 
418  void mouseMoved(Vector2f pos) override;
419 
423  void mouseNoLongerOnWidget() override;
424 
425 
433  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
434 
435 
437  protected:
438 
448  Signal& getSignal(std::string signalName) override;
449 
450 
452  // Recalculates the size of each tab image.
454  void recalculateTabsWidth();
455 
456 
458  // Update the colors of the text that is drawn on the tabs
460  void updateTextColors();
461 
462 
469  void rendererChanged(const std::string& property) override;
470 
471 
475  std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
476 
477 
481  void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
482 
483 
485  // Makes a copy of the widget
487  Widget::Ptr clone() const override
488  {
489  return std::make_shared<Tabs>(*this);
490  }
491 
492 
494  public:
495 
496  SignalString onTabSelect = {"TabSelected"};
497 
498 
500  protected:
501  unsigned int m_requestedTextSize = 0;
502  unsigned int m_textSize = 22;
503  float m_maximumTabWidth = 0;
504  float m_minimumTabWidth = 0;
505  int m_selectedTab = -1;
506  int m_hoveringTab = -1;
507  bool m_autoSize = true;
508 
509  struct Tab
510  {
511  bool visible;
512  bool enabled;
513  float width;
514  Text text;
515  };
516  std::vector<Tab> m_tabs;
517 
518  Sprite m_spriteTab;
519  Sprite m_spriteSelectedTab;
520  Sprite m_spriteDisabledTab;
521 
522  // Cached renderer properties
523  Borders m_bordersCached;
524  Color m_borderColorCached;
525  Color m_backgroundColorCached;
526  Color m_backgroundColorHoverCached;
527  Color m_backgroundColorDisabledCached;
528  Color m_selectedBackgroundColorCached;
529  Color m_selectedBackgroundColorHoverCached;
530  Color m_textColorCached;
531  Color m_textColorHoverCached;
532  Color m_textColorDisabledCached;
533  Color m_selectedTextColorCached;
534  Color m_selectedTextColorHoverCached;
535  float m_distanceToSideCached = 0;
536 
538  };
539 
541 }
542 
543 
545 
546 #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:243
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:58
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:487
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:509