TGUI  0.8-dev
Tabs.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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 
117  void setAutoSize(bool autoSize);
118 
119 
126  bool getAutoSize() const;
127 
128 
140  std::size_t add(const sf::String& text, bool select = true);
141 
142 
151  void insert(std::size_t index, const sf::String& text, bool select = true);
152 
153 
162  sf::String getText(std::size_t index) const;
163 
164 
174  bool changeText(std::size_t index, const sf::String& text);
175 
176 
188  void select(const sf::String& text);
189 
190 
201  void select(std::size_t index);
202 
203 
208  void deselect();
209 
210 
221  void remove(const sf::String& text);
222 
223 
234  void remove(std::size_t index);
235 
236 
241  void removeAll();
242 
243 
251  sf::String getSelected() const;
252 
253 
263  int getSelectedIndex() const;
264 
265 
273  void setTextSize(unsigned int size);
274 
275 
282  unsigned int getTextSize() const;
283 
284 
294  void setTabHeight(float height);
295 
296 
308  void setMaximumTabWidth(float maximumWidth);
309 
310 
322  float getMaximumTabWidth() const;
323 
324 
335  void setMinimumTabWidth(float minimumWidth);
336 
337 
348  float getMinimumTabWidth() const;
349 
350 
357  std::size_t getTabsCount() const;
358 
359 
366  bool mouseOnWidget(sf::Vector2f pos) const override;
367 
371  void leftMousePressed(sf::Vector2f pos) override;
372 
376  void mouseMoved(sf::Vector2f pos) override;
377 
381  void mouseNoLongerOnWidget() override;
382 
383 
391  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
392 
393 
395  protected:
396 
406  Signal& getSignal(std::string signalName) override;
407 
408 
410  // Recalculates the size of each tab image.
412  void recalculateTabsWidth();
413 
414 
416  // Update the colors of the text that is drawn on the tabs
418  void updateTextColors();
419 
420 
427  void rendererChanged(const std::string& property) override;
428 
429 
431  // Makes a copy of the widget
433  Widget::Ptr clone() const override
434  {
435  return std::make_shared<Tabs>(*this);
436  }
437 
438 
440  public:
441 
442  SignalString onTabSelect = {"TabSelected"};
443 
444 
446  protected:
447  unsigned int m_requestedTextSize = 0;
448  unsigned int m_textSize = 22;
449  float m_maximumTabWidth = 0;
450  float m_minimumTabWidth = 0;
451  int m_selectedTab = -1;
452  int m_hoveringTab = -1;
453  bool m_autoSize = true;
454  std::vector<float> m_tabWidth;
455  std::vector<Text> m_tabTexts;
456 
457  Sprite m_spriteTab;
458  Sprite m_spriteSelectedTab;
459 
460  // Cached renderer properties
461  Borders m_bordersCached;
462  Color m_borderColorCached;
463  Color m_backgroundColorCached;
464  Color m_backgroundColorHoverCached;
465  Color m_selectedBackgroundColorCached;
466  Color m_selectedBackgroundColorHoverCached;
467  Color m_textColorCached;
468  Color m_textColorHoverCached;
469  Color m_selectedTextColorCached;
470  Color m_selectedTextColorHoverCached;
471  float m_distanceToSideCached = 0;
472 
474  };
475 
477 }
478 
479 
481 
482 #endif // TGUI_TAB_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Definition: Sprite.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:243
The parent class for every widget.
Definition: Widget.hpp:62
std::shared_ptr< const Tabs > ConstPtr
Shared constant widget pointer.
Definition: Tabs.hpp:46
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
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:433
Definition: TabsRenderer.hpp:36
Tabs widget.
Definition: Tabs.hpp:41
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition: Tabs.hpp:45