Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
scene_text.hpp
Go to the documentation of this file.
1// SceneText — retained text node.
2//
3// Holds the string + family/size + paint; at paint time emits
4// `Canvas::set_font` + `Canvas::fill_text` (or `stroke_text`) so any
5// backend with font support (Skia, CG) renders it natively. The widget
6// side (`pulp::view::Label`) is the caller that drives the canonical
7// TextShaper measure-once pipeline; SceneText
8// stays intentionally thin so that a vector scene serialized from SVG
9// or design-tool import has somewhere to land its `<text>` element.
10#pragma once
11
13
14#include <string>
15#include <utility>
16
17namespace pulp::canvas {
18
19class SceneText : public SceneNode {
20public:
22
23 void set_position(float x, float y) {
24 if (x == x_ && y == y_) return;
25 x_ = x; y_ = y;
26 mark_dirty();
27 }
28 float x() const { return x_; }
29 float y() const { return y_; }
30
31 void set_text(std::string text) {
32 if (text_ == text) return;
33 text_ = std::move(text);
34 mark_dirty();
35 }
36 const std::string& text() const { return text_; }
37
38 void set_font(std::string family, float size) {
39 if (font_family_ == family && font_size_ == size) return;
40 font_family_ = std::move(family);
41 font_size_ = size;
42 mark_dirty();
43 }
44 const std::string& font_family() const { return font_family_; }
45 float font_size() const { return font_size_; }
46
51 void set_measured_width(float w) {
52 if (measured_width_ == w) return;
53 measured_width_ = w;
54 mark_dirty();
55 }
56 float measured_width() const { return measured_width_; }
57
58 Color fill_color() const { return fill_color_; }
60 if (fill_color_ == c) return;
61 fill_color_ = c;
62 mark_dirty();
63 }
64
65 bool stroke_enabled() const { return stroke_enabled_; }
66 void set_stroke_enabled(bool v) {
67 if (stroke_enabled_ == v) return;
68 stroke_enabled_ = v;
69 mark_dirty();
70 }
71 Color stroke_color() const { return stroke_color_; }
73 if (stroke_color_ == c) return;
74 stroke_color_ = c;
75 mark_dirty();
76 }
77
78 // ── SceneNode overrides ──────────────────────────────────────────────
79 SceneRect local_bounds() const override;
80 void paint_geometry(Canvas& canvas) const override;
81
82private:
83 float x_ = 0, y_ = 0;
84 std::string text_;
85 std::string font_family_ = "system";
86 float font_size_ = 12.0f;
87 float measured_width_ = 0.0f; // optional override; otherwise estimated
88 Color fill_color_ = Color::rgba(0, 0, 0, 1);
89 Color stroke_color_ = Color::rgba(0, 0, 0, 1);
90 bool stroke_enabled_ = false;
91};
92
93} // namespace pulp::canvas
Definition canvas.hpp:240
void mark_dirty()
Mark this node and (recursively) every ancestor dirty.
SceneNode(SceneNodeKind kind)
Definition scene_node.hpp:108
void set_stroke_enabled(bool v)
Definition scene_text.hpp:66
float font_size() const
Definition scene_text.hpp:45
SceneText()
Definition scene_text.hpp:21
void set_measured_width(float w)
Approximate text width used by local_bounds().
Definition scene_text.hpp:51
float y() const
Definition scene_text.hpp:29
void set_stroke_color(Color c)
Definition scene_text.hpp:72
void set_fill_color(Color c)
Definition scene_text.hpp:59
void set_text(std::string text)
Definition scene_text.hpp:31
SceneRect local_bounds() const override
Local-coordinate bounding box (pre-transform, pre-opacity).
float measured_width() const
Definition scene_text.hpp:56
float x() const
Definition scene_text.hpp:28
Color stroke_color() const
Definition scene_text.hpp:71
void paint_geometry(Canvas &canvas) const override
Paint this node (and its sub-tree) into canvas.
void set_position(float x, float y)
Definition scene_text.hpp:23
void set_font(std::string family, float size)
Definition scene_text.hpp:38
bool stroke_enabled() const
Definition scene_text.hpp:65
const std::string & font_family() const
Definition scene_text.hpp:44
Color fill_color() const
Definition scene_text.hpp:58
const std::string & text() const
Definition scene_text.hpp:36
Definition affine_transform.hpp:24
SceneNodeKind
Kind discriminator — keeps dynamic_cast off the hot path.
Definition scene_node.hpp:91
Definition canvas.hpp:52
static constexpr Color rgba(float r, float g, float b, float a=1.0f)
Construct from float channels [0,1] (>1.0 allowed for HDR).
Definition canvas.hpp:56
Axis-aligned bounding box used for repaint-rect math.
Definition scene_node.hpp:27