Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
selectable_text.hpp
Go to the documentation of this file.
1#pragma once
2
3// SelectableText — the capability that lets a text-bearing widget take part in
4// a selection that spans more than one widget.
5//
6// The shape follows the repo's "expose the pipeline, not just the endpoints"
7// rule. Both `Label` and `TextEditor` already compute, during paint, the exact
8// intermediate a selection needs: where each painted line sits and where every
9// cluster boundary falls inside it. `TextEditor` kept that intermediate private
10// in `LayoutSnapshot`; `Label` threw it away entirely. This header names that
11// intermediate once, so the hit-test and rect arithmetic are written a single
12// time instead of per widget.
13//
14// Offsets are UTF-8 BYTE offsets into `selectable_text()`, matching the units
15// `TextEditor` already uses for its own selection and the units
16// `text_accessibility.hpp` reports to assistive technology
17// (`selection_start_utf8` / `selection_end_utf8`).
18
20
21#include <string>
22#include <string_view>
23#include <vector>
24
25namespace pulp::view {
26
27class View;
28
37 int start_utf8 = 0;
38 int end_utf8 = 0;
39 float top = 0.0f;
40 float height = 0.0f;
41 std::vector<float> x_offsets;
42 std::vector<int> byte_offsets;
43};
44
53 bool measured = false;
54 std::vector<SelectableLine> lines;
55};
56
59 public:
60 virtual ~SelectableText() = default;
61
65 virtual std::string_view selectable_text() const = 0;
66
69
71 virtual void set_selection_highlight(int start_utf8, int end_utf8) = 0;
72
74 virtual bool selection_highlight(int& start_utf8, int& end_utf8) const = 0;
75
77 virtual View* selectable_view() = 0;
78 const View* selectable_view() const {
79 return const_cast<SelectableText*>(this)->selectable_view();
80 }
81};
82
91
100
103std::vector<Rect> selectable_rects_for_range(const SelectableLayout& layout, int start_utf8,
104 int end_utf8);
105
111
112} // namespace pulp::view
A widget whose painted text can join a document-level selection.
Definition selectable_text.hpp:58
const View * selectable_view() const
Definition selectable_text.hpp:78
virtual void set_selection_highlight(int start_utf8, int end_utf8)=0
Paint this byte range as selected. start >= end clears the highlight.
virtual View * selectable_view()=0
The View this capability is mixed into. Never null.
virtual ~SelectableText()=default
virtual SelectableLayout selectable_layout() const =0
Where the glyphs landed at the last paint. See SelectableLayout.
virtual bool selection_highlight(int &start_utf8, int &end_utf8) const =0
The current highlight. Returns false when nothing is highlighted.
virtual std::string_view selectable_text() const =0
The widget's text, in UTF-8.
Definition view.hpp:73
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
View * enclosing_text_selection_region(View &from)
The nearest enclosing text-content region of from (itself included), or null when it is not inside on...
int selectable_index_at_point(const SelectableLayout &layout, Point local)
Nearest cluster boundary to local within layout.
std::vector< Rect > selectable_rects_for_range(const SelectableLayout &layout, int start_utf8, int end_utf8)
The painted rects covering [start_utf8, end_utf8), in local coordinates, one per touched line.
int selectable_first_index(const SelectableLayout &layout)
First / last selectable byte offset in layout.
int selectable_last_index(const SelectableLayout &layout)
Definition geometry.hpp:20
The painted line geometry of one widget.
Definition selectable_text.hpp:52
bool measured
Definition selectable_text.hpp:53
std::vector< SelectableLine > lines
Definition selectable_text.hpp:54
One painted line of selectable text, in the widget's LOCAL coordinates.
Definition selectable_text.hpp:36
std::vector< float > x_offsets
Definition selectable_text.hpp:41
int start_utf8
First byte of this line in selectable_text().
Definition selectable_text.hpp:37
float height
Definition selectable_text.hpp:40
float top
Definition selectable_text.hpp:39
int end_utf8
One past this line's last byte.
Definition selectable_text.hpp:38
std::vector< int > byte_offsets
Definition selectable_text.hpp:42