A pluggable sizing delegate for Pulp's stock widgets — the sibling of WidgetPainter (widget_painter.hpp). More...
Go to the source code of this file.
Classes | |
| struct | pulp::view::FontSpec |
| A font request, as a delegate expresses it. More... | |
| struct | pulp::view::EdgeInsets |
| Per-side insets in pixels. More... | |
| struct | pulp::view::MenuItemMetricsQuery |
| What a menu row is, when the delegate is asked how big it should be. More... | |
| struct | pulp::view::BoxSize |
| A control's natural size. More... | |
| class | pulp::view::WidgetMetrics |
| Install on a View to supply the SIZES of the controls in its subtree. More... | |
Namespaces | |
| namespace | pulp |
| namespace | pulp::view |
| Hover-cursor tracking for platform window hosts. | |
A pluggable sizing delegate for Pulp's stock widgets — the sibling of WidgetPainter (widget_painter.hpp).
A WidgetPainter answers "what pixels?". A WidgetMetrics answers "how big?". They are deliberately separate objects with the same installation and cascade rules, because the two questions have different lifetimes: metrics are consulted during LAYOUT (possibly many times, with no canvas and no pixels), painting happens once per frame afterwards. Fusing them into one class would force every skin that only restyles to also be dragged into the layout pass.
View::set_metrics(std::shared_ptr<WidgetMetrics>). Applies to that view and its whole subtree; a widget uses the nearest delegate found by walking up the parent chain (View::effective_metrics()). Identical cascade to effective_painter().
Every hook is non-pure and returns false by default, meaning "I have no opinion — use the widget's stock metric". A delegate therefore only sizes the things it actually wants to size.
Pulp lays out with a flex/grid engine that measures leaf views through View::intrinsic_width() / View::intrinsic_height(). A widget that wants its size delegated simply consults effective_metrics() from inside those two overrides. There is no second seam and no parallel measure protocol: the delegate feeds the SAME function the layout engine already calls. Widgets that are not laid out by the engine at all — an overlay panel such as ContextMenu, which positions itself from an anchor point — consult the delegate directly when they compute their own box.
Metric hooks run during layout, where there is no canvas. Measure with pulp::canvas::global_text_shaper(), which is the same shaper the painter draws with, so a measured width and a drawn width cannot disagree.