Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
widget_painter.hpp File Reference

A pluggable paint delegate for Pulp's stock widgets. More...

#include <string>
#include <pulp/canvas/canvas.hpp>
#include <pulp/view/geometry.hpp>

Go to the source code of this file.

Classes

struct  pulp::view::ControlPaintState
 State every control hands to its painter. More...
struct  pulp::view::RotaryPaintState
 A rotary control. More...
struct  pulp::view::LinearPaintState
 A linear control (fader / slider / scroll thumb). More...
struct  pulp::view::ButtonPaintState
 A push / toggle button. More...
struct  pulp::view::ComboBoxPaintState
 A dropdown field (the closed control, not the open list). More...
struct  pulp::view::MenuBackgroundPaintState
 A menu panel's backing surface. bounds is the whole panel. More...
struct  pulp::view::MenuItemPaintState
 One menu row. bounds is the row rect within the menu panel. More...
struct  pulp::view::MenuHeaderPaintState
 A menu section title row. More...
struct  pulp::view::TextFieldPaintState
 A text field's frame. More...
struct  pulp::view::CaretPaintState
 The text-insertion caret. More...
class  pulp::view::WidgetPainter
 Install on a View to supply the pixels for the controls in its subtree. More...

Namespaces

namespace  pulp
namespace  pulp::view
 Hover-cursor tracking for platform window hosts.

Detailed Description

A pluggable paint delegate for Pulp's stock widgets.

A WidgetPainter replaces the rendering of a widget without replacing the widget: the control keeps its own hit-testing, value engine, accessibility node and event handling, and only the pixels are supplied by the delegate. That is the difference between this and subclassing — a subclass owns behavior; a painter owns look.

Installation and inheritance

Install with View::set_painter(std::shared_ptr<WidgetPainter>). The delegate applies to that view and to its whole subtree: a widget looks for a painter on itself first, then walks up the parent chain and uses the nearest one it finds (View::effective_painter()). A descendant that installs its own painter overrides the ancestor's for its own subtree. This is the same cascade shape as the typography inheritance in View (inheritable_text_color() and friends) — set it once on a panel and every control inside is skinned.

Partial override

Every hook is a non-pure virtual whose default returns false, meaning "I did not paint this — use the widget's stock rendering". A delegate therefore only overrides the controls it actually restyles; everything else keeps Pulp's default look. Return true from a hook once you have drawn.

Coordinates and units

Every state struct is expressed in the widget's own LOCAL coordinates, with the origin at the widget's top-left. Note the deliberate asymmetry between the rotary and linear states: a rotary control's position is a normalized proportion (the angle is derived from it), whereas a linear control's position is in pixels along the travel axis (the track geometry, not the value, is what a linear skin needs to place a thumb). Both forms are given because a skin that had to reconstruct one from the other would have to duplicate the widget's padding and thumb-size rules.

Colors

A delegate reads named color tokens off the source view with View::resolve_color(name, fallback), which walks the parent chain, and a host installs per-view overrides with View::set_color(name, color).