ListBoxStyler.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_LISTBOXSTYLE_H
30 #define PT_FORMS_LISTBOXSTYLE_H
31 
32 #include <Pt/Forms/Styler.h>
33 
34 namespace Pt {
35 
36 namespace Forms {
37 
38 class Pixmap;
39 
40 
41 class PT_FORMS_API ListBoxState
42 {
43  public:
44  ListBoxState();
45 
46  bool isEnabled() const;
47 
48  void setEnabled(bool value);
49 
50  bool isFocused() const;
51 
52  void setFocused(bool value);
53 
54  private:
55  bool _enabled;
56  bool _focused;
57 };
58 
59 
62 class PT_FORMS_API ListBoxRenderer : public Renderer
63 {
64  public:
65  explicit ListBoxRenderer(std::size_t refs = 0);
66 
67  virtual ~ListBoxRenderer();
68 
72 
73  public:
74  Gfx::SizeF measureFrame(PaintSurface& surface,
75  const Gfx::SizeF& contentSize);
76 
77  Gfx::RectF layoutFrame(PaintSurface& surface,
78  const Gfx::RectF& rect);
79 
80  void renderBackground(PaintContext& context,
81  const Gfx::RectF& rect,
82  const ListBoxState& state);
83 
84  void renderChrome(PaintContext& context,
85  const Gfx::RectF& rect,
86  const ListBoxState& state);
87 
88  protected:
89  virtual ListBoxRenderer* onCreate() const = 0;
90 
93  virtual void onReset(const StyleOptions& options) = 0;
94 
95  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
96  const Gfx::SizeF& contentSize) = 0;
97 
98  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
99  const Gfx::RectF& rect) = 0;
100 
101  virtual void onRenderBackground(PaintContext& context,
102  const Gfx::RectF& rect,
103  const ListBoxState& state) = 0;
104 
105  virtual void onRenderChrome(PaintContext& context,
106  const Gfx::RectF& rect,
107  const ListBoxState& state) = 0;
108 };
109 
110 
113 class PT_FORMS_API ListBoxStyler : public Styler
114 {
115  public:
119 
122  const Gfx::Brush& background() const;
123 
126  void setBackground(const Gfx::Brush& brush);
127 
130  const Gfx::Pen& contour() const;
131 
134  void setContour(const Gfx::Pen& pen);
135 
139  const Gfx::SizeF& contentSize) const;
140 
144  const Gfx::RectF& frameRect) const;
145 
149  const Gfx::RectF& rect,
150  const ListBoxState& state) const;
151 
154  void renderChrome(PaintContext& context,
155  const Gfx::RectF& rect,
156  const ListBoxState& state) const;
157 
160  void setRenderer(ListBoxRenderer* renderer = 0);
161 
162  protected:
163  virtual StyleOptions& onBindOptions(const StyleOptions& global);
164 
165  virtual Renderer* onStyleRenderer(const Style& style);
166 
167  virtual Renderer* onCreateRenderer(const Style& style);
168 
169  private:
170  FacetPtr<ListBoxRenderer> _renderer;
171  StyleOptions _options;
172 };
173 
174 
175 class PT_FORMS_API ListItemState
176 {
177  public:
178  ListItemState();
179 
180  bool isEnabled() const;
181 
182  void setEnabled(bool value);
183 
184  bool isHighlighted() const;
185 
186  void setHighlighted(bool value);
187 
188  bool isFocused() const;
189 
190  void setFocused(bool value);
191 
192  bool isSelected() const;
193 
194  void setSelected(bool value);
195 
196  private:
197  bool _enabled;
198  bool _highlighted;
199  bool _focused;
200  bool _selected;
201 };
202 
203 
206 class PT_FORMS_API ListItemRenderer : public Renderer
207 {
208  public:
209  explicit ListItemRenderer(std::size_t refs = 0);
210 
211  virtual ~ListItemRenderer();
212 
213  ListItemRenderer* create() const;
214 
215  public:
216  Gfx::SizeF measureContent(PaintSurface& surface,
217  const Gfx::SizeF& iconSize,
218  const Gfx::SizeF& textSize);
219 
220  Gfx::SizeF measureFrame(PaintSurface& surface,
221  const Gfx::SizeF& contentSize);
222 
223  const Painter& textPainter(PaintSurface& surface);
224 
225  Gfx::RectF layoutFrame(PaintSurface& surface,
226  const Gfx::RectF& rect);
227 
228  void layoutContent(PaintSurface& surface,
229  const Gfx::RectF& contentRect,
230  const Gfx::SizeF& iconSize,
231  const Gfx::SizeF& textSize,
232  Gfx::RectF& iconRect,
233  Gfx::RectF& textRect);
234 
235  void renderBackground(PaintContext& context,
236  const Gfx::RectF& rect,
237  const ListItemState& state);
238 
242  const Gfx::RectF& rect,
243  const ListItemState& state);
244 
245  void renderText(PaintContext& context,
246  const Gfx::RectF& textRect,
247  const String& text,
248  const Gfx::PointF& pos,
249  const ListItemState& state);
250 
251  void renderIcon(PaintContext& context,
252  const Gfx::RectF& iconRect,
253  const Pixmap& picture,
254  const Gfx::PointF& pos,
255  const ListItemState& state);
256 
257  protected:
258  virtual ListItemRenderer* onCreate() const = 0;
259 
262  virtual void onReset(const StyleOptions& options) = 0;
263 
264  virtual Gfx::SizeF onMeasureContent(PaintSurface& surface,
265  const Gfx::SizeF& iconSize,
266  const Gfx::SizeF& textSize) = 0;
267 
268  virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
269  const Gfx::SizeF& contentSize) = 0;
270 
271  virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
272 
273  virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
274  const Gfx::RectF& rect) = 0;
275 
276  virtual void onLayoutContent(PaintSurface& surface,
277  const Gfx::RectF& contentRect,
278  const Gfx::SizeF& iconSize,
279  const Gfx::SizeF& textSize,
280  Gfx::RectF& iconRect,
281  Gfx::RectF& textRect) = 0;
282 
283  virtual void onRenderBackground(PaintContext& context,
284  const Gfx::RectF& rect,
285  const ListItemState& state) = 0;
286 
289  virtual void onRenderHighlight(PaintContext& context,
290  const Gfx::RectF& rect,
291  const ListItemState& state) = 0;
292 
293  virtual void onRenderText(PaintContext& context,
294  const Gfx::RectF& textRect,
295  const String& text,
296  const Gfx::PointF& pos,
297  const ListItemState& state) = 0;
298 
299  virtual void onRenderIcon(PaintContext& context,
300  const Gfx::RectF& iconRect,
301  const Pixmap& picture,
302  const Gfx::PointF& pos,
303  const ListItemState& state) = 0;
304 };
305 
306 
309 class PT_FORMS_API ListItemStyler : public Styler
310 {
311  public:
315 
318  void setBackground(const Gfx::Brush& brush);
319 
322  const Gfx::Color& textColor() const;
323 
326  void setTextColor(const Gfx::Color& color);
327 
330  Gfx::Font font() const;
331 
334  void setFont(const Gfx::Font& font);
335 
338  void setFontSize(std::size_t size);
339 
343 
347 
351  const Gfx::SizeF& iconSize,
352  const Gfx::SizeF& textSize) const;
353 
357  const Gfx::SizeF& contentSize) const;
358 
361  const Painter* textPainter(PaintSurface& surface) const;
362 
366  const Gfx::RectF& frameRect) const;
367 
371  const Gfx::RectF& contentRect,
372  const Gfx::SizeF& iconSize,
373  const Gfx::SizeF& textSize,
374  Gfx::RectF& iconRect,
375  Gfx::RectF& textRect) const;
376 
380  const Gfx::RectF& rect,
381  const ListItemState& state) const;
382 
386  const Gfx::RectF& rect,
387  const ListItemState& state) const;
388 
391  void renderText(PaintContext& context,
392  const Gfx::RectF& textRect,
393  const String& text,
394  const Gfx::PointF& pos,
395  const ListItemState& state) const;
396 
399  void renderIcon(PaintContext& context,
400  const Gfx::RectF& iconRect,
401  const Pixmap& picture,
402  const Gfx::PointF& pos,
403  const ListItemState& state) const;
404 
407  void setRenderer(ListItemRenderer* renderer = 0);
408 
412 
415  const StyleOptions& options() const;
416 
417  protected:
418  virtual StyleOptions& onBindOptions(const StyleOptions& global);
419 
420  virtual Renderer* onStyleRenderer(const Style& style);
421 
422  virtual Renderer* onCreateRenderer(const Style& style);
423 
424  private:
425  FacetPtr<ListItemRenderer> _renderer;
426  StyleOptions _options;
427 };
428 
429 } // namespace
430 
431 } // namespace
432 
433 #endif
Core module.
Definition: Allocator.h:33
void setFont(const Gfx::Font &font)
Sets the widget-local list item font to font.
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize) const
Measures content containing iconSize and textSize.
void setContour(const Gfx::Pen &pen)
Sets the widget-local list box contour pen to pen.
virtual void onRenderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)=0
Renders the selected or highlighted list item background.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local list box background brush to brush.
void setRenderer(ListBoxRenderer *renderer=0)
Assigns a specific list box renderer.
Paint surface.
Definition: PaintSurface.h:44
Slant
Describes the requested font slant.
Definition: Font.h:76
Styler.
Definition: Styler.h:47
Gfx::Font font() const
Returns the effective list item font.
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
2D painter for Forms paint surfaces.
Definition: Painter.h:46
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
Paint context.
Definition: PaintContext.h:45
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
virtual void onReset(const StyleOptions &options)=0
void setFontSize(std::size_t size)
Sets the widget-local list item font size to size.
const StyleOptions & options() const
Returns the bound effective list item options.
Binds list box renderers and their local style options.
Definition: ListBoxStyler.h:114
ListBoxRenderer * create() const
Creates a new default-constructed renderer instance.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Renders the visual appearance of a list item.
Definition: ListBoxStyler.h:207
const Gfx::Color & textColor() const
Returns the effective list item text color.
void setBackground(const Gfx::Brush &brush)
Sets the widget-local list item background brush to brush.
Binds list item renderers and their local style options.
Definition: ListBoxStyler.h:310
virtual Renderer * onCreateRenderer(const Style &style)
Creates an independant style renderer.
Weight
Describes the requested font weight.
Definition: Font.h:61
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state) const
Renders the list box background within rect for state.
void renderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)
Renders the list item highlight background within rect for state.
const Gfx::Pen & contour() const
Returns the effective list box contour pen.
Renders the visual appearance of a list box container.
Definition: ListBoxStyler.h:63
Style for widgets.
Definition: Style.h:155
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state) const
Renders the list item background within rect for state.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
void renderIcon(PaintContext &context, const Gfx::RectF &iconRect, const Pixmap &picture, const Gfx::PointF &pos, const ListItemState &state) const
Renders picture at pos within iconRect for state.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Returns the specific style options.
Cloneable style facet used by widget renderers.
Definition: Renderer.h:48
Font request used for text drawing and measurement.
Definition: Font.h:56
void layoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize, Gfx::RectF &iconRect, Gfx::RectF &textRect) const
Lays out icon and text rectangles within contentRect.
Style options container.
Definition: StyleOptions.h:535
virtual Renderer * onStyleRenderer(const Style &style)
Resolves the shared style renderer for the current style.
virtual ListItemRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
void setTextColor(const Gfx::Color &color)
Sets the widget-local list item text color to color.
virtual void onReset(const StyleOptions &options)=0
Standard color type.
Definition: Color.h:47
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state) const
Renders the list box chrome within rect for state.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local list item font slant to slant.
Unicode capable basic_string.
Definition: Api-String.h:44
const Gfx::Brush & background() const
Returns the effective list box background brush.
void renderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state) const
Renders the list item highlight background within rect for state.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
Back buffer drawing surface.
Definition: Pixmap.h:77
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const ListItemState &state) const
Renders text at pos within textRect for state.
StyleOptions & options()
Returns the bound effective list item options.
ListBoxStyler()
Constructs an unbound list box styler.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local list item font weight to weight.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
void setRenderer(ListItemRenderer *renderer=0)
Assigns a specific list item renderer.
virtual ListBoxRenderer * onCreate() const =0
Hook that allocates a new renderer of the same concrete type.
ListItemStyler()
Constructs an unbound list item styler.