guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <string>
26
27#include <utility/graphic/color.hpp>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/theme/typescale.hpp"
31
33{
34
65 class Text: public ecs::Component
66 {
67 private:
68 std::string _content {};
69 float _fontSize { 24 };
70 theme::FontWeight _fontWeight {
72 };
73
74 float _lineHeight { 0.0f };
75 float _letterSpacing { 0.0f };
76 std::size_t _cursorPosition {
77 0
78 };
79
80 public:
84 Text(void) = default;
85
89 ~Text(void) = default;
90
95 const std::string &getContent(void) const;
96
106 Text &setContent(const std::string &content);
107
112 float getFontSize(void) const;
113
123 Text &setFontSize(float fontSize);
124
130
142
148 float getLineHeight(void) const;
149
161 Text &setLineHeight(float lineHeight);
162
167 float getLetterSpacing(void) const;
168
178 Text &setLetterSpacing(float letterSpacing);
179
192 Text &setTypeToken(const theme::TypeToken &token);
193
199 std::size_t getCursorPosition(void) const;
200
211 Text &setCursorPosition(std::size_t position);
212
219 bool moveCursorLeft(void);
220
227 bool moveCursorRight(void);
228
236 Text &insertCharacter(char ch);
237
245 Text &insertString(const std::string &str);
246
254 bool deleteCharacterBefore(void);
255
263 bool deleteCharacterAfter(void);
264 };
265
266} // namespace guillaume::components
bool deleteCharacterBefore(void)
Delete the UTF-8 character before the cursor (backspace) and move the cursor back to where it started...
Definition text.cpp:180
Text & insertString(const std::string &str)
Insert a string at the cursor and move the cursor after it. Always marks the component changed,...
Definition text.cpp:172
bool moveCursorLeft(void)
Move the cursor to the start of the previous UTF-8 character. Marks the component changed when it mov...
Definition text.cpp:131
float getLetterSpacing(void) const
Get the extra space between letters.
Definition text.cpp:93
Text & setLineHeight(float lineHeight)
Set the minimum height of the text's bound.
Definition text.cpp:80
float getLineHeight(void) const
Get the minimum height of the text's bound.
Definition text.cpp:75
Text & setFontWeight(theme::FontWeight fontWeight)
Set the font weight.
Definition text.cpp:65
Text & setLetterSpacing(float letterSpacing)
Set the extra space between letters.
Definition text.cpp:98
Text & setCursorPosition(std::size_t position)
Move the editing cursor.
Definition text.cpp:124
~Text(void)=default
Default destructor for the Text component.
Text & setFontSize(float fontSize)
Set the font size.
Definition text.cpp:53
Text(void)=default
Default constructor for the Text component.
std::size_t getCursorPosition(void) const
Get the position of the editing cursor.
Definition text.cpp:119
bool moveCursorRight(void)
Move the cursor past the next UTF-8 character. Marks the component changed when it moves.
Definition text.cpp:147
const std::string & getContent(void) const
Get the text.
Definition text.cpp:29
theme::FontWeight getFontWeight(void) const
Get the font weight.
Definition text.cpp:60
float getFontSize(void) const
Get the font size.
Definition text.cpp:48
Text & insertCharacter(char ch)
Insert one byte at the cursor and move the cursor after it. Marks the component changed.
Definition text.cpp:164
Text & setContent(const std::string &content)
Replace the text.
Definition text.cpp:34
Text & setTypeToken(const theme::TypeToken &token)
Apply the four metrics of a typescale token at once: font size, weight, line height and letter spacin...
Definition text.cpp:108
bool deleteCharacterAfter(void)
Delete the UTF-8 character after the cursor (delete key); the cursor does not move....
Definition text.cpp:199
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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,...
Definition typescale.hpp:71
One text style: everything needed to measure and draw a piece of text.
Definition typescale.hpp:83