ButtonRenderer Class Referenceabstract

#include <Pt/Forms/ButtonStyler.h>

Renders the look of a push button. More...

Inherits Renderer.

Public Member Functions

 ButtonRenderer (std::size_t refs=0)
 Constructs a renderer with reference count refs.
virtual ~ButtonRenderer ()
 Destroys the renderer.
ButtonRenderercreate () const
 Creates a new default-constructed instance that the caller owns.
Gfx::SizeF measureContent (PaintSurface &surface, Direction direction, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize)
 Returns the combined content size for icon and text arranged by direction.
Gfx::SizeF measureFrame (PaintSurface &surface, const Gfx::SizeF &contentSize)
 Returns the outer size including button decoration for contentSize on surface.
Gfx::RectF layoutFrame (PaintSurface &surface, const Gfx::RectF &frameRect)
 Returns the content rectangle within the outer frameRect.
Gfx::RectF layoutMnemonic (PaintSurface &surface, const String &text, const Gfx::PointF &textPos, const Gfx::FontMetrics &fontMetrics, String::size_type mnemonicIndex)
 Computes the underline rectangle for the mnemonic character at mnemonicIndex.
const PaintertextPainter (PaintSurface &surface)
 Returns a painter with the current font and text color applied for surface.
void layoutContent (PaintSurface &surface, const Gfx::RectF &contentRect, Direction direction, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize, Gfx::RectF &iconRect, Gfx::RectF &textRect)
 Computes the icon and text sub-rectangles within the content rect.
void prepareIcon (const Gfx::Image &icon, Pixmap &picture, const ButtonState &state) const
 Converts icon to a state-appropriate pixmap written to picture.
void renderBackground (PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)
 Paints the background fill within the widget rect.
void renderChrome (PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)
 Paints the button background and border within the button bounding rect.
void renderText (PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const ButtonState &state)
 Draws text at pos, clipped to the button bounding rect.
void renderMnemonic (PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const ButtonState &state)
 Draws the mnemonic underline within mnemonic, clipped to the button bounding rect.
void renderIcon (PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const ButtonState &state)
 Draws picture at pos, clipped to the button bounding rect.
const std::type_info & typeId () const
 Returns the dynamic type used as the registry key.
void ref ()
 Adds one reference.
std::size_t unref ()
 Removes one reference and returns the remaining count.
void reset (const StyleOptions &options)
 Resets this facet with options.

Protected Member Functions

virtual ButtonRendereronCreate () const =0
 Creates a new instance of the same concrete type.
virtual void onReset (const StyleOptions &options)=0
 Resets this facet with options.
virtual Gfx::SizeF onMeasureFrame (PaintSurface &surface, const Gfx::SizeF &contentSize)=0
 Measures the frame enclosing contentSize.
virtual Gfx::SizeF onMeasureContent (PaintSurface &surface, Direction direction, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize)=0
 Measures icon and text arranged by direction.
virtual Gfx::RectF onLayoutFrame (PaintSurface &surface, const Gfx::RectF &frameRect)=0
 Returns the content rectangle within frameRect.
virtual Gfx::RectF onLayoutMnemonic (PaintSurface &surface, const String &text, const Gfx::PointF &textPos, const Gfx::FontMetrics &fontMetrics, String::size_type mnemonicIndex)=0
 Returns the mnemonic underline rectangle.
virtual const PainteronGetTextPainter (PaintSurface &surface)=0
 Returns a painter with the current font and text color.
virtual void onLayoutContent (PaintSurface &surface, const Gfx::RectF &contentRect, Direction direction, const Gfx::SizeF &iconSize, const Gfx::SizeF &textSize, Gfx::RectF &iconRect, Gfx::RectF &textRect)=0
 Partitions contentRect into icon and text rectangles.
virtual void onRenderBackground (PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)=0
 Paints the background fill for state.
virtual void onPrepareIcon (const Gfx::Image &icon, Pixmap &picture, const ButtonState &state) const =0
 Prepares picture from icon for state.
virtual void onRenderChrome (PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)=0
 Paints the button chrome for state.
virtual void onRenderText (PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const ButtonState &state)=0
 Paints text at pos for state.
virtual void onRenderMnemonic (PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const ButtonState &state)=0
 Paints the mnemonic underline for state.
virtual void onRenderIcon (PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const ButtonState &state)=0
 Paints picture at pos for state.

Detailed Description

A ButtonRenderer is a Style::Facet for the push-button family. Named measure methods run inside-out: content, then frame. Named layout methods run outside-in: frame, then content and mnemonic. Named render methods paint prepared rectangles. The widget owns geometry and orchestrates those passes. The renderer does not mutate widget geometry.

Caption, icon, and mnemonic underline are independent layers. layoutContent() returns the text and icon rectangles. renderText() paints the caption in the text rectangle. renderIcon() paints the picture. renderMnemonic() paints the underline.

Derive a renderer to change the look of push buttons. Register it on a Style, or assign it to a widget with PushButton::setRenderer().

Member Function Documentation

◆ measureContent()

Gfx::SizeF measureContent ( PaintSurface & surface,
Direction direction,
const Gfx::SizeF & iconSize,
const Gfx::SizeF & textSize )

Computes the space needed for icon, text, and spacing between them. Does not include surface decoration (borders/padding).

◆ layoutContent()

void layoutContent ( PaintSurface & surface,
const Gfx::RectF & contentRect,
Direction direction,
const Gfx::SizeF & iconSize,
const Gfx::SizeF & textSize,
Gfx::RectF & iconRect,
Gfx::RectF & textRect )

The content rect is the output of layoutFrame (decoration already stripped). This method partitions it based on direction and sizes.

◆ renderBackground()

void renderBackground ( PaintContext & context,
const Gfx::RectF & rect,
const ButtonState & state )

Only fills if an explicit background is needed. Otherwise the call is a no-op, leaving the widget transparent.

◆ onReset()

virtual void onReset ( const StyleOptions & options)
protectedpure virtual

Resolves tokens from options and stores the painter and metric state used later by measure, layout, and render. Shared facets are reset when the application applies global options.

Reimplemented from Style::Facet.