Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
caret.hpp
Go to the documentation of this file.
1#pragma once
2
53
56
57#include <string>
58#include <string_view>
59
60namespace pulp::view {
61
68
70const char* caret_style_to_string(CaretStyle style) noexcept;
71
75CaretStyle caret_style_from_string(std::string_view name) noexcept;
76
80 float period_seconds = 1.06f;
82 float duty = 0.5f;
84 float solid_hold_seconds = 0.35f;
86 bool enabled = true;
87};
88
94void set_default_caret_blink(const CaretBlinkConfig& config) noexcept;
95
103public:
106 CaretBlink() noexcept;
107
108 void set_config(const CaretBlinkConfig& config) noexcept;
109 const CaretBlinkConfig& config() const noexcept { return config_; }
110
112 void keep_solid() noexcept;
113
115 void reset() noexcept;
116
119 void advance(float dt) noexcept;
120
124 bool visible() const noexcept;
125
129 bool holding_solid() const noexcept { return solid_remaining_ > 0.0f; }
130
131private:
132 CaretBlinkConfig config_{};
133 float phase_ = 0.0f;
134 float solid_remaining_ = 0.0f;
135};
136
145 float x = 0.0f;
146 float cell_top = 0.0f;
147 float cell_height = 0.0f;
148 float baseline = 0.0f;
149 float advance = 0.0f;
150 float nominal_advance = 0.0f;
151 float stroke = 1.5f;
152};
153
156float caret_advance(const CaretMetrics& metrics) noexcept;
157
161Rect caret_rect_for_style(CaretStyle style, const CaretMetrics& metrics) noexcept;
162
166 const CaretMetrics& metrics, canvas::Color color);
167
174 const CaretMetrics& metrics, canvas::Color color,
175 canvas::Color text_bg, const std::string& text,
176 float text_x);
177
178} // namespace pulp::view
Definition canvas.hpp:240
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
void paint_caret_over_text(canvas::Canvas &canvas, CaretStyle style, const CaretMetrics &metrics, canvas::Color color, canvas::Color text_bg, const std::string &text, float text_x)
Paint the caret, and for block redraw the covered glyph in text_bg so it stays legible against the fi...
CaretStyle default_caret_style() noexcept
Process-wide caret defaults.
@ text
Plain text (default color).
Definition code_editor_tokenizer.hpp:37
Rect caret_rect_for_style(CaretStyle style, const CaretMetrics &metrics) noexcept
The rect a caret of style occupies.
const CaretBlinkConfig & default_caret_blink() noexcept
void paint_caret(canvas::Canvas &canvas, CaretStyle style, const CaretMetrics &metrics, canvas::Color color)
Fill the caret rect.
float caret_advance(const CaretMetrics &metrics) noexcept
The width the underline and block shapes cover: advance when there is a glyph at the caret,...
CaretStyle
Caret shape. All three anchor at the same caret x.
Definition caret.hpp:63
@ block
Filled glyph cell; the covered glyph is drawn in the bg color.
Definition caret.hpp:66
@ ibeam
Vertical rule spanning the glyph cell. The default.
Definition caret.hpp:64
@ underline
Rule at the underline position, one glyph cell wide.
Definition caret.hpp:65
const char * caret_style_to_string(CaretStyle style) noexcept
Stable lowercase names, for serialization and the JS bridge.
void set_default_caret_blink(const CaretBlinkConfig &config) noexcept
@ color
Definition css_animation.hpp:121
CaretStyle caret_style_from_string(std::string_view name) noexcept
Parse a name produced by caret_style_to_string.
void set_default_caret_style(CaretStyle style) noexcept
Definition canvas.hpp:52
Blink timing. The defaults are the values Pulp has always used.
Definition caret.hpp:78
float duty
Fraction of the period the caret is visible. Clamped to [0, 1].
Definition caret.hpp:82
float period_seconds
Full on+off cycle, in seconds. Clamped to >= 0.05 s when applied.
Definition caret.hpp:80
float solid_hold_seconds
How long the caret stays solid after a movement or an edit.
Definition caret.hpp:84
bool enabled
False → the caret never blinks and is always visible while focused.
Definition caret.hpp:86
Where a caret goes, in the coordinate space the widget paints text in.
Definition caret.hpp:144
float cell_top
Top of the glyph cell.
Definition caret.hpp:146
float cell_height
Height of the glyph cell.
Definition caret.hpp:147
float stroke
I-beam width and underline thickness.
Definition caret.hpp:151
float advance
Width of the glyph at the caret; 0 at end of text.
Definition caret.hpp:149
float nominal_advance
Fallback width when advance is 0.
Definition caret.hpp:150
float x
Left edge of the caret, for every style.
Definition caret.hpp:145
float baseline
Text baseline, for the underline shape.
Definition caret.hpp:148
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52