SpinBoxStyler.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_SpinBoxStyler_h
30 #define Pt_Forms_SpinBoxStyler_h
31 
32 #include <Pt/Forms/Styler.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
42 class PT_FORMS_API SpinBoxState
43 {
44  public:
45  SpinBoxState();
46 
47  bool isEnabled() const;
48 
49  void setEnabled(bool value);
50 
51  bool isHovered() const;
52 
53  void setHovered(bool value);
54 
55  bool isFocused() const;
56 
57  void setFocused(bool value);
58 
59  bool isEditable() const;
60 
61  void setEditable(bool value);
62 
63  bool isUpPressed() const;
64 
65  void setUpPressed(bool value);
66 
67  bool isUpHovered() const;
68 
69  void setUpHovered(bool value);
70 
71  bool isDownPressed() const;
72 
73  void setDownPressed(bool value);
74 
75  bool isDownHovered() const;
76 
77  void setDownHovered(bool value);
78 
79  private:
80  bool _enabled;
81  bool _hovered;
82  bool _focused;
83  bool _editable;
84  bool _upPressed;
85  bool _upHovered;
86  bool _downPressed;
87  bool _downHovered;
88 };
89 
90 
96 class PT_FORMS_API SpinBoxRenderer : public Renderer
97 {
98  public:
99  explicit SpinBoxRenderer(std::size_t refs = 0);
100 
101  virtual ~SpinBoxRenderer();
102 
106 
107  public:
108  Gfx::SizeF measureFrame(PaintSurface& surface,
109  const Gfx::SizeF& contentSize);
110 
111  Gfx::SizeF measureEntry(PaintSurface& surface,
112  const Gfx::SizeF& contentSize);
113 
114  Gfx::SizeF measureIndicator(PaintSurface& surface);
115 
116  void layoutChrome(PaintSurface& surface,
117  const Gfx::RectF& rect,
118  Gfx::RectF& entryRect,
119  Gfx::RectF& upButtonRect,
120  Gfx::RectF& downButtonRect,
121  Gfx::RectF& textRect);
122 
123  Gfx::RectF layoutEntry(PaintSurface& surface,
124  const Gfx::RectF& entryRect);
125 
126  const Painter& textPainter(PaintSurface& surface);
127 
128  void renderChrome(PaintContext& context,
129  const Gfx::RectF& rect,
130  const Gfx::RectF& entryRect,
131  const Gfx::RectF& upButtonRect,
132  const Gfx::RectF& downButtonRect,
133  const SpinBoxState& state);
134 
135  void renderText(PaintContext& context,
136  const Gfx::RectF& textRect,
137  const String& text,
138  const Gfx::PointF& textPos,
139  const Gfx::RectF& cursor,
140  const SpinBoxState& state);
141 
142  protected:
143  virtual SpinBoxRenderer* onCreate() const = 0;
144 
147  virtual void onReset(const StyleOptions& options) = 0;
148 
149  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
150  const Gfx::SizeF& contentSize) = 0;
151 
152  virtual Gfx::SizeF onMeasureEntry(PaintSurface& surface,
153  const Gfx::SizeF& contentSize) = 0;
154 
155  virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
156 
157  virtual void onLayoutChrome(PaintSurface& surface,
158  const Gfx::RectF& rect,
159  Gfx::RectF& entryRect,
160  Gfx::RectF& upButtonRect,
161  Gfx::RectF& downButtonRect,
162  Gfx::RectF& textRect) = 0;
163 
164  virtual Gfx::RectF onLayoutEntry(PaintSurface& surface,
165  const Gfx::RectF& entryRect) = 0;
166 
167  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
168 
169  virtual void onRenderChrome(PaintContext& context,
170  const Gfx::RectF& rect,
171  const Gfx::RectF& entryRect,
172  const Gfx::RectF& upButtonRect,
173  const Gfx::RectF& downButtonRect,
174  const SpinBoxState& state);
175 
176  virtual void onRenderEntry(PaintContext& context,
177  const Gfx::RectF& entryRect,
178  const SpinBoxState& state) = 0;
179 
180  virtual void onRenderUpButton(PaintContext& context,
181  const Gfx::RectF& buttonRect,
182  const SpinBoxState& state) = 0;
183 
184  virtual void onRenderDownButton(PaintContext& context,
185  const Gfx::RectF& buttonRect,
186  const SpinBoxState& state) = 0;
187 
188  virtual void onRenderText(PaintContext& context,
189  const Gfx::RectF& textRect,
190  const String& text,
191  const Gfx::PointF& textPos,
192  const Gfx::RectF& cursor,
193  const SpinBoxState& state) = 0;
194 };
195 
196 
199 class PT_FORMS_API SpinBoxStyler : public Styler
200 {
201  public:
205 
208  const Gfx::Brush& background() const;
209 
212  void setBackground(const Gfx::Brush& brush);
213 
216  const Gfx::Brush& foreground() const;
217 
220  void setForeground(const Gfx::Brush& brush);
221 
224  const Gfx::Pen& contour() const;
225 
228  void setContour(const Gfx::Pen& pen);
229 
232  const Gfx::Color& textColor() const;
233 
236  void setTextColor(const Gfx::Color& color);
237 
240  Gfx::Font font() const;
241 
244  void setFont(const Gfx::Font& font);
245 
248  void setFontSize(std::size_t size);
249 
253 
257 
261  const Gfx::SizeF& contentSize) const;
262 
265  void layoutChrome(PaintSurface& surface,
266  const Gfx::RectF& rect,
267  Gfx::RectF& entryRect,
268  Gfx::RectF& upButtonRect,
269  Gfx::RectF& downButtonRect,
270  Gfx::RectF& textRect) const;
271 
274  const Painter* textPainter(PaintSurface& surface) const;
275 
278  void renderChrome(PaintContext& context,
279  const Gfx::RectF& rect,
280  const Gfx::RectF& entryRect,
281  const Gfx::RectF& upButtonRect,
282  const Gfx::RectF& downButtonRect,
283  const SpinBoxState& state) const;
284 
287  void renderText(PaintContext& context,
288  const Gfx::RectF& textRect,
289  const String& text,
290  const Gfx::PointF& textPos,
291  const Gfx::RectF& cursor,
292  const SpinBoxState& state) const;
293 
296  void setRenderer(SpinBoxRenderer* renderer = 0);
297 
301 
304  const StyleOptions& options() const;
305 
306  protected:
307  virtual StyleOptions& onBindOptions(const StyleOptions& global);
308 
309  virtual Renderer* onStyleRenderer(const Style& style);
310 
311  virtual Renderer* onCreateRenderer(const Style& style);
312 
313  private:
314  FacetPtr<SpinBoxRenderer> _renderer;
315  StyleOptions _options;
316 };
317 
318 } // namespace
319 
320 } // namespace
321 
322 #endif
Core module.
Definition: Allocator.h:33
Binds spin box renderers and widget-local style options.
Definition: SpinBoxStyler.h:200
SpinBoxStyler()
Constructs an unbound spin box styler.
StyleOptions & options()
Returns the bound effective spin box options.
Attributes for the drawing of outlines.
Definition: Pen.h:54
const Gfx::Color & textColor() const
Returns the effective text color.
void setRenderer(SpinBoxRenderer *renderer=0)
Assigns a specific spin box renderer.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color.
Paint surface.
Definition: PaintSurface.h:44
SpinBoxRenderer * create() const
Creates a new default-constructed spin box renderer.
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &upButtonRect, const Gfx::RectF &downButtonRect, const SpinBoxState &state) const
Renders spin box chrome within the supplied rectangles.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
Size with floating-point width and height.
Definition: Size.h:47
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen.
Weight
Describes the requested font weight.
Definition: Font.h:61
virtual void onReset(const StyleOptions &options)=0
const Painter * textPainter(PaintSurface &surface) const
Returns the prepared text painter for surface, or 0 when unavailable.
Style for widgets.
Definition: Style.h:155
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
const Gfx::Brush & background() const
Returns the effective spin box text background brush.
void setFontSize(std::size_t size)
Sets the widget-local font size.
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
void setFont(const Gfx::Font &font)
Sets the widget-local font.
Style options container.
Definition: StyleOptions.h:535
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant.
Stores the transient render state for a spin box widget.
Definition: SpinBoxStyler.h:43
const Gfx::Pen & contour() const
Returns the effective contour pen.
Standard color type.
Definition: Color.h:47
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &upButtonRect, Gfx::RectF &downButtonRect, Gfx::RectF &textRect) const
Lays out spin box chrome and clears the output rectangles when unavailable.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local spin box text background brush.
Gfx::Font font() const
Returns the effective font.
Unicode capable basic_string.
Definition: Api-String.h:44
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Renders the visual appearance of a spin box widget.
Definition: SpinBoxStyler.h:97
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight.
virtual SpinBoxRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
const StyleOptions & options() const
Returns the bound effective spin box options.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const SpinBoxState &state) const
Renders spin box text and cursor data within textRect.