#pragma once // Spec: SPEC.md UX-INPUT-01. Single-line TextField / SecureField and multi-line TextEditor with caret, // selection, clipboard, word movement, IME commit text. Caps: spec kMaxEditChars. #include #include #include #include "ui/Views.hpp" namespace dp::ui { // Screen-side handle: query/move the caret, focus the field. Valid after the first frame. class TextInputHandle { public: int caret() const; // byte offset void setCaret(int byteOffset); void focus(); bool focused() const; void insertAtCaret(const std::string& utf8); // replaces the selection std::uint64_t id = 0; Binding* binding = nullptr; // set by the view each frame }; struct TextInputOptions { std::string placeholder; bool secure = false; std::optional font; std::function onSubmit; // Return in single-line mode std::function onChange; std::function onCaretChange; std::shared_ptr handle; int minLines = 1; // editor: grows between minLines and maxLines int maxLines = 6; bool disabled = false; std::size_t maxChars = 0; // 0 = global cap }; ViewPtr TextField(Binding text, TextInputOptions options = {}); ViewPtr TextEditor(Binding text, TextInputOptions options = {}); // Clipboard (SDL3) with a size cap. struct Clipboard { static std::string get(); static void set(const std::string& utf8); static constexpr std::size_t kMaxBytes = 4u * 1024u * 1024u; }; } // namespace dp::ui