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
34namespace Pt {
35
36namespace Forms {
37
38class Pixmap;
39
40
49class PT_FORMS_API ListBoxState
50{
51 public:
55
58 bool isEnabled() const;
59
62 void setEnabled(bool value);
63
66 bool isFocused() const;
67
70 void setFocused(bool value);
71
72 private:
73 bool _enabled;
74 bool _focused;
75};
76
77
94class PT_FORMS_API ListBoxRenderer : public Renderer
95{
96 public:
99 explicit ListBoxRenderer(std::size_t refs = 0);
100
104
108
109 public:
112 Gfx::SizeF measureFrame(PaintSurface& surface,
113 const Gfx::SizeF& contentSize);
114
117 Gfx::RectF layoutFrame(PaintSurface& surface,
118 const Gfx::RectF& rect);
119
123 const Gfx::RectF& rect,
124 const ListBoxState& state);
125
129 const Gfx::RectF& rect,
130 const ListBoxState& state);
131
132 protected:
135 virtual ListBoxRenderer* onCreate() const = 0;
136
139 virtual void onReset(const StyleOptions& options) = 0;
140
143 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
144 const Gfx::SizeF& contentSize) = 0;
145
148 virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
149 const Gfx::RectF& rect) = 0;
150
153 virtual void onRenderBackground(PaintContext& context,
154 const Gfx::RectF& rect,
155 const ListBoxState& state) = 0;
156
159 virtual void onRenderChrome(PaintContext& context,
160 const Gfx::RectF& rect,
161 const ListBoxState& state) = 0;
162};
163
164
180class PT_FORMS_API ListBoxStyler : public Styler
181{
182 public:
186
189 const Gfx::Brush& background() const;
190
193 void setBackground(const Gfx::Brush& brush);
194
197 const Gfx::Pen& contour() const;
198
201 void setContour(const Gfx::Pen& pen);
202
205 Gfx::SizeF measureFrame(PaintSurface& surface,
206 const Gfx::SizeF& contentSize) const;
207
210 Gfx::RectF layoutFrame(PaintSurface& surface,
211 const Gfx::RectF& frameRect) const;
212
216 const Gfx::RectF& rect,
217 const ListBoxState& state) const;
218
222 const Gfx::RectF& rect,
223 const ListBoxState& state) const;
224
229 void setRenderer(ListBoxRenderer* renderer = 0);
230
231 protected:
234 virtual StyleOptions& onBindOptions(const StyleOptions& global);
235
238 virtual Renderer* onStyleRenderer(const Style& style);
239
242 virtual Renderer* onCreateRenderer(const Style& style);
243
244 private:
246 StyleOptions _options;
247};
248
249
259class PT_FORMS_API ListItemState
260{
261 public:
265
268 bool isEnabled() const;
269
272 void setEnabled(bool value);
273
276 bool isHighlighted() const;
277
280 void setHighlighted(bool value);
281
284 bool isFocused() const;
285
288 void setFocused(bool value);
289
292 bool isSelected() const;
293
296 void setSelected(bool value);
297
298 private:
299 bool _enabled;
300 bool _highlighted;
301 bool _focused;
302 bool _selected;
303};
304
305
323class PT_FORMS_API ListItemRenderer : public Renderer
324{
325 public:
328 explicit ListItemRenderer(std::size_t refs = 0);
329
333
337
338 public:
341 Gfx::SizeF measureContent(PaintSurface& surface,
342 const Gfx::SizeF& iconSize,
343 const Gfx::SizeF& textSize);
344
347 Gfx::SizeF measureFrame(PaintSurface& surface,
348 const Gfx::SizeF& contentSize);
349
353
356 Gfx::RectF layoutFrame(PaintSurface& surface,
357 const Gfx::RectF& rect);
358
362 const Gfx::RectF& contentRect,
363 const Gfx::SizeF& iconSize,
364 const Gfx::SizeF& textSize,
365 Gfx::RectF& iconRect,
366 Gfx::RectF& textRect);
367
371 const Gfx::RectF& rect,
372 const ListItemState& state);
373
377 const Gfx::RectF& rect,
378 const ListItemState& state);
379
383 const Gfx::RectF& textRect,
384 const String& text,
385 const Gfx::PointF& pos,
386 const ListItemState& state);
387
391 const Gfx::RectF& iconRect,
392 const Pixmap& picture,
393 const Gfx::PointF& pos,
394 const ListItemState& state);
395
396 protected:
399 virtual ListItemRenderer* onCreate() const = 0;
400
403 virtual void onReset(const StyleOptions& options) = 0;
404
407 virtual Gfx::SizeF onMeasureContent(PaintSurface& surface,
408 const Gfx::SizeF& iconSize,
409 const Gfx::SizeF& textSize) = 0;
410
413 virtual Gfx::SizeF onMeasureFrame(PaintSurface& surface,
414 const Gfx::SizeF& contentSize) = 0;
415
418 virtual const Painter& onGetTextPainter(PaintSurface& surface) = 0;
419
422 virtual Gfx::RectF onLayoutFrame(PaintSurface& surface,
423 const Gfx::RectF& rect) = 0;
424
427 virtual void onLayoutContent(PaintSurface& surface,
428 const Gfx::RectF& contentRect,
429 const Gfx::SizeF& iconSize,
430 const Gfx::SizeF& textSize,
431 Gfx::RectF& iconRect,
432 Gfx::RectF& textRect) = 0;
433
436 virtual void onRenderBackground(PaintContext& context,
437 const Gfx::RectF& rect,
438 const ListItemState& state) = 0;
439
442 virtual void onRenderHighlight(PaintContext& context,
443 const Gfx::RectF& rect,
444 const ListItemState& state) = 0;
445
448 virtual void onRenderText(PaintContext& context,
449 const Gfx::RectF& textRect,
450 const String& text,
451 const Gfx::PointF& pos,
452 const ListItemState& state) = 0;
453
456 virtual void onRenderIcon(PaintContext& context,
457 const Gfx::RectF& iconRect,
458 const Pixmap& picture,
459 const Gfx::PointF& pos,
460 const ListItemState& state) = 0;
461};
462
463
479class PT_FORMS_API ListItemStyler : public Styler
480{
481 public:
485
488 void setBackground(const Gfx::Brush& brush);
489
492 const Gfx::Color& textColor() const;
493
496 void setTextColor(const Gfx::Color& color);
497
501
504 void setFont(const Gfx::Font& font);
505
508 void setFontSize(std::size_t size);
509
513
517
520 Gfx::SizeF measureContent(PaintSurface& surface,
521 const Gfx::SizeF& iconSize,
522 const Gfx::SizeF& textSize) const;
523
526 Gfx::SizeF measureFrame(PaintSurface& surface,
527 const Gfx::SizeF& contentSize) const;
528
531 const Painter* textPainter(PaintSurface& surface) const;
532
535 Gfx::RectF layoutFrame(PaintSurface& surface,
536 const Gfx::RectF& frameRect) const;
537
541 const Gfx::RectF& contentRect,
542 const Gfx::SizeF& iconSize,
543 const Gfx::SizeF& textSize,
544 Gfx::RectF& iconRect,
545 Gfx::RectF& textRect) const;
546
550 const Gfx::RectF& rect,
551 const ListItemState& state) const;
552
556 const Gfx::RectF& rect,
557 const ListItemState& state) const;
558
562 const Gfx::RectF& textRect,
563 const String& text,
564 const Gfx::PointF& pos,
565 const ListItemState& state) const;
566
570 const Gfx::RectF& iconRect,
571 const Pixmap& picture,
572 const Gfx::PointF& pos,
573 const ListItemState& state) const;
574
579 void setRenderer(ListItemRenderer* renderer = 0);
580
584
587 const StyleOptions& options() const;
588
589 protected:
592 virtual StyleOptions& onBindOptions(const StyleOptions& global);
593
596 virtual Renderer* onStyleRenderer(const Style& style);
597
600 virtual Renderer* onCreateRenderer(const Style& style);
601
602 private:
604 StyleOptions _options;
605};
606
607} // namespace
608
609} // namespace
610
611#endif
Manages a reference-counted Style::Facet.
Definition Style.h:79
Renders the look of a list box.
Definition ListBoxStyler.h:95
virtual void onRenderBackground(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state)=0
Paints the background for state.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state)
Paints the frame for state.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
virtual void onRenderChrome(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state)=0
Paints the frame for state.
virtual Gfx::RectF onLayoutFrame(PaintSurface &surface, const Gfx::RectF &rect)=0
Returns the content rectangle within rect.
ListBoxRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
ListBoxRenderer * create() const
Creates a new default-constructed instance that the caller owns.
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.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state)
Paints the background for state.
virtual ~ListBoxRenderer()
Destroys the renderer.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
virtual ListBoxRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
Transient visual state of a list box.
Definition ListBoxStyler.h:50
bool isFocused() const
Returns true if the list currently has focus.
void setFocused(bool value)
Sets whether the list has focus.
bool isEnabled() const
Returns true if the list is currently enabled.
void setEnabled(bool value)
Sets whether the list is enabled.
ListBoxState()
Constructs an empty list box state.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state) const
Renders the list box background within rect for state.
void renderChrome(PaintContext &context, const Gfx::RectF &rect, const ListBoxState &state) const
Renders the list box chrome within rect for state.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared list-box renderer from style, or 0.
ListBoxStyler()
Constructs an unbound list box styler.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
const Gfx::Brush & background() const
Returns the effective list box background brush.
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 list box background brush to brush.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
const Gfx::Pen & contour() const
Returns the effective list box contour pen.
void setContour(const Gfx::Pen &pen)
Sets the widget-local list box contour pen to pen.
void setRenderer(ListBoxRenderer *renderer=0)
Assigns a specific list box renderer.
Renders the look of a list item.
Definition ListBoxStyler.h:324
virtual void onRenderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const ListItemState &state)=0
Paints text at pos for state.
virtual const Painter & onGetTextPainter(PaintSurface &surface)=0
Returns a painter with the current font and text color.
void layoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize, Gfx::RectF &iconRect, Gfx::RectF &textRect)
Places the icon and text in contentRect.
ListItemRenderer(std::size_t refs=0)
Constructs a renderer with reference count refs.
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize)
Returns the size of content with iconSize and textSize.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize)
Returns the outer size including the frame for contentSize.
void renderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)
Paints the highlight for state.
virtual Gfx::SizeF onMeasureContent(PaintSurface &surface, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize)=0
Returns the size of content with iconSize and textSize.
virtual Gfx::RectF onLayoutFrame(PaintSurface &surface, const Gfx::RectF &rect)=0
Returns the content rectangle within rect.
virtual ~ListItemRenderer()
Destroys the renderer.
void renderIcon(PaintContext &context, const Gfx::RectF &iconRect, const Pixmap &picture, const Gfx::PointF &pos, const ListItemState &state)
Paints picture at pos for state.
void renderText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const ListItemState &state)
Paints text at pos 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.
ListItemRenderer * create() const
Creates a new default-constructed instance that the caller owns.
virtual void onLayoutContent(PaintSurface &surface, const Gfx::RectF &contentRect, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize, Gfx::RectF &iconRect, Gfx::RectF &textRect)=0
Places the icon and text in contentRect.
virtual void onRenderBackground(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)=0
Paints the background for state.
virtual ListItemRenderer * onCreate() const =0
Creates a new instance of the same concrete type.
const Painter & textPainter(PaintSurface &surface)
Returns a painter with the current font and text color.
virtual void onRenderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)=0
Paints the highlight for state.
virtual void onRenderIcon(PaintContext &context, const Gfx::RectF &iconRect, const Pixmap &picture, const Gfx::PointF &pos, const ListItemState &state)=0
Paints picture at pos for state.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state)
Paints the background for state.
virtual void onReset(const StyleOptions &options)=0
Resets this facet with options.
Transient visual state of a list item.
Definition ListBoxStyler.h:260
ListItemState()
Constructs an empty list item state.
bool isFocused() const
Returns true if the item currently has focus.
void setSelected(bool value)
Sets whether the item is selected.
void setFocused(bool value)
Sets whether the item has focus.
bool isSelected() const
Returns true if the item is currently selected.
bool isHighlighted() const
Returns true if the pointer is currently over the item.
bool isEnabled() const
Returns true if the item is currently enabled.
void setEnabled(bool value)
Sets whether the item is enabled.
void setHighlighted(bool value)
Sets whether the pointer is over the item.
void renderHighlight(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state) const
Renders the list item highlight background within rect for state.
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.
StyleOptions & options()
Returns the bound effective list item options.
const Gfx::Color & textColor() const
Returns the effective list item text color.
Gfx::SizeF measureContent(PaintSurface &surface, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize) const
Measures content containing iconSize and textSize.
void setRenderer(ListItemRenderer *renderer=0)
Assigns a specific list item renderer.
virtual Renderer * onStyleRenderer(const Style &style)
Returns the shared list-item renderer from style, or 0.
virtual StyleOptions & onBindOptions(const StyleOptions &global)
Binds the overlay to global and returns it.
Gfx::Font font() const
Returns the effective list item font.
ListItemStyler()
Constructs an unbound list item styler.
const Painter * textPainter(PaintSurface &surface) const
Returns the text painter for surface, or 0 when unavailable.
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 list item background brush to brush.
Gfx::RectF layoutFrame(PaintSurface &surface, const Gfx::RectF &frameRect) const
Returns the frame content rectangle within frameRect.
Gfx::SizeF measureFrame(PaintSurface &surface, const Gfx::SizeF &contentSize) const
Measures the frame enclosing contentSize.
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.
const StyleOptions & options() const
Returns the bound effective list item options.
void setTextColor(const Gfx::Color &color)
Sets the widget-local list item text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local list item font to font.
void renderBackground(PaintContext &context, const Gfx::RectF &rect, const ListItemState &state) const
Renders the list item background within rect for state.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local list item font weight to weight.
void setFontSize(std::size_t size)
Sets the widget-local list item font size to size.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local list item font slant to slant.
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.
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
Off-screen Forms paint surface.
Definition Pixmap.h:130
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