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 
34 namespace Pt {
35 
36 namespace Forms {
37 
38 class PT_FORMS_API LineEditState
39 {
40  public:
41  LineEditState();
42 
43  bool isEnabled() const;
44 
45  void setEnabled(bool value);
46 
47  bool isFocused() const;
48 
49  void setFocused(bool value);
50 
51  bool isHighlighted() const;
52 
53  void setHighlighted(bool value);
54 
55  bool isEditable() const;
56 
57  void setEditable(bool value);
58 
59  bool isPlaceholder() const;
60 
61  void setPlaceholder(bool value);
62 
63  private:
64  bool _enabled;
65  bool _focused;
66  bool _highlighted;
67  bool _editable;
68  bool _placeholder;
69 };
70 
71 
74 class PT_FORMS_API LineEditRenderer : public Renderer
75 {
76  public:
77  explicit LineEditRenderer(std::size_t refs = 0);
78 
79  virtual ~LineEditRenderer();
80 
81  LineEditRenderer* create() const;
82 
83  public:
84  Gfx::SizeF measureFrame(PaintSurface& surface,
85  const Gfx::SizeF& contentSize);
86 
87  Gfx::RectF layoutFrame(PaintSurface& surface,
88  const Gfx::RectF& rect);
89 
92  const Painter& textPainter(PaintSurface& surface);
93 
94  void renderChrome(PaintContext& context,
95  const Gfx::RectF& rect,
96  const Gfx::RectF& textRect,
97  const String& text,
98  const Gfx::PointF& textPos,
99  const Gfx::RectF& cursor,
100  const Gfx::RectF& selection,
101  const LineEditState& state);
102 
103  void renderEntry(PaintContext& context,
104  const Gfx::RectF& rect,
105  const LineEditState& state);
106 
107  void renderSelection(PaintContext& context,
108  const Gfx::RectF& textRect,
109  const Gfx::RectF& selection,
110  const LineEditState& state);
111 
112  void renderText(PaintContext& context,
113  const Gfx::RectF& textRect,
114  const String& text,
115  const Gfx::PointF& textPos,
116  const LineEditState& state);
117 
118  void renderCursor(PaintContext& context,
119  const Gfx::RectF& textRect,
120  const Gfx::RectF& cursor,
121  const LineEditState& state);
122 
123  protected:
124  virtual LineEditRenderer* onCreate() const = 0;
125 
128  virtual void onReset(const StyleOptions& options) = 0;
129 
130  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
131  const Gfx::SizeF& contentSize) = 0;
132 
133  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
134  const Gfx::RectF& rect) = 0;
135 
136  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
137 
138  virtual void onRenderChrome(PaintContext& context,
139  const Gfx::RectF& rect,
140  const Gfx::RectF& textRect,
141  const String& text,
142  const Gfx::PointF& textPos,
143  const Gfx::RectF& cursor,
144  const Gfx::RectF& selection,
145  const LineEditState& state);
146 
147  virtual void onRenderEntry(PaintContext& context,
148  const Gfx::RectF& rect,
149  const LineEditState& state) = 0;
150 
151  virtual void onRenderSelection(PaintContext& context,
152  const Gfx::RectF& textRect,
153  const Gfx::RectF& selection,
154  const LineEditState& state) = 0;
155 
156  virtual void onRenderText(PaintContext& context,
157  const Gfx::RectF& textRect,
158  const String& text,
159  const Gfx::PointF& textPos,
160  const LineEditState& state) = 0;
161 
162  virtual void onRenderCursor(PaintContext& context,
163  const Gfx::RectF& textRect,
164  const Gfx::RectF& cursor,
165  const LineEditState& state) = 0;
166 };
167 
168 
171 class PT_FORMS_API LineEditStyler : public Styler
172 {
173  public:
177 
180  const Gfx::Brush& background() const;
181 
184  void setBackground(const Gfx::Brush& brush);
185 
188  const Gfx::Pen& contour() const;
189 
192  void setContour(const Gfx::Pen& pen);
193 
196  const Gfx::Color& textColor() const;
197 
200  void setTextColor(const Gfx::Color& color);
201 
204  Gfx::Font font() const;
205 
208  void setFont(const Gfx::Font& font);
209 
212  void setFontSize(std::size_t size);
213 
217 
221 
225  const Gfx::SizeF& contentSize) const;
226 
230  const Gfx::RectF& rect) const;
231 
234  const Painter* textPainter(PaintSurface& surface) const;
235 
238  void renderChrome(PaintContext& context,
239  const Gfx::RectF& rect,
240  const Gfx::RectF& textRect,
241  const String& text,
242  const Gfx::PointF& textPos,
243  const Gfx::RectF& cursor,
244  const Gfx::RectF& selection,
245  const LineEditState& state) const;
246 
249  void setRenderer(LineEditRenderer* renderer = 0);
250 
254 
257  const StyleOptions& options() const;
258 
259  protected:
260  virtual StyleOptions& onBindOptions(const StyleOptions& styleOptions);
261 
262  virtual Renderer* onStyleRenderer(const Style& style);
263 
264  virtual Renderer* onCreateRenderer(const Style& style);
265 
266  private:
267  FacetPtr<LineEditRenderer> _renderer;
268  StyleOptions _options;
269 };
270 
271 } // namespace
272 
273 } // namespace
274 
275 #endif
Core module.
Definition: Allocator.h:33
void setContour(const Gfx::Pen &pen)
Sets the widget-local contour pen to pen.
const Painter & textPainter(PaintSurface &surface)
Returns the prepared text painter for surface.
Attributes for the drawing of outlines.
Definition: Pen.h:54
LineEditStyler()
Constructs an unbound line edit styler.
virtual void onReset(const StyleOptions &options)=0
Paint surface.
Definition: PaintSurface.h:44
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
Renders the visual appearance of a line edit.
Definition: LineEditStyler.h:75
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Binds line edit renderers and widget-local style options.
Definition: LineEditStyler.h:172
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
StyleOptions & options()
Returns the bound effective line edit options.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setRenderer(LineEditRenderer *renderer=0)
Assigns a specific line edit renderer or restores style fallback.
Size with floating-point width and height.
Definition: Size.h:47
void setBackground(const Gfx::Brush &brush)
Sets the widget-local text background brush to brush.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
const StyleOptions & options() const
Returns the bound effective line edit options.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
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.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &rect) const
Returns the frame content rectangle, or an empty rectangle when unavailable.
Gfx::Font font() const
Returns the effective font.
Weight
Describes the requested font weight.
Definition: Font.h:61
Style for widgets.
Definition: Style.h:155
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
Style options container.
Definition: StyleOptions.h:535
virtual LineEditRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
const Painter * textPainter(PaintSurface &surface) const
Returns the prepared text painter, or 0 when no renderer is bound.
const Gfx::Brush & background() const
Returns the effective text background brush.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
Standard color type.
Definition: Color.h:47
const Gfx::Color & textColor() const
Returns the effective text color.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize, or returns an empty size.
Unicode capable basic_string.
Definition: Api-String.h:44
virtual StyleOptions & onBindOptions(const StyleOptions &styleOptions)
Returns the specific style options.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.