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 {
49  class TGUI_API Tabs : public Widget
50  {
51  public:
52 
53  typedef std::shared_ptr<Tabs> Ptr;
54  typedef std::shared_ptr<const Tabs> ConstPtr;
55 
56 
58  // Default constructor
60  Tabs();
61 
62 
69  static Tabs::Ptr create();
70 
71 
80  static Tabs::Ptr copy(Tabs::ConstPtr tab);
81 
82 
90  {
91  return aurora::downcast<TabsRenderer*>(m_renderer.get());
92  }
93 
94 
107  virtual void setSize(const Layout2d& size) override;
109 
110 
117  virtual sf::Vector2f getSize() const override
118  {
119  return {m_width, m_tabHeight};
120  }
121 
122 
134  std::size_t add(const sf::String& text, bool select = true);
135 
136 
145  void insert(std::size_t index, const sf::String& text, bool select = true);
146 
147 
156  sf::String getText(std::size_t index) const;
157 
158 
168  bool changeText(std::size_t index, const sf::String& text);
169 
170 
182  void select(const sf::String& text);
183 
184 
195  void select(std::size_t index);
196 
197 
202  void deselect();
203 
204 
215  void remove(const sf::String& text);
216 
217 
228  void remove(std::size_t index);
229 
230 
235  void removeAll();
236 
237 
245  sf::String getSelected() const;
246 
247 
257  int getSelectedIndex() const;
258 
259 
267  void setTextSize(unsigned int size);
268 
269 
276  unsigned int getTextSize() const;
277 
278 
287  void setTabHeight(float height);
288 
289 
296  float getTabHeight() const;
297 
298 
308  void setMaximumTabWidth(float maximumWidth);
309 
310 
320  float getMaximumTabWidth() const;
321 
322 
329  std::size_t getTabsCount() const;
330 
331 
335  virtual bool mouseOnWidget(sf::Vector2f pos) const override;
336 
340  virtual void leftMousePressed(sf::Vector2f pos) override;
341 
342 
350  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
351 
352 
354  protected:
355 
356 
358  // Recalculates the size of each tab image.
360  void recalculateTabsWidth();
361 
362 
369  virtual void rendererChanged(const std::string& property) override;
370 
371 
373  // Makes a copy of the widget
375  virtual Widget::Ptr clone() const override
376  {
377  return std::make_shared<Tabs>(*this);
378  }
379 
380 
382  protected:
383  unsigned int m_requestedTextSize = 0;
384  unsigned int m_textSize = 22;
385 
386  float m_maximumTabWidth = 0;
387  int m_selectedTab = -1;
388 
389  float m_width = 0;
390  float m_tabHeight = 0;
391  std::vector<float> m_tabWidth;
392 
393  std::vector<Text> m_tabTexts;
394 
395  Sprite m_spriteTab;
396  Sprite m_spriteSelectedTab;
397 
398  // Cached renderer properties
399  Borders m_bordersCached;
400  Color m_borderColorCached;
401  Color m_backgroundColorCached;
402  Color m_selectedBackgroundColorCached;
403  Color m_textColorCached;
404  Color m_selectedTextColorCached;
405  float m_distanceToSideCached = 0;
406 
408  };
409 
411 }
412 
413 
415 
416 #endif // TGUI_TAB_HPP
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:33
Definition: Sprite.hpp:40
Wrapper for colors.
Definition: Color.hpp:46
virtual sf::Vector2f getSize() const override
Returns the size of the tabs.
Definition: Tabs.hpp:117
Class to store the position or size of a widget.
Definition: Layout.hpp:263
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Tabs.hpp:375
The parent class for every widget.
Definition: Widget.hpp:72
std::shared_ptr< const Tabs > ConstPtr
Shared constant widget pointer.
Definition: Tabs.hpp:54
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:76
TabsRenderer * getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed...
Definition: Tabs.hpp:89
Definition: Outline.hpp:37
Definition: TabsRenderer.hpp:36
Tabs widget.
Definition: Tabs.hpp:49
std::shared_ptr< Tabs > Ptr
Shared widget pointer.
Definition: Tabs.hpp:53