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
34namespace Pt {
35
36namespace Forms {
37
47class PT_FORMS_API SpinBoxState
48{
49 public:
53
56 bool isEnabled() const;
57
60 void setEnabled(bool value);
61
64 bool isHovered() const;
65
68 void setHovered(bool value);
69
72 bool isFocused() const;
73
76 void setFocused(bool value);
77
80 bool isEditable() const;
81
84 void setEditable(bool value);
85
88 bool isUpPressed() const;
89
92 void setUpPressed(bool value);
93
96 bool isUpHovered() const;
97
100 void setUpHovered(bool value);
101
104 bool isDownPressed() const;
105
108 void setDownPressed(bool value);
109
112 bool isDownHovered() const;
113
116 void setDownHovered(bool value);
117
118 private:
119 bool _enabled;
120 bool _hovered;
121 bool _focused;
122 bool _editable;
123 bool _upPressed;
124 bool _upHovered;
125 bool _downPressed;
126 bool _downHovered;
127};
128
129
147class PT_FORMS_API SpinBoxRenderer : public Renderer
148{
149 public:
152 explicit SpinBoxRenderer(std::size_t refs = 0);
153
157
161
162 public:
165 Gfx::SizeF measureFrame(PaintSurface& surface,
166 const Gfx::SizeF& contentSize);
167
170 Gfx::SizeF measureEntry(PaintSurface& surface,
171 const Gfx::SizeF& contentSize);
172
175 Gfx::SizeF measureIndicator(PaintSurface& surface);
176
180 const Gfx::RectF& rect,
181 Gfx::RectF& entryRect,
182 Gfx::RectF& upButtonRect,
183 Gfx::RectF& downButtonRect,
184 Gfx::RectF& textRect);
185
188 Gfx::RectF layoutEntry(PaintSurface& surface,
189 const Gfx::RectF& entryRect);
190
194
198 const Gfx::RectF& rect,
199 const Gfx::RectF& entryRect,
200 const Gfx::RectF& upButtonRect,
201 const Gfx::RectF& downButtonRect,
202 const SpinBoxState& state);
203
207 const Gfx::RectF& textRect,
208 const String& text,
209 const Gfx::PointF& textPos,
210 const Gfx::RectF& cursor,
211 const SpinBoxState& state);
212
213 protected:
216 virtual SpinBoxRenderer* onCreate() const = 0;
217
220 virtual void onReset(const StyleOptions& options) = 0;
221
224 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
225 const Gfx::SizeF& contentSize) = 0;
226
229 virtual Gfx::SizeF onMeasureEntry(PaintSurface& surface,
230 const Gfx::SizeF& contentSize) = 0;
231
234 virtual Gfx::SizeF onMeasureIndicator(PaintSurface& surface) = 0;
235
238 virtual void onLayoutChrome(PaintSurface& surface,
239 const Gfx::RectF& rect,
240 Gfx::RectF& entryRect,
241 Gfx::RectF& upButtonRect,
242 Gfx::RectF& downButtonRect,
243 Gfx::RectF& textRect) = 0;
244
247 virtual Gfx::RectF onLayoutEntry(PaintSurface& surface,
248 const Gfx::RectF& entryRect) = 0;
249
252 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
253
256 virtual void onRenderChrome(PaintContext& context,
257 const Gfx::RectF& rect,
258 const Gfx::RectF& entryRect,
259 const Gfx::RectF& upButtonRect,
260 const Gfx::RectF& downButtonRect,
261 const SpinBoxState& state);
262
265 virtual void onRenderEntry(PaintContext& context,
266 const Gfx::RectF& entryRect,
267 const SpinBoxState& state) = 0;
268
271 virtual void onRenderUpButton(PaintContext& context,
272 const Gfx::RectF& buttonRect,
273 const SpinBoxState& state) = 0;
274
277 virtual void onRenderDownButton(PaintContext& context,
278 const Gfx::RectF& buttonRect,
279 const SpinBoxState& state) = 0;
280
283 virtual void onRenderText(PaintContext& context,
284 const Gfx::RectF& textRect,
285 const String& text,
286 const Gfx::PointF& textPos,
287 const Gfx::RectF& cursor,
288 const SpinBoxState& state) = 0;
289};
290
291
307class PT_FORMS_API SpinBoxStyler : public Styler
308{
309 public:
313
316 const Gfx::Brush& background() const;
317
320 void setBackground(const Gfx::Brush& brush);
321
324 const Gfx::Brush& foreground() const;
325
328 void setForeground(const Gfx::Brush& brush);
329
332 const Gfx::Pen& contour() const;
333
336 void setContour(const Gfx::Pen& pen);
337
340 const Gfx::Color& textColor() const;
341
344 void setTextColor(const Gfx::Color& color);
345
349
352 void setFont(const Gfx::Font& font);
353
356 void setFontSize(std::size_t size);
357
361
365
368 Gfx::SizeF measureFrame(PaintSurface& surface,
369 const Gfx::SizeF& contentSize) const;
370
374 const Gfx::RectF& rect,
375 Gfx::RectF& entryRect,
376 Gfx::RectF& upButtonRect,
377 Gfx::RectF& downButtonRect,
378 Gfx::RectF& textRect) const;
379
382 const Painter* textPainter(PaintSurface& surface) const;
383
387 const Gfx::RectF& rect,
388 const Gfx::RectF& entryRect,
389 const Gfx::RectF& upButtonRect,
390 const Gfx::RectF& downButtonRect,
391 const SpinBoxState& state) const;
392
396 const Gfx::RectF& textRect,
397 const String& text,
398 const Gfx::PointF& textPos,
399 const Gfx::RectF& cursor,
400 const SpinBoxState& state) const;
401
406 void setRenderer(SpinBoxRenderer* renderer = 0);
407
411
414 const StyleOptions& options() const;
415
416 protected:
419 virtual StyleOptions& onBindOptions(const StyleOptions& global);
420
423 virtual Renderer* onStyleRenderer(const Style& style);
424
427 virtual Renderer* onCreateRenderer(const Style& style);
428
429 private:
431 StyleOptions _options;
432};
433
434} // namespace
435
436} // namespace
437
438#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
Renders the look of a spin box.
Definition SpinBoxStyler.h:148
virtual void onLayoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &upButtonRect, Gfx::RectF &downButtonRect, Gfx::RectF &textRect)=0
Places the entry, step controls, and text in rect.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
SpinBoxRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual Gfx::SizeF onMeasureIndicator(PaintSurface &surface)=0
Returns the natural size of a step control.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &upButtonRect, const Gfx::RectF &downButtonRect, const SpinBoxState &state)
Paints entry and step controls for state.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const SpinBoxState &state)
Paints text at textPos for state.
virtual void onRenderDownButton(PaintContext &context, const Gfx::RectF &buttonRect, const SpinBoxState &state)=0
Paints the down control for state.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
virtual Gfx::SizeF onMeasureEntry(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the entry enclosing contentSize.
Gfx::RectF layoutEntry(PaintSurface &surface, const Gfx::RectF &entryRect)
Returns the text rectangle within entryRect.
Gfx::SizeF measureEntry(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the entry size for contentSize.
virtual SpinBoxRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
SpinBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual void onRenderUpButton(PaintContext &context, const Gfx::RectF &buttonRect, const SpinBoxState &state)=0
Paints the up control for state.
virtual Gfx::RectF onLayoutEntry(PaintSurface &surface, const Gfx::RectF &entryRect)=0
Returns the text rectangle within entryRect.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
Gfx::SizeF measureIndicator(PaintSurface &surface)
Returns the natural size of a step control.
virtual ~SpinBoxRenderer()
Destroys the renderer.
virtual void onRenderEntry(PaintContext &context, const Gfx::RectF &entryRect, const SpinBoxState &state)=0
Paints the entry for state.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &upButtonRect, Gfx::RectF &downButtonRect, Gfx::RectF &textRect)
Places the entry, step controls, and text in rect.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const SpinBoxState &state)=0
Paints text at textPos for state.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &upButtonRect, const Gfx::RectF &downButtonRect, const SpinBoxState &state)
Paints entry and step controls for state.
Transient visual state of a spin box.
Definition SpinBoxStyler.h:48
void setEditable(bool value)
Sets whether the box currently accepts typing.
bool isEditable() const
Returns true if the box currently accepts typing.
bool isUpHovered() const
Returns true if the pointer is currently over the up control.
void setDownPressed(bool value)
Sets whether the down control is pressed.
bool isDownHovered() const
Returns true if the pointer is currently over the down control.
void setDownHovered(bool value)
Sets whether the pointer is over the down control.
bool isFocused() const
Returns true if the box currently has focus.
void setFocused(bool value)
Sets whether the box has focus.
void setHovered(bool value)
Sets whether the pointer is over the box.
bool isUpPressed() const
Returns true if the up control is currently pressed.
SpinBoxState()
Constructs an empty spin box state.
bool isEnabled() const
Returns true if the box is currently enabled.
void setEnabled(bool value)
Sets whether the box is enabled.
void setUpPressed(bool value)
Sets whether the up control is pressed.
bool isDownPressed() const
Returns true if the down control is currently pressed.
bool isHovered() const
Returns true if the pointer is currently over the box.
void setUpHovered(bool value)
Sets whether the pointer is over the up control.
StyleOptions & options()
Returns the bound effective spin box options.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared spin-box renderer from style, or 0.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
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.
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush.
const Gfx::Brush & background() const
Returns the effective spin box text background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Gfx::Font font() const
Returns the effective font.
SpinBoxStyler()
Constructs an unbound spin box styler.
const Painter * textPainter(PaintSurface &surface) const
Returns the prepared text painter for surface, or 0 when unavailable.
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.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independent clone of the style renderer, or 0.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local spin box text background brush.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
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.
const StyleOptions & options() const
Returns the bound effective spin box options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color.
void setFont(const Gfx::Font &font)
Sets the widget-local font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight.
void setRenderer(SpinBoxRenderer *renderer=0)
Assigns a specific spin box renderer.
void setFontSize(std::size_t size)
Sets the widget-local font size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant.
Stores named appearance options.
Definition StyleOptions.h:646
Stores renderer facets for the active theme.
Definition Style.h:203
Styler()
Constructor.
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