TabViewStyler.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_TABVIEWSTYLE_H
30 #define PT_FORMS_TABVIEWSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
38 class PT_FORMS_API TabViewState
39 {
40  public:
41  TabViewState();
42 
43  bool isEnabled() const;
44 
45  void setEnabled(bool value);
46 
47  bool isFocused() const;
48 
49  void setFocused(bool value);
50 
51  private:
52  bool _enabled;
53  bool _focused;
54 };
55 
56 
57 class PT_FORMS_API TabViewItemState
58 {
59  public:
60  TabViewItemState();
61 
62  bool isEnabled() const;
63 
64  void setEnabled(bool value);
65 
66  bool isActive() const;
67 
68  void setActive(bool value);
69 
70  bool isHighlighted() const;
71 
72  void setHighlighted(bool value);
73 
74  bool isPressed() const;
75 
76  void setPressed(bool value);
77 
78  private:
79  bool _enabled;
80  bool _active;
81  bool _highlighted;
82  bool _pressed;
83 };
84 
85 
88 class PT_FORMS_API TabViewRenderer : public Renderer
89 {
90  public:
93  explicit TabViewRenderer(std::size_t refs = 0);
94 
95  virtual ~TabViewRenderer();
96 
100 
101  public:
102  Gfx::SizeF measureTab(PaintSurface& surface,
103  const Pt::String& text);
104 
105  Gfx::RectF layoutTab(PaintSurface& surface,
106  const Gfx::RectF& tabRect);
107 
108  const Painter& textPainter(PaintSurface& surface);
109 
110  void renderBackground(PaintContext& context,
111  const Gfx::RectF& contentRect,
112  const TabViewState& state);
113 
114  void renderChrome(PaintContext& context,
115  const Gfx::RectF& contentRect,
116  const Gfx::RectF& activeTabRect,
117  const TabViewState& state);
118 
119  void renderTab(PaintContext& context,
120  const Gfx::RectF& tabRect,
121  const Pt::String& text,
122  const Gfx::PointF& textPos,
123  const TabViewItemState& state);
124 
125  protected:
126  virtual TabViewRenderer* onCreate() const = 0;
127 
130  virtual void onReset(const StyleOptions& options) = 0;
131 
132  virtual Gfx::SizeF onMeasureTab(PaintSurface& surface,
133  const Pt::String& text) = 0;
134 
135  virtual Gfx::RectF onLayoutTab(PaintSurface& surface,
136  const Gfx::RectF& tabRect) = 0;
137 
138  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
139 
140  virtual void onRenderBackground(PaintContext& context,
141  const Gfx::RectF& contentRect,
142  const TabViewState& state) = 0;
143 
144  virtual void onRenderChrome(PaintContext& context,
145  const Gfx::RectF& contentRect,
146  const Gfx::RectF& activeTabRect,
147  const TabViewState& state) = 0;
148 
149  virtual void onRenderTab(PaintContext& context,
150  const Gfx::RectF& tabRect,
151  const Pt::String& text,
152  const Gfx::PointF& textPos,
153  const TabViewItemState& state) = 0;
154 };
155 
156 
159 class PT_FORMS_API TabViewStyler : public Styler
160 {
161  public:
165 
168  const Gfx::Brush& background() const;
169 
172  void setBackground(const Gfx::Brush& brush);
173 
176  const Gfx::Pen& contour() const;
177 
180  void setContour(const Gfx::Pen& pen);
181 
184  const Gfx::Color& textColor() const;
185 
188  void setTextColor(const Gfx::Color& color);
189 
192  const Gfx::Color& accentColor() const;
193 
196  void setAccentColor(const Gfx::Color& color);
197 
200  Gfx::Font font() const;
201 
204  void setFont(const Gfx::Font& font);
205 
208  void setFontSize(std::size_t size);
209 
213 
217 
221  const Pt::String& text) const;
222 
226  const Gfx::RectF& tabRect) const;
227 
230  const Painter* textPainter(PaintSurface& surface) const;
231 
235  const Gfx::RectF& contentRect,
236  const TabViewState& state) const;
237 
240  void renderChrome(PaintContext& context,
241  const Gfx::RectF& contentRect,
242  const Gfx::RectF& activeTabRect,
243  const TabViewState& state) const;
244 
247  void renderTab(PaintContext& context,
248  const Gfx::RectF& tabRect,
249  const Pt::String& text,
250  const Gfx::PointF& textPos,
251  const TabViewItemState& state) const;
252 
255  void setRenderer(TabViewRenderer* renderer = 0);
256 
260 
263  const StyleOptions& options() const;
264 
265  protected:
268  virtual StyleOptions& onBindOptions(const StyleOptions& global);
269 
272  virtual Renderer* onStyleRenderer(const Style& style);
273 
276  virtual Renderer* onCreateRenderer(const Style& style);
277 
278  private:
279  FacetPtr<TabViewRenderer> _renderer;
280  StyleOptions _options;
281 };
282 
283 } // namespace
284 
285 } // namespace
286 
287 #endif
Core module.
Definition: Allocator.h:33
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared tab view renderer from style.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Gfx::SizeF measureTab(PaintSurface &surface, const Pt::String &text) const
Measures text as a tab label.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the local tab view options to global.
TabViewRenderer(std::size_t refs=0)
Constructs a tab view renderer.
virtual TabViewRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
const Gfx::Color & textColor() const
Returns the effective text color.
void renderTab(PaintContext &context, const Gfx::RectF &tabRect, const Pt::String &text, const Gfx::PointF &textPos, const TabViewItemState &state) const
Renders a tab item for state.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
void renderBackground(PaintContext &context, const Gfx::RectF &contentRect, const TabViewState &state) const
Renders the tab view background for state.
virtual void onReset(const StyleOptions &options)=0
Renders tab view chrome and tab items.
Definition: TabViewStyler.h:89
Weight
Describes the requested font weight.
Definition: Font.h:61
Style for widgets.
Definition: Style.h:155
const Gfx::Brush & background() const
Returns the effective background brush.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Gfx::RectF layoutTab(PaintSurface &surface, const Gfx::RectF &tabRect) const
Returns the tab-label rectangle within tabRect.
TabViewRenderer * create() const
Creates a new default-constructed renderer instance.
void renderChrome(PaintContext &context, const Gfx::RectF &contentRect, const Gfx::RectF &activeTabRect, const TabViewState &state) const
Renders the tab view frame for state.
const Gfx::Color & accentColor() const
Returns the effective accent color.
const StyleOptions & options() const
Returns the effective tab view options.
Gfx::Font font() const
Returns the effective font.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
const Gfx::Pen & contour() const
Returns the effective contour pen.
Font request used for text drawing and measurement.
Definition: Font.h:56
Style options container.
Definition: StyleOptions.h:535
Standard color type.
Definition: Color.h:47
Binds tab view renderers and local style options.
Definition: TabViewStyler.h:160
StyleOptions & options()
Returns the effective tab view options.
const Painter * textPainter(PaintSurface &surface) const
Returns a tab-label painter for surface, or 0 when unavailable.
Unicode capable basic_string.
Definition: Api-String.h:44
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
Fill description for shapes and text.
Definition: Brush.h:145
void setAccentColor(const Gfx::Color &color)
Sets the widget-local accent color to color.
Rect with floating-point coordinates.
Definition: Rect.h:47
void setRenderer(TabViewRenderer *renderer=0)
Assigns a specific tab view renderer.
virtual Renderer * onCreateRenderer(const Style &style)
Creates a tab view renderer clone from style.
TabViewStyler()
Constructs an unbound tab view styler.