LineEditStyler.h
1/* Copyright (C) 2015 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_LINEEDITSTYLE_H
30#define PT_FORMS_LINEEDITSTYLE_H
31
32#include <Pt/Forms/Styler.h>
33
34namespace Pt {
35
36namespace Forms {
37
47class PT_FORMS_API LineEditState
48{
49 public:
53
56 bool isEnabled() const;
57
60 void setEnabled(bool value);
61
64 bool isFocused() const;
65
68 void setFocused(bool value);
69
72 bool isHighlighted() const;
73
76 void setHighlighted(bool value);
77
80 bool isEditable() const;
81
84 void setEditable(bool value);
85
88 bool isPlaceholder() const;
89
92 void setPlaceholder(bool value);
93
94 private:
95 bool _enabled;
96 bool _focused;
97 bool _highlighted;
98 bool _editable;
99 bool _placeholder;
100};
101
102
116class PT_FORMS_API LineEditRenderer : public Renderer
117{
118 public:
121 explicit LineEditRenderer(std::size_t refs = 0);
122
126
130
131 public:
134 Gfx::SizeF measureFrame(PaintSurface& surface,
135 const Gfx::SizeF& contentSize);
136
139 Gfx::RectF layoutFrame(PaintSurface& surface,
140 const Gfx::RectF& rect);
141
145
149 const Gfx::RectF& rect,
150 const Gfx::RectF& textRect,
151 const String& text,
152 const Gfx::PointF& textPos,
153 const Gfx::RectF& cursor,
154 const Gfx::RectF& selection,
155 const LineEditState& state);
156
160 const Gfx::RectF& rect,
161 const LineEditState& state);
162
166 const Gfx::RectF& textRect,
167 const Gfx::RectF& selection,
168 const LineEditState& state);
169
173 const Gfx::RectF& textRect,
174 const String& text,
175 const Gfx::PointF& textPos,
176 const LineEditState& state);
177
181 const Gfx::RectF& textRect,
182 const Gfx::RectF& cursor,
183 const LineEditState& state);
184
185 protected:
188 virtual LineEditRenderer* onCreate() const = 0;
189
192 virtual void onReset(const StyleOptions& options) = 0;
193
196 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
197 const Gfx::SizeF& contentSize) = 0;
198
201 virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
202 const Gfx::RectF& rect) = 0;
203
206 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
207
210 virtual void onRenderChrome(PaintContext& context,
211 const Gfx::RectF& rect,
212 const Gfx::RectF& textRect,
213 const String& text,
214 const Gfx::PointF& textPos,
215 const Gfx::RectF& cursor,
216 const Gfx::RectF& selection,
217 const LineEditState& state);
218
221 virtual void onRenderEntry(PaintContext& context,
222 const Gfx::RectF& rect,
223 const LineEditState& state) = 0;
224
227 virtual void onRenderSelection(PaintContext& context,
228 const Gfx::RectF& textRect,
229 const Gfx::RectF& selection,
230 const LineEditState& state) = 0;
231
234 virtual void onRenderText(PaintContext& context,
235 const Gfx::RectF& textRect,
236 const String& text,
237 const Gfx::PointF& textPos,
238 const LineEditState& state) = 0;
239
242 virtual void onRenderCursor(PaintContext& context,
243 const Gfx::RectF& textRect,
244 const Gfx::RectF& cursor,
245 const LineEditState& state) = 0;
246};
247
248
264class PT_FORMS_API LineEditStyler : public Styler
265{
266 public:
270
273 const Gfx::Brush& background() const;
274
277 void setBackground(const Gfx::Brush& brush);
278
281 const Gfx::Pen& contour() const;
282
285 void setContour(const Gfx::Pen& pen);
286
289 const Gfx::Color& textColor() const;
290
293 void setTextColor(const Gfx::Color& color);
294
298
301 void setFont(const Gfx::Font& font);
302
305 void setFontSize(std::size_t size);
306
310
314
317 Gfx::SizeF measureFrame(PaintSurface& surface,
318 const Gfx::SizeF& contentSize) const;
319
322 Gfx::RectF layoutFrame(PaintSurface& surface,
323 const Gfx::RectF& rect) const;
324
327 const Painter* textPainter(PaintSurface& surface) const;
328
332 const Gfx::RectF& rect,
333 const Gfx::RectF& textRect,
334 const String& text,
335 const Gfx::PointF& textPos,
336 const Gfx::RectF& cursor,
337 const Gfx::RectF& selection,
338 const LineEditState& state) const;
339
342 void setRenderer(LineEditRenderer* renderer = 0);
343
347
350 const StyleOptions& options() const;
351
352 protected:
355 virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
356
359 virtual Renderer* onStyleRenderer(const Style& style);
360
363 virtual Renderer* onCreateRenderer(const Style& style);
364
365 private:
367 StyleOptions _options;
368};
369
370} // namespace
371
372} // namespace
373
374#endif
Manages a reference-counted Style::Facet.
Definition Style.h:79
Renders the look of a line edit.
Definition LineEditStyler.h:117
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const Gfx::RectF &selection, const LineEditState &state)
Paints entry, selection, text, and caret for state.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
void renderEntry(PaintContext &context, const Gfx::RectF &rect, const LineEditState &state)
Paints the entry for state.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const Gfx::RectF &selection, const LineEditState &state)
Paints entry, selection, text, and caret for state.
virtual Gfx::RectF onLayoutFrame(PaintSurface &surface, const Gfx::RectF &rect)=0
Returns the content rectangle within rect.
void renderCursor(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &cursor, const LineEditState &state)
Paints the caret for state.
void renderSelection(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &selection, const LineEditState &state)
Paints the selection for state.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &rect)
Returns the content rectangle within rect.
LineEditRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual void onRenderSelection(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &selection, const LineEditState &state)=0
Paints the selection for state.
virtual ~LineEditRenderer()
Destroys the renderer.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
virtual LineEditRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
LineEditRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual void onRenderCursor(PaintContext &context, const Gfx::RectF &textRect, const Gfx::RectF &cursor, const LineEditState &state)=0
Paints the caret for state.
virtual void onRenderEntry(PaintContext &context, const Gfx::RectF &rect, const LineEditState &state)=0
Paints the entry for state.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const LineEditState &state)
Paints text at textPos for state.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const LineEditState &state)=0
Paints text at textPos for state.
Transient visual state of a line edit.
Definition LineEditStyler.h:48
void setEditable(bool value)
Sets whether the field currently accepts editing.
bool isEditable() const
Returns true if the field currently accepts editing.
bool isPlaceholder() const
Returns true if the field currently shows placeholder text.
LineEditState()
Constructs an empty line edit state.
bool isFocused() const
Returns true if the field currently has focus.
void setFocused(bool value)
Sets whether the field has focus.
bool isHighlighted() const
Returns true if the pointer is currently over the field.
bool isEnabled() const
Returns true if the field is currently enabled.
void setEnabled(bool value)
Sets whether the field is enabled.
void setPlaceholder(bool value)
Sets whether the field currently shows placeholder text.
void setHighlighted(bool value)
Sets whether the pointer is over the field.
StyleOptions & options()
Returns the bound effective line edit options.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const Gfx::RectF &selection, const LineEditState &state) const
Renders line edit chrome when a renderer is bound.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared line-edit renderer from style, or 0.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &rect) const
Returns the frame content rectangle, or an empty rectangle when unavailable.
const Gfx::Brush & background() const
Returns the effective text background brush.
Gfx::Font font() const
Returns the effective font.
LineEditStyler()
Constructs an unbound line edit styler.
const Painter * textPainter(PaintSurface &surface) const
Returns the prepared text painter, or 0 when no renderer is bound.
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 text background brush to brush.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize, or returns an empty size.
const StyleOptions & options() const
Returns the bound effective line edit 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 setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Binds the overlay to styleOptions and returns it.
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.
void setRenderer(LineEditRenderer *renderer=0)
Assigns a specific line edit renderer or restores style fallback.
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.
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