23#include "guillaume/components/text.hpp"
36 if (_content == content) {
41 if (_cursorPosition > _content.size()) {
42 _cursorPosition = _content.size();
67 if (_fontWeight == fontWeight) {
70 _fontWeight = fontWeight;
82 if (lineHeight < 0.0f) {
83 throw std::invalid_argument(
"Line height must be non-negative");
85 if (_lineHeight == lineHeight) {
88 _lineHeight = lineHeight;
95 return _letterSpacing;
100 if (_letterSpacing == letterSpacing) {
103 _letterSpacing = letterSpacing;
121 return _cursorPosition;
126 _cursorPosition = std::min(position, _content.size());
133 if (_cursorPosition == 0) {
140 }
while (_cursorPosition > 0
141 && (_content[_cursorPosition] & 0xC0) == 0x80);
149 if (_cursorPosition >= _content.size()) {
155 while (_cursorPosition < _content.size()
156 && (_content[_cursorPosition] & 0xC0) == 0x80) {
166 _content.insert(_cursorPosition, 1, ch);
174 _content.insert(_cursorPosition, str);
175 _cursorPosition += str.size();
182 if (_cursorPosition == 0 || _content.empty()) {
187 std::size_t deleteStart = _cursorPosition - 1;
188 while (deleteStart > 0 && (_content[deleteStart] & 0xC0) == 0x80) {
192 const std::size_t deleteLength = _cursorPosition - deleteStart;
193 _content.erase(deleteStart, deleteLength);
194 _cursorPosition = deleteStart;
201 if (_cursorPosition >= _content.size()) {
206 std::size_t deleteEnd = _cursorPosition + 1;
207 while (deleteEnd < _content.size()
208 && (_content[deleteEnd] & 0xC0) == 0x80) {
212 const std::size_t deleteLength = deleteEnd - _cursorPosition;
213 _content.erase(_cursorPosition, deleteLength);
bool deleteCharacterBefore(void)
Delete the UTF-8 character before the cursor (backspace) and move the cursor back to where it started...
Text & insertString(const std::string &str)
Insert a string at the cursor and move the cursor after it. Always marks the component changed,...
bool moveCursorLeft(void)
Move the cursor to the start of the previous UTF-8 character. Marks the component changed when it mov...
float getLetterSpacing(void) const
Get the extra space between letters.
Text & setLineHeight(float lineHeight)
Set the minimum height of the text's bound.
float getLineHeight(void) const
Get the minimum height of the text's bound.
Text & setFontWeight(theme::FontWeight fontWeight)
Set the font weight.
Text & setLetterSpacing(float letterSpacing)
Set the extra space between letters.
Text & setCursorPosition(std::size_t position)
Move the editing cursor.
Text & setFontSize(float fontSize)
Set the font size.
Text(void)=default
Default constructor for the Text component.
std::size_t getCursorPosition(void) const
Get the position of the editing cursor.
bool moveCursorRight(void)
Move the cursor past the next UTF-8 character. Marks the component changed when it moves.
const std::string & getContent(void) const
Get the text.
theme::FontWeight getFontWeight(void) const
Get the font weight.
float getFontSize(void) const
Get the font size.
Text & insertCharacter(char ch)
Insert one byte at the cursor and move the cursor after it. Marks the component changed.
Text & setContent(const std::string &content)
Replace the text.
Text & setTypeToken(const theme::TypeToken &token)
Apply the four metrics of a typescale token at once: font size, weight, line height and letter spacin...
bool deleteCharacterAfter(void)
Delete the UTF-8 character after the cursor (delete key); the cursor does not move....
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
State. Every class here is plain data attached to an entity.
FontWeight
Font weights available to the typescale. The value is the usual numeric weight (400 regular,...
One text style: everything needed to measure and draw a piece of text.
float letterSpacing
Extra space between characters, in dp.
FontWeight fontWeight
Font weight.
float fontSize
Font size, in dp.
float lineHeight
Distance between two baselines, in dp.