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
34namespace Pt {
35
36namespace Forms {
37
46class PT_FORMS_API TabViewState
47{
48 public:
52
55 bool isEnabled() const;
56
59 void setEnabled(bool value);
60
63 bool isFocused() const;
64
67 void setFocused(bool value);
68
69 private:
70 bool _enabled;
71 bool _focused;
72};
73
74
83class PT_FORMS_API TabViewItemState
84{
85 public:
89
92 bool isEnabled() const;
93
96 void setEnabled(bool value);
97
100 bool isActive() const;
101
104 void setActive(bool value);
105
108 bool isHighlighted() const;
109
112 void setHighlighted(bool value);
113
116 bool isPressed() const;
117
120 void setPressed(bool value);
121
122 private:
123 bool _enabled;
124 bool _active;
125 bool _highlighted;
126 bool _pressed;
127};
128
129
146class PT_FORMS_API TabViewRenderer : public Renderer
147{
148 public:
151 explicit TabViewRenderer(std::size_t refs = 0);
152
156
160
161 public:
164 Gfx::SizeF measureTab(PaintSurface& surface,
165 const Pt::String& text);
166
169 Gfx::RectF layoutTab(PaintSurface& surface,
170 const Gfx::RectF& tabRect);
171
175
179 const Gfx::RectF& contentRect,
180 const TabViewState& state);
181
185 const Gfx::RectF& contentRect,
186 const Gfx::RectF& activeTabRect,
187 const TabViewState& state);
188
191 void renderTab(PaintContext& context,
192 const Gfx::RectF& tabRect,
193 const Pt::String& text,
194 const Gfx::PointF& textPos,
195 const TabViewItemState& state);
196
197 protected:
200 virtual TabViewRenderer* onCreate() const = 0;
201
204 virtual void onReset(const StyleOptions& options) = 0;
205
208 virtual Gfx::SizeF onMeasureTab(PaintSurface& surface,
209 const Pt::String& text) = 0;
210
213 virtual Gfx::RectF onLayoutTab(PaintSurface& surface,
214 const Gfx::RectF& tabRect) = 0;
215
218 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
219
222 virtual void onRenderBackground(PaintContext& context,
223 const Gfx::RectF& contentRect,
224 const TabViewState& state) = 0;
225
228 virtual void onRenderChrome(PaintContext& context,
229 const Gfx::RectF& contentRect,
230 const Gfx::RectF& activeTabRect,
231 const TabViewState& state) = 0;
232
235 virtual void onRenderTab(PaintContext& context,
236 const Gfx::RectF& tabRect,
237 const Pt::String& text,
238 const Gfx::PointF& textPos,
239 const TabViewItemState& state) = 0;
240};
241
242
258class PT_FORMS_API TabViewStyler : public Styler
259{
260 public:
264
267 const Gfx::Brush& background() const;
268
271 void setBackground(const Gfx::Brush& brush);
272
275 const Gfx::Pen& contour() const;
276
279 void setContour(const Gfx::Pen& pen);
280
283 const Gfx::Color& textColor() const;
284
287 void setTextColor(const Gfx::Color& color);
288
291 const Gfx::Color& accentColor() const;
292
295 void setAccentColor(const Gfx::Color& color);
296
300
303 void setFont(const Gfx::Font& font);
304
307 void setFontSize(std::size_t size);
308
312
316
319 Gfx::SizeF measureTab(PaintSurface& surface,
320 const Pt::String& text) const;
321
324 Gfx::RectF layoutTab(PaintSurface& surface,
325 const Gfx::RectF& tabRect) const;
326
329 const Painter* textPainter(PaintSurface& surface) const;
330
334 const Gfx::RectF& contentRect,
335 const TabViewState& state) const;
336
340 const Gfx::RectF& contentRect,
341 const Gfx::RectF& activeTabRect,
342 const TabViewState& state) const;
343
346 void renderTab(PaintContext& context,
347 const Gfx::RectF& tabRect,
348 const Pt::String& text,
349 const Gfx::PointF& textPos,
350 const TabViewItemState& state) const;
351
356 void setRenderer(TabViewRenderer* renderer = 0);
357
361
364 const StyleOptions& options() const;
365
366 protected:
369 virtual StyleOptions& onBindOptions(const StyleOptions& global);
370
373 virtual Renderer* onStyleRenderer(const Style& style);
374
377 virtual Renderer* onCreateRenderer(const Style& style);
378
379 private:
381 StyleOptions _options;
382};
383
384} // namespace
385
386} // namespace
387
388#endif
Manages a reference-counted Style::Facet.
Definition Style.h:79
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Forms render target for painting.
Definition PaintSurface.h:50
Draws on a Forms paint surface or paint context.
Definition Painter.h:53
Provides cloneable drawing for one control family.
Definition Renderer.h:61
Renderer(const std::type_info &ti, std::size_t refs=0)
Constructor.
Definition Renderer.h:65
Stores named appearance options.
Definition StyleOptions.h:646
Stores renderer facets for the active theme.
Definition Style.h:203
Styler()
Constructor.
Transient visual state of a tab.
Definition TabViewStyler.h:84
void setPressed(bool value)
Sets whether the tab is pressed.
bool isActive() const
Returns true if the tab is the current tab.
TabViewItemState()
Constructs an empty tab state.
bool isPressed() const
Returns true if the tab is currently pressed.
bool isHighlighted() const
Returns true if the pointer is currently over the tab.
bool isEnabled() const
Returns true if the tab is currently enabled.
void setEnabled(bool value)
Sets whether the tab is enabled.
void setActive(bool value)
Sets whether the tab is the current tab.
void setHighlighted(bool value)
Sets whether the pointer is over the tab.
Renders the look of a tab view.
Definition TabViewStyler.h:147
Gfx::SizeF measureTab(PaintSurface &surface, const Pt::String &text)
Returns the natural size of a tab labeled text.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
virtual TabViewRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
Gfx::RectF layoutTab(PaintSurface &surface, const Gfx::RectF &tabRect)
Returns the label rectangle within tabRect.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &contentRect, const Gfx::RectF &activeTabRect, const TabViewState &state)=0
Paints the frame for state.
virtual void onRenderTab(PaintContext &context, const Gfx::RectF &tabRect, const Pt::String &text, const Gfx::PointF &textPos, const TabViewItemState &state)=0
Paints a tab labeled text for state.
TabViewRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
virtual Gfx::RectF onLayoutTab(PaintSurface &surface, const Gfx::RectF &tabRect)=0
Returns the label rectangle within tabRect.
TabViewRenderer * create() const
Creates a new default-constructed instance that the caller owns.
void renderChrome(PaintContext &context, const Gfx::RectF &contentRect, const Gfx::RectF &activeTabRect, const TabViewState &state)
Paints the frame for state.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
void renderTab(PaintContext &context, const Gfx::RectF &tabRect, const Pt::String &text, const Gfx::PointF &textPos, const TabViewItemState &state)
Paints a tab labeled text for state.
void renderBackground(PaintContext &context, const Gfx::RectF &contentRect, const TabViewState &state)
Paints the background for state.
virtual void onRenderBackground(PaintContext &context, const Gfx::RectF &contentRect, const TabViewState &state)=0
Paints the background for state.
virtual Gfx::SizeF onMeasureTab(PaintSurface &surface, const Pt::String &text)=0
Returns the natural size of a tab labeled text.
virtual ~TabViewRenderer()
Destroys the renderer.
Transient visual state of a tab view.
Definition TabViewStyler.h:47
bool isFocused() const
Returns true if the view currently has focus.
void setFocused(bool value)
Sets whether the view has focus.
bool isEnabled() const
Returns true if the view is currently enabled.
void setEnabled(bool value)
Sets whether the view is enabled.
TabViewState()
Constructs an empty tab view state.
StyleOptions & options()
Returns the effective tab view options.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared tab view renderer from style.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the local tab view options to global.
Gfx::SizeF measureTab(PaintSurface &surface, const Pt::String &text) const
Measures text as a tab label.
const Gfx::Brush & background() const
Returns the effective background brush.
Gfx::Font font() const
Returns the effective font.
void renderBackground(PaintContext &context, const Gfx::RectF &contentRect, const TabViewState &state) const
Renders the tab view background for state.
Gfx::RectF layoutTab(PaintSurface &surface, const Gfx::RectF &tabRect) const
Returns the tab-label rectangle within tabRect.
void setRenderer(TabViewRenderer *renderer=0)
Assigns a specific tab view renderer.
void renderChrome(PaintContext &context, const Gfx::RectF &contentRect, const Gfx::RectF &activeTabRect, const TabViewState &state) const
Renders the tab view frame for state.
const Painter * textPainter(PaintSurface &surface) const
Returns a tab-label painter for surface, or 0 when unavailable.
virtual Renderer * onCreateRenderer(const Style &style)
Creates a tab view renderer clone from style.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local background brush to brush.
TabViewStyler()
Constructs an unbound tab view styler.
const Gfx::Color & accentColor() const
Returns the effective accent color.
const StyleOptions & options() const
Returns the effective tab view options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
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 setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setAccentColor(const Gfx::Color &color)
Sets the widget-local accent color to color.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33