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
35namespace Pt {
36
37namespace Forms {
38
48class PT_FORMS_API ComboBoxState
49{
50 public:
54
57 bool isEnabled() const;
58
61 void setEnabled(bool value);
62
65 bool isFocused() const;
66
69 void setFocused(bool value);
70
73 bool isHighlighted() const;
74
77 void setHighlighted(bool value);
78
81 bool isEditable() const;
82
85 void setEditable(bool value);
86
89 bool isPopupVisible() const;
90
93 void setPopupVisible(bool value);
94
95 private:
96 bool _enabled;
97 bool _focused;
98 bool _highlighted;
99 bool _editable;
100 bool _popupVisible;
101};
102
103
112class PT_FORMS_API ComboBoxButtonState
113{
114 public:
118
121 bool isHighlighted() const;
122
125 void setHighlighted(bool value);
126
129 bool isPressed() const;
130
133 void setPressed(bool value);
134
135 private:
136 bool _highlighted;
137 bool _pressed;
138};
139
140
154class PT_FORMS_API ComboBoxRenderer : public Renderer
155{
156 public:
159 explicit ComboBoxRenderer(std::size_t refs = 0);
160
164
168
169 public:
172 Gfx::SizeF measureFrame(PaintSurface& surface,
173 const Gfx::SizeF& contentSize);
174
177 Gfx::SizeF measureButton(PaintSurface& surface);
178
182 const Gfx::RectF& rect,
183 Gfx::RectF& entryRect,
184 Gfx::RectF& buttonRect,
185 Gfx::RectF& textRect);
186
190
194 const Gfx::RectF& rect,
195 const Gfx::RectF& entryRect,
196 const Gfx::RectF& buttonRect,
197 const ComboBoxState& state,
198 const ComboBoxButtonState& buttonState);
199
203 const Gfx::RectF& buttonRect,
204 const ComboBoxState& state,
205 const ComboBoxButtonState& buttonState);
206
210 const Gfx::RectF& textRect,
211 const String& text,
212 const Gfx::PointF& textPos,
213 const Gfx::RectF& cursor,
214 const ComboBoxState& state);
215
216 protected:
219 virtual ComboBoxRenderer* onCreate() const = 0;
220
223 virtual void onReset(const StyleOptions& options) = 0;
224
227 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
228 const Gfx::SizeF& contentSize) = 0;
229
232 virtual Gfx::SizeF onMeasureButton(PaintSurface& surface) = 0;
233
236 virtual void onLayoutChrome(PaintSurface& surface,
237 const Gfx::RectF& rect,
238 Gfx::RectF& entryRect,
239 Gfx::RectF& buttonRect,
240 Gfx::RectF& textRect) = 0;
241
244 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
245
248 virtual void onRenderChrome(PaintContext& context,
249 const Gfx::RectF& rect,
250 const Gfx::RectF& entryRect,
251 const Gfx::RectF& buttonRect,
252 const ComboBoxState& state,
253 const ComboBoxButtonState& buttonState);
254
257 virtual void onRenderEntry(PaintContext& context,
258 const Gfx::RectF& entryRect,
259 const ComboBoxState& state) = 0;
260
263 virtual void onRenderButton(PaintContext& context,
264 const Gfx::RectF& buttonRect,
265 const ComboBoxState& state,
266 const ComboBoxButtonState& buttonState) = 0;
267
270 virtual void onRenderText(PaintContext& context,
271 const Gfx::RectF& textRect,
272 const String& text,
273 const Gfx::PointF& textPos,
274 const Gfx::RectF& cursor,
275 const ComboBoxState& state) = 0;
276};
277
278
294class PT_FORMS_API ComboBoxStyler : public Styler
295{
296 public:
300
303 const Gfx::Brush& background() const;
304
307 void setBackground(const Gfx::Brush& brush);
308
311 const Gfx::Brush& foreground() const;
312
315 void setForeground(const Gfx::Brush& brush);
316
319 const Gfx::Pen& contour() const;
320
323 void setContour(const Gfx::Pen& pen);
324
327 const Gfx::Color& textColor() const;
328
331 void setTextColor(const Gfx::Color& color);
332
336
339 void setFont(const Gfx::Font& font);
340
343 void setFontSize(std::size_t size);
344
348
352
355 Gfx::SizeF measureFrame(PaintSurface& surface,
356 const Gfx::SizeF& contentSize) const;
357
361 const Gfx::RectF& rect,
362 Gfx::RectF& entryRect,
363 Gfx::RectF& buttonRect,
364 Gfx::RectF& textRect) const;
365
369
373 const Gfx::RectF& rect,
374 const Gfx::RectF& entryRect,
375 const Gfx::RectF& buttonRect,
376 const ComboBoxState& state,
377 const ComboBoxButtonState& buttonState) const;
378
382 const Gfx::RectF& textRect,
383 const String& text,
384 const Gfx::PointF& textPos,
385 const Gfx::RectF& cursor,
386 const ComboBoxState& state) const;
387
392 void setRenderer(ComboBoxRenderer* renderer = 0);
393
397
400 const StyleOptions& options() const;
401
402 protected:
405 virtual StyleOptions& onBindOptions(const StyleOptions& global);
406
409 virtual Renderer* onStyleRenderer(const Style& style);
410
413 virtual Renderer* onCreateRenderer(const Style& style);
414
415 private:
417 StyleOptions _options;
418};
419
420} // namespace
421
422} // namespace
423
424#endif
Transient visual state of a combo-box drop button.
Definition ComboBoxStyler.h:113
void setPressed(bool value)
Sets whether the button is pressed.
ComboBoxButtonState()
Constructs an empty combo-box button state.
bool isPressed() const
Returns true if the button is currently pressed.
bool isHighlighted() const
Returns true if the pointer is currently over the button.
void setHighlighted(bool value)
Sets whether the pointer is over the button.
Renders the look of a combo box.
Definition ComboBoxStyler.h:155
ComboBoxRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
void layoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &buttonRect, Gfx::RectF &textRect)
Places the entry, drop button, and text in rect.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const ComboBoxState &state)
Paints text at textPos for state.
virtual void onRenderEntry(PaintContext &context, const Gfx::RectF &entryRect, const ComboBoxState &state)=0
Paints the entry for state.
ComboBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const Gfx::RectF &cursor, const ComboBoxState &state)=0
Paints text at textPos for state.
virtual Gfx::SizeF onMeasureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)=0
Measures the frame enclosing contentSize.
virtual void onRenderButton(PaintContext &context, const Gfx::RectF &buttonRect, const ComboBoxState &state, const ComboBoxButtonState &buttonState)=0
Paints the drop button for state.
Gfx::SizeF measureButton(PaintSurface &surface)
Returns the natural size of the drop button.
void renderButton(PaintContext &context, const Gfx::RectF &buttonRect, const ComboBoxState &state, const ComboBoxButtonState &buttonState)
Paints the drop button for state.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &buttonRect, const ComboBoxState &state, const ComboBoxButtonState &buttonState)
Paints entry and drop button for state.
virtual Gfx::SizeF onMeasureButton(PaintSurface &surface)=0
Returns the natural size of the drop button.
virtual void onLayoutChrome(PaintSurface &surface, const Gfx::RectF &rect, Gfx::RectF &entryRect, Gfx::RectF &buttonRect, Gfx::RectF &textRect)=0
Places the entry, drop button, and text in rect.
virtual ~ComboBoxRenderer()
Destroys the renderer.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
virtual ComboBoxRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &entryRect, const Gfx::RectF &buttonRect, const ComboBoxState &state, const ComboBoxButtonState &buttonState)
Paints entry and drop button for state.
Transient visual state of a combo box.
Definition ComboBoxStyler.h:49
void setEditable(bool value)
Sets whether the box currently accepts typing.
bool isEditable() const
Returns true if the box currently accepts typing.
ComboBoxState()
Constructs an empty combo box state.
void setPopupVisible(bool value)
Sets whether the popup list is shown.
bool isFocused() const
Returns true if the box currently has focus.
void setFocused(bool value)
Sets whether the box has focus.
bool isHighlighted() const
Returns true if the pointer is currently over the box.
bool isPopupVisible() const
Returns true if the popup list is currently shown.
bool isEnabled() const
Returns true if the box is currently enabled.
void setEnabled(bool value)
Sets whether the box is enabled.
void setHighlighted(bool value)
Sets whether the pointer is over the box.
StyleOptions & options()
Returns the effective combo box options.
const Gfx::Color & textColor() const
Returns the effective text color.
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.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared combo-box renderer from style, or 0.
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.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
void setRenderer(ComboBoxRenderer *renderer=0)
Assigns a specific combo box renderer.
void setForeground(const Gfx::Brush &brush)
Sets the widget-local foreground brush to brush.
const Gfx::Brush & background() const
Returns the effective text background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Gfx::Font font() const
Returns the effective font.
const Painter * textPainter(PaintSurface &surface)
Returns the painter configured for combo box text, or 0 if the styler is not bound.
ComboBoxStyler()
Constructs an unbound combo box styler.
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.
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.
const StyleOptions & options() const
Returns the effective combo box 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.
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.
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
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