ComboBoxStyler.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_COMBOBOXSTYLE_H
30 #define PT_FORMS_COMBOBOXSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 #include <Pt/Forms/Painter.h>
34 
35 namespace Pt {
36 
37 namespace Forms {
38 
39 class PT_FORMS_API ComboBoxState
40 {
41  public:
42  ComboBoxState();
43 
44  bool isEnabled() const;
45 
46  void setEnabled(bool value);
47 
48  bool isFocused() const;
49 
50  void setFocused(bool value);
51 
52  bool isHighlighted() const;
53 
54  void setHighlighted(bool value);
55 
56  bool isEditable() const;
57 
58  void setEditable(bool value);
59 
60  bool isPopupVisible() const;
61 
62  void setPopupVisible(bool value);
63 
64  private:
65  bool _enabled;
66  bool _focused;
67  bool _highlighted;
68  bool _editable;
69  bool _popupVisible;
70 };
71 
72 
73 class PT_FORMS_API ComboBoxButtonState
74 {
75  public:
76  ComboBoxButtonState();
77 
78  bool isHighlighted() const;
79 
80  void setHighlighted(bool value);
81 
82  bool isPressed() const;
83 
84  void setPressed(bool value);
85 
86  private:
87  bool _highlighted;
88  bool _pressed;
89 };
90 
91 
94 class PT_FORMS_API ComboBoxRenderer : public Renderer
95 {
96  public:
99  explicit ComboBoxRenderer(std::size_t refs = 0);
100 
101  virtual ~ComboBoxRenderer();
102 
106 
107  public:
108  Gfx::SizeF measureFrame(PaintSurface& surface,
109  const Gfx::SizeF& contentSize);
110 
111  Gfx::SizeF measureButton(PaintSurface& surface);
112 
113  void layoutChrome(PaintSurface& surface,
114  const Gfx::RectF& rect,
115  Gfx::RectF& entryRect,
116  Gfx::RectF& buttonRect,
117  Gfx::RectF& textRect);
118 
119  const Painter& textPainter(PaintSurface& surface);
120 
121  void renderChrome(PaintContext& context,
122  const Gfx::RectF& rect,
123  const Gfx::RectF& entryRect,
124  const Gfx::RectF& buttonRect,
125  const ComboBoxState& state,
126  const ComboBoxButtonState& buttonState);
127 
128  void renderButton(PaintContext& context,
129  const Gfx::RectF& buttonRect,
130  const ComboBoxState& state,
131  const ComboBoxButtonState& buttonState);
132 
133  void renderText(PaintContext& context,
134  const Gfx::RectF& textRect,
135  const String& text,
136  const Gfx::PointF& textPos,
137  const Gfx::RectF& cursor,
138  const ComboBoxState& state);
139 
140  protected:
141  virtual ComboBoxRenderer* onCreate() const = 0;
142 
145  virtual void onReset(const StyleOptions& options) = 0;
146 
147  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
148  const Gfx::SizeF& contentSize) = 0;
149 
150  virtual Gfx::SizeF onMeasureButton(PaintSurface& surface) = 0;
151 
152  virtual void onLayoutChrome(PaintSurface& surface,
153  const Gfx::RectF& rect,
154  Gfx::RectF& entryRect,
155  Gfx::RectF& buttonRect,
156  Gfx::RectF& textRect) = 0;
157 
158  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
159 
160  virtual void onRenderChrome(PaintContext& context,
161  const Gfx::RectF& rect,
162  const Gfx::RectF& entryRect,
163  const Gfx::RectF& buttonRect,
164  const ComboBoxState& state,
165  const ComboBoxButtonState& buttonState);
166 
167  virtual void onRenderEntry(PaintContext& context,
168  const Gfx::RectF& entryRect,
169  const ComboBoxState& state) = 0;
170 
171  virtual void onRenderButton(PaintContext& context,
172  const Gfx::RectF& buttonRect,
173  const ComboBoxState& state,
174  const ComboBoxButtonState& buttonState) = 0;
175 
176  virtual void onRenderText(PaintContext& context,
177  const Gfx::RectF& textRect,
178  const String& text,
179  const Gfx::PointF& textPos,
180  const Gfx::RectF& cursor,
181  const ComboBoxState& state) = 0;
182 };
183 
184 
187 class PT_FORMS_API ComboBoxStyler : public Styler
188 {
189  public:
193 
196  const Gfx::Brush& background() const;
197 
200  void setBackground(const Gfx::Brush& brush);
201 
204  const Gfx::Brush& foreground() const;
205 
208  void setForeground(const Gfx::Brush& brush);
209 
212  const Gfx::Pen& contour() const;
213 
216  void setContour(const Gfx::Pen& pen);
217 
220  const Gfx::Color& textColor() const;
221 
224  void setTextColor(const Gfx::Color& color);
225 
228  Gfx::Font font() const;
229 
232  void setFont(const Gfx::Font& font);
233 
236  void setFontSize(std::size_t size);
237 
241 
245 
249  const Gfx::SizeF& contentSize) const;
250 
253  void layoutChrome(PaintSurface& surface,
254  const Gfx::RectF& rect,
255  Gfx::RectF& entryRect,
256  Gfx::RectF& buttonRect,
257  Gfx::RectF& textRect) const;
258 
261  const Painter* textPainter(PaintSurface& surface);
262 
265  void renderChrome(PaintContext& context,
266  const Gfx::RectF& rect,
267  const Gfx::RectF& entryRect,
268  const Gfx::RectF& buttonRect,
269  const ComboBoxState& state,
270  const ComboBoxButtonState& buttonState) const;
271 
274  void renderText(PaintContext& context,
275  const Gfx::RectF& textRect,
276  const String& text,
277  const Gfx::PointF& textPos,
278  const Gfx::RectF& cursor,
279  const ComboBoxState& state) const;
280 
283  void setRenderer(ComboBoxRenderer* renderer = 0);
284 
288 
291  const StyleOptions& options() const;
292 
293  protected:
294  virtual StyleOptions& onBindOptions(const StyleOptions& global);
295 
296  virtual Renderer* onStyleRenderer(const Style& style);
297 
298  virtual Renderer* onCreateRenderer(const Style& style);
299 
300  private:
301  FacetPtr<ComboBoxRenderer> _renderer;
302  StyleOptions _options;
303 };
304 
305 } // namespace
306 
307 } // namespace
308 
309 #endif
Core module.
Definition: Allocator.h:33
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
const Gfx::Color & textColor() const
Returns the effective text color.
Attributes for the drawing of outlines.
Definition: Pen.h:54
ComboBoxStyler()
Constructs an unbound combo box styler.
Gfx::Font font() const
Returns the effective font.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local text background brush to brush.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Paint surface.
Definition: PaintSurface.h:44
ComboBoxRenderer(std::size_t refs=0)
Constructs a combo box renderer.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
2D painter for Forms paint surfaces.
Definition: Painter.h:46
Paint context.
Definition: PaintContext.h:45
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
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 ComboBoxRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
Size with floating-point width and height.
Definition: Size.h:47
const Gfx::Pen & contour() const
Returns the effective contour pen.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
void setRenderer(ComboBoxRenderer *renderer=0)
Assigns a specific combo box renderer.
Weight
Describes the requested font weight.
Definition: Font.h:61
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &buttonRect, Gfx::RectF &textRect) const
Lays out combo box chrome within rect.
Style for widgets.
Definition: Style.h:155
const StyleOptions & options() const
Returns the effective combo box options.
virtual void onReset(const StyleOptions &options)=0
StyleOptions & options()
Returns the effective combo box options.
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
ComboBoxRenderer * create() const
Creates a new default-constructed renderer instance.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Standard color type.
Definition: Color.h:47
Unicode capable basic_string.
Definition: Api-String.h:44
const Painter * textPainter(PaintSurface &surface)
Returns the painter configured for combo box text, or 0 if the styler is not bound.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
Binds ComboBox renderers and widget-local style options.
Definition: ComboBoxStyler.h:188
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &buttonRect, const ComboBoxState &state, const ComboBoxButtonState &buttonState) const
Renders combo box chrome for the supplied states.
const Gfx::Brush & background() const
Returns the effective text background brush.
Renders the visual appearance of a combo box.
Definition: ComboBoxStyler.h:95
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const ComboBoxState &state) const
Renders text at textPos for state.