TabView.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_TabView_H
30 #define Pt_Forms_TabView_H
31 
32 #include <Pt/Forms/Control.h>
33 #include <Pt/Forms/StackLayout.h>
34 #include <Pt/Forms/DockingLayout.h>
35 #include <Pt/SmartPtr.h>
36 #include <Pt/Signal.h>
37 
38 namespace Pt {
39 
40 namespace Forms {
41 
44 class TabItem
45 {
46  public:
47  TabItem()
48  : _isPressed(false)
49  {}
50 
51  ~TabItem()
52  {}
53 
54  const String& text() const
55  { return _text; }
56 
57  void setText(const String& s)
58  { _text = s; }
59 
60  const Gfx::RectF& geometry() const
61  { return _geometry; }
62 
63  void setGeometry(const Gfx::RectF& r)
64  { _geometry = r; }
65 
66  bool isPressed() const
67  { return _isPressed; }
68 
69  void setPressed(bool b)
70  { _isPressed = b; }
71 
72  private:
73  String _text;
74  Gfx::RectF _geometry;
75  bool _isPressed;
76 };
77 
80 class PT_FORMS_API TabBar : public Control
81 {
82  public:
83  typedef Control Base;
84 
85  public:
86  TabBar();
87 
88  virtual ~TabBar();
89 
90  bool empty() const;
91 
92  std::size_t size() const;
93 
94  void addTab(const Pt::String& title);
95 
96  void removeTab(std::size_t n);
97 
98  std::size_t current() const;
99 
100  void setCurrent(std::size_t n);
101 
102  void setText(std::size_t n, const Pt::String& title);
103 
104  Pt::Signal<std::size_t>& currentChanged()
105  { return _currentChanged; }
106 
107  public:
108  void setRenderer(TabViewRenderer* renderer);
109 
110  protected:
111  virtual void onInvalidate();
112 
113  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
114 
115  virtual void onLayout(const Gfx::RectF& rect);
116 
117  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& updateRect);
118 
119  protected:
120  virtual bool onMouseEvent(const MouseEvent& ev);
121 
122  virtual bool onTouchEvent(const TouchEvent& ev);
123 
124  private:
125  Pt::Signal<std::size_t> _currentChanged;
126  std::vector<TabItem> _tabs;
127  std::size_t _current;
128 
129  FacetPtr<TabViewRenderer> _renderer;
130  bool _hasRenderer;
131 
132  Gfx::Brush _backgroundBrush;
133  Gfx::Brush _foregroundBrush;
134  Gfx::Pen _contourPen;
135  Gfx::Pen _textPen;
136  Gfx::Font _font;
137 };
138 
141 class PT_FORMS_API TabView : public Control
142 {
143  public:
144  typedef Control Base;
145 
146  public:
147  TabView();
148 
149  virtual ~TabView();
150 
151  bool empty() const;
152 
153  std::size_t size() const;
154 
155  void addTab(Control& control, const Pt::String& title);
156 
157  void removeTab(std::size_t n);
158 
159  std::size_t current() const;
160 
161  void setCurrent(std::size_t n);
162 
163  void setText(std::size_t n, const Pt::String& title);
164 
165  public:
166  void setRenderer(TabViewRenderer* renderer);
167 
168  protected:
169  virtual void onInvalidate();
170 
171  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
172 
173  virtual void onLayout(const Gfx::RectF& rect);
174 
175  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& updateRect);
176 
177  private:
178  DockingLayout _layout;
179  TabBar _tabBar;
180  StackLayout _stack;
181 
182  FacetPtr<TabViewRenderer> _renderer;
183  bool _hasRenderer;
184 
185  Gfx::Brush _backgroundBrush;
186  Gfx::Brush _foregroundBrush;
187  Gfx::Pen _contourPen;
188 };
189 
190 } // namespace
191 
192 } // namespace
193 
194 #endif
Rect with floating-point coordinates.
Definition: Rect.h:44
Paint surface.
Definition: PaintSurface.h:43
Tab bar for all tabbed controls.
Definition: TabView.h:80
Tabbed view for controls.
Definition: TabView.h:141
Attributes for the drawing of outlines.
Definition: Pen.h:52
Item for tab bars.
Definition: TabView.h:44
Size with floating-point width and height.
Definition: Size.h:44
Unicode capable basic_string.
Definition: String.h:42