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/TabViewStyle.h>
34 #include <Pt/Forms/StackLayout.h>
35 #include <Pt/Signal.h>
36 
37 #include <vector>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
46 {
47  public:
48  TabViewItem()
49  : _isPressed(false)
50  {}
51 
52  ~TabViewItem()
53  {}
54 
55  const String& text() const
56  { return _text; }
57 
58  void setText(const String& s)
59  { _text = s; }
60 
61  const Gfx::RectF& geometry() const
62  { return _geometry; }
63 
64  void setGeometry(const Gfx::RectF& r)
65  { _geometry = r; }
66 
67  const Gfx::SizeF& measuredSize() const
68  { return _measuredSize; }
69 
70  void setMeasuredSize(const Gfx::SizeF& s)
71  { _measuredSize = s; }
72 
73  const Gfx::PointF& textPos() const
74  { return _textPos; }
75 
76  void setTextPos(const Gfx::PointF& p)
77  { _textPos = p; }
78 
79  bool isPressed() const
80  { return _isPressed; }
81 
82  void setPressed(bool b)
83  { _isPressed = b; }
84 
85  private:
86  String _text;
87  Gfx::SizeF _measuredSize;
88  Gfx::RectF _geometry;
89  Gfx::PointF _textPos;
90  bool _isPressed;
91 };
92 
95 class PT_FORMS_API TabView : public Control
96 {
97  public:
98  typedef Control Base;
99 
100  public:
101  TabView();
102 
103  virtual ~TabView();
104 
105  bool empty() const;
106 
107  std::size_t size() const;
108 
109  void addTab(Control& control, const Pt::String& title);
110 
111  void removeTab(std::size_t n);
112 
113  std::size_t current() const;
114 
115  void setCurrent(std::size_t n);
116 
117  void setText(std::size_t n, const Pt::String& title);
118 
119  public:
120  void setBackground(const Gfx::Brush& b);
121 
122  void setBackground(bool enable);
123 
124  void setContour(const Gfx::Pen& p);
125 
126  void setFrame(bool enable);
127 
128  void setFont(const Gfx::Font& font);
129 
130  void setFontSize(std::size_t size);
131 
132  void setFontWeight(Gfx::Font::Weight weight);
133 
134  void setFontSlant(Gfx::Font::Slant slant);
135 
136  void setTextColor(const Gfx::Color& color);
137 
140  void setAccentColor(const Gfx::Color& color);
141 
142  void setRenderer(TabViewRenderer* renderer);
143 
144  protected:
145  virtual void onProcessMouseEvent(const MouseEvent& ev);
146 
147  virtual void onProcessTouchEvent(const TouchEvent& ev);
148 
149  virtual void onInvalidate();
150 
151  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
152 
153  virtual void onLayout(const Gfx::RectF& rect);
154 
155  virtual void onPaint(PaintContext& context, const Gfx::RectF& updateRect);
156 
157  virtual void onPaintBackground(PaintContext& context,
158  const Gfx::RectF& contentRect,
159  const TabViewState& state);
160 
161  virtual void onPaintChrome(PaintContext& context,
162  const Gfx::RectF& contentRect,
163  const Gfx::RectF& activeTabRect,
164  const TabViewState& state);
165 
166  private:
167  std::size_t hitTab(const Gfx::PointF& pos) const;
168 
169  Gfx::SizeF measureTabs(PaintSurface& surface,
170  TabViewRenderer& renderer);
171 
172  void layoutTabs(PaintSurface& surface,
173  TabViewRenderer& renderer,
174  const Gfx::RectF& rect);
175 
176  void renderTabs(PaintContext& context,
177  TabViewRenderer& renderer,
178  bool enabled);
179 
180  void renderTab(PaintContext& context,
181  TabViewRenderer& renderer,
182  const Gfx::RectF& tabRect,
183  const Pt::String& text,
184  const Gfx::PointF& textPos,
185  const TabViewItemState& state);
186 
187  const Gfx::RectF& currentTabRect() const;
188 
189  void onControlRemoved(std::size_t n);
190 
191  StackLayout _stack;
192  std::vector<TabViewItem> _tabs;
193  std::size_t _current;
194  Gfx::RectF _tabBarRect;
195 
196  TabViewStyle _tabViewStyle;
197  TabViewStyleOptions _tabViewOptions;
198  bool _hasBackground;
199  bool _hasFrame;
200 };
201 
202 } // namespace
203 
204 } // namespace
205 
206 #endif
Core module.
Definition: Allocator.h:33
Attributes for the drawing of outlines.
Definition: Pen.h:54
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Paint context.
Definition: PaintContext.h:45
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Weight
Describes the requested font weight.
Definition: Font.h:61
Font request used for text drawing and measurement.
Definition: Font.h:56
Standard color type.
Definition: Color.h:47
Unicode capable basic_string.
Definition: Api-String.h:44
void setAccentColor(const Gfx::Color &color)
Sets the local accent color for the active tab.
Item for tab bars.
Definition: TabView.h:46
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
Tabbed view for controls.
Definition: TabView.h:96