utility 2026.2.0
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
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
31#pragma once
32
33#include <cmath>
34#include <string>
35
36#include <utility/graphic/renderable.hpp>
37
39#include <utility/graphic/pose.hpp>
40
41#include <utility/graphic/mesh.hpp>
42
43#include <utility/graphic/text/font.hpp>
44
46#include <utility/graphic/size.hpp>
47#include <utility/math/vector.hpp>
48
49#include <utility/system_io/file.hpp>
50#include <utility/ressource_provider.hpp>
51
53
56
60#define DEFAULT_FONT_COLOR \
61 utility::graphic::Color<std::uint8_t>(255, 255, 255, 255)
62
63namespace utility::graphic
64{
65
72 class Text:
73 public Renderable,
74 protected logging::Loggable<Text, logging::DefaultLogger>
75 {
76 private:
77 std::string _content;
78 std::string _fontPath;
79 float _fontSize;
80
81 protected:
82 std::shared_ptr<Font>
84
94 void updateMesh(void);
95
112 codePointString utf8ToCodepoints(const std::string &str)
113 const; //< Convert UTF-8 string to Unicode code points
114
115 public:
133 Text(std::shared_ptr<RessourceProvider> ressourceProvider,
134 const PoseF &pose, const Color32Bit &color,
135 const std::string &content, uint32_t fontSize,
136 const std::string &font);
137
142 Text(const Text &other) = delete;
143
148 Text(Text &&other) noexcept = default;
149
161 std::shared_ptr<Mesh> getMesh() const;
162
175 const std::string &getFontFamily(void) const;
176
182 Text &operator=(const Text &other) = delete;
183
189 Text &operator=(Text &&other) noexcept = default;
190
195 const std::string &getContent(void) const;
196
202 Text &setContent(const std::string &content);
203
208 uint32_t getFontSize(void) const;
209
222
228 Text &setFontSize(uint32_t fontSize);
229
234 RenderableType getRenderableType(void) const override;
235
240 std::string getMaterialName() const override;
241
246 bool empty(void) const noexcept
247 {
248 return _content.empty();
249 }
250
255 bool hasFontPath(void) const noexcept
256 {
257 return !_fontPath.empty();
258 }
259
265 {
266 _content.clear();
267 return *this;
268 }
269
275 bool operator==(const Text &other) const
276 {
277 return _content == other._content && _fontPath == other._fontPath
278 && _fontSize == other._fontSize && _color == other._color
279 && _pose == other._pose;
280 }
281
287 bool operator!=(const Text &other) const
288 {
289 return !(*this == other);
290 }
291 };
292
293} // namespace utility::graphic
The Renderable class represents an object that can be rendered in the graphics application.
PoseF _pose
World pose (position and orientation) of the text.
Color32Bit _color
Text RGBA color.
Storage for text content and rendering properties.
Definition text.hpp:75
Text(Text &&other) noexcept=default
Move constructor.
std::shared_ptr< Font > _font
Shared pointer to the font used for rendering.
Definition text.hpp:83
Text & clearContent(void)
Clear text content.
Definition text.hpp:264
bool operator!=(const Text &other) const
Inequality comparison.
Definition text.hpp:287
codePointString utf8ToCodepoints(const std::string &str) const
Converts a UTF-8 encoded string to a string of Unicode code points.
Definition text.cpp:177
Text(const Text &other)=delete
Copy constructor.
bool empty(void) const noexcept
Check if text content is empty.
Definition text.hpp:246
Text & operator=(const Text &other)=delete
Copy assignment operator.
const std::string & getFontFamily(void) const
Get the font family (path) used for rendering the text.
Definition text.cpp:53
void updateMesh(void)
Updates the mesh for rendering the text based on the current content, font, and font size.
Definition text.cpp:117
bool operator==(const Text &other) const
Equality comparison.
Definition text.hpp:275
std::string getMaterialName() const override
Get the material name.
Definition text.cpp:89
bool hasFontPath(void) const noexcept
Check if font path is set.
Definition text.hpp:255
const std::string & getContent(void) const
Get the text content.
Definition text.cpp:58
std::shared_ptr< Mesh > getMesh() const
Get the mesh for rendering the text.
Definition text.cpp:48
RenderableType getRenderableType(void) const override
Get the RenderableType of this object.
Definition text.cpp:84
Text & setFontSize(uint32_t fontSize)
Set the font size.
Definition text.cpp:75
Text & operator=(Text &&other) noexcept=default
Move assignment operator.
uint32_t getFontSize(void) const
Get the font size.
Definition text.cpp:70
Text & setContent(const std::string &content)
Set the text content.
Definition text.cpp:63
graphic::SizeF getTextDimensions(void) const
Get the dimensions of the rendered text.
Definition text.cpp:94
Mixin base class providing logging capabilities to derived classes.
Definition loggable.hpp:55
Code point definitions for text rendering.
std::vector< uint32_t > codePointString
A type representing a string of Unicode code points.
RGBA color representation with blending and manipulation operations.
Platform-specific default logger alias.
Mixin class to provide logging capabilities to derived classes.