MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TextEdit.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "TypeSetter.hpp"
4
6
7/**
8 * @file TextEdit.hpp
9 * @brief Text editing operations: a mutable buffer plus a byte-offset
10 * cursor, and the operations that keep it correct.
11 *
12 * A mutable counterpart to copy()/x_at()/index_at() in TypeSetter.hpp:
13 * those query a fixed string at a byte position or range, these mutate one
14 * in place at a single byte-offset cursor. Built entirely from
15 * is_control(), encode_utf8(), and next_codepoint_offset()/
16 * previous_codepoint_offset() - no atlas, no layout, no rendering
17 * dependency of any kind. Scoped to text editing generally, not tied to
18 * any one caller - room for word-boundary movement, selection ranges,
19 * Home/End, and similar to land here later.
20 */
21
22/**
23 * @struct EditableText
24 * @brief Mutable UTF-8 text plus a byte-offset cursor.
25 *
26 * cursor is always a codepoint boundary into text: every function below
27 * that moves or writes it goes through next_codepoint_offset(),
28 * previous_codepoint_offset(), or encode_utf8(), so nothing here ever sets
29 * it to an arbitrary byte offset.
30 */
32 std::string text;
33 size_t cursor { 0 };
34};
35
36/**
37 * @brief Insert one codepoint at the cursor, advancing it past the insert.
38 *
39 * No-op if is_control(codepoint) is true.
40 */
41MAYAFLUX_API void insert_codepoint(EditableText& s, uint32_t codepoint);
42
43/**
44 * @brief Insert one raw ASCII byte at the cursor, advancing it past the insert.
45 *
46 * For control bytes ('\\t', '\\n') that structurally never reach
47 * WindowEventType::TEXT_INPUT and so cannot go through insert_codepoint().
48 */
49MAYAFLUX_API void insert_literal(EditableText& s, char c);
50
51/**
52 * @brief Move the cursor by @p n codepoints.
53 *
54 * Positive @p n moves toward the end of the text, negative toward the
55 * start. Clamps at whichever text boundary is reached first rather than
56 * wrapping or erroring on an out-of-range count.
57 */
58MAYAFLUX_API void move(EditableText& s, int n);
59
60/**
61 * @brief Erase @p n codepoints from the cursor.
62 *
63 * Positive @p n erases forward: the codepoints at and after the cursor,
64 * which does not move. Negative @p n erases backward: the codepoints
65 * before the cursor, which moves back by the same count. Clamps at
66 * whichever text boundary is reached first.
67 */
68MAYAFLUX_API void erase(EditableText& s, int n);
69
70} // namespace MayaFlux::Portal::Text
void move(EditableText &s, int n)
Move the cursor by n codepoints.
Definition TextEdit.cpp:20
void erase(EditableText &s, int n)
Erase n codepoints from the cursor.
Definition TextEdit.cpp:31
void insert_codepoint(EditableText &s, uint32_t codepoint)
Insert one codepoint at the cursor, advancing it past the insert.
Definition TextEdit.cpp:5
void insert_literal(EditableText &s, char c)
Insert one raw ASCII byte at the cursor, advancing it past the insert.
Definition TextEdit.cpp:14
Mutable UTF-8 text plus a byte-offset cursor.
Definition TextEdit.hpp:31