psychic-ui 0.0.0
Loading...
Searching...
No Matches
psychic_ui::TextEditing Class Reference

#include <TextEditing.hpp>

Classes

class  Clipboard

Public Types

enum class  Edit : std::uint8_t { None = 0 , Caret = 1u << 0 , Text = 1u << 1 , TextAndCaret = Caret | Text }
enum class  Direction : std::uint8_t { Backward , Forward }
enum class  Unit : std::uint8_t {
  Grapheme , Word , Line , LineEdge ,
  All
}

Public Member Functions

const icu::UnicodeString & text () const
std::string utf8 () const
Edit setText (const icu::UnicodeString &text)
unsigned int anchor () const
unsigned int caret () const
std::pair< unsigned int, unsigned int > selection () const
bool hasSelection () const
Edit select (unsigned int anchor, unsigned int caret)
bool multiline () const
void setMultiline (bool multiline)
bool readOnly () const
void setReadOnly (bool readOnly)
Edit insert (const icu::UnicodeString &str)
Edit erase (Direction direction, Unit unit, const TextGeometry &geometry)
Edit move (Direction direction, Unit unit, bool extend, const TextGeometry &geometry)
Edit selectAt (unsigned int index, unsigned int clickCount, bool extend)
Edit dragTo (unsigned int index)
Edit handleKey (Key key, Mod mod, const TextGeometry &geometry, Clipboard &clipboard)
std::pair< unsigned int, unsigned int > wordAt (unsigned int index) const

Detailed Description

The editing model of a text: the text itself, an anchor and a caret (the selection is what lies between them), the column that line moves keep, and what keys, typing and the mouse do to them. No Div: what shows the text answers the geometry questions (TextGeometry), and the clipboard is given (Clipboard).

Every index is in UTF-16 code units, like icu::UnicodeString's, and moves step over whole grapheme clusters (an emoji, a letter and its combining marks). Nothing is emitted: every operation returns what it changed (Edit), so that what owns the model tells the world once its own state is consistent.

Read-only text refuses edits but keeps the selection, the caret's moves and copying.

Member Enumeration Documentation

◆ Edit

enum class psychic_ui::TextEditing::Edit : std::uint8_t
strong

What an operation changed, as a bitmask (Edit::Caret | Edit::Text). Every combination is an enumerator, so that | never makes a value the type doesn't name.

◆ Unit

enum class psychic_ui::TextEditing::Unit : std::uint8_t
strong

How far a move or an erase goes

Member Function Documentation

◆ dragTo()

TextEditing::Edit psychic_ui::TextEditing::dragTo ( unsigned int index)

Drag from the last press to the index: the selection grows from what the press selected

◆ erase()

TextEditing::Edit psychic_ui::TextEditing::erase ( Direction direction,
Unit unit,
const TextGeometry & geometry )

Remove the selection, or else from the caret to where a move would go

◆ handleKey()

TextEditing::Edit psychic_ui::TextEditing::handleKey ( Key key,
Mod mod,
const TextGeometry & geometry,
Clipboard & clipboard )

What a key does: moves (Shift extends), erasing, Enter on several lines, select all, copy, cut and paste (Ctrl or Super)

Returns
What changed, Edit::None for a key it has no use for

◆ insert()

TextEditing::Edit psychic_ui::TextEditing::insert ( const icu::UnicodeString & str)

Replace the selection with the string, the caret after it

◆ move()

TextEditing::Edit psychic_ui::TextEditing::move ( Direction direction,
Unit unit,
bool extend,
const TextGeometry & geometry )

Move the caret, extending the selection from the anchor or collapsing it. Without extending, a grapheme move with a selection collapses it to its side.

◆ multiline()

bool psychic_ui::TextEditing::multiline ( ) const
inline

Whether the text keeps its line returns: on one line, inserted line returns become spaces and Enter does nothing

◆ readOnly()

bool psychic_ui::TextEditing::readOnly ( ) const
inline

Whether edits are refused

◆ select()

TextEditing::Edit psychic_ui::TextEditing::select ( unsigned int anchor,
unsigned int caret )

Select from the anchor to the caret (clamped to the text), forgetting the column kept

◆ selectAt()

TextEditing::Edit psychic_ui::TextEditing::selectAt ( unsigned int index,
unsigned int clickCount,
bool extend )

A press at the index: the caret there (1 click, or extending the selection), the word (2), the sentence (3) or everything (4 and more)

◆ selection()

std::pair< unsigned int, unsigned int > psychic_ui::TextEditing::selection ( ) const
inline

The selection, sorted: equal when nothing is selected

◆ setText()

TextEditing::Edit psychic_ui::TextEditing::setText ( const icu::UnicodeString & text)

Replace the text, the caret at its start

◆ utf8()

std::string psychic_ui::TextEditing::utf8 ( ) const

The text in UTF-8

◆ wordAt()

std::pair< unsigned int, unsigned int > psychic_ui::TextEditing::wordAt ( unsigned int index) const

The word around an index, which a double click selects


The documentation for this class was generated from the following files: