CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
text.cppm
Go to the documentation of this file.
1
// Copyright (c) 2024, Víctor Castillo Agüero.
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
4
module
;
5
#include <cairomm-1.16/cairomm/cairomm.h>
6
#include <tracy/Tracy.hpp>
7
8
export
module
cydui.graphics.vector.elements.text
;
9
10
import
std;
11
12
export
import
cydui.dimensions
;
13
export
import
cydui.graphics.vector.element
;
14
15
export
namespace
vg
{
16
using
font_extents_t
= Cairo::FontExtents;
17
using
text_extents_t
= Cairo::TextExtents;
18
19
struct
text
:
element_t
,
20
attrs_core
<text>,
21
attrs_fill
<text>,
22
// attrs_stroke<text>,
23
attrs_font
<text>,
24
attr_x
<text>,
25
attr_y
<text>,
26
attr_rotate
<text>,
27
attr_pivot_x
<text>,
28
attr_pivot_y
<text>,
29
attr_scale_x
<text>,
30
attr_scale_y
<text>,
31
attr_w
<text>,
32
attr_h
<text> {
33
std::string
_text
;
34
explicit
text
(std::string
_text
)
35
:
_text
(std::move(
_text
)) {
36
// TracyAllocN(this, sizeof(decltype(*this)), "fragment_elements");
37
}
38
~text
()
override
{
39
// TracyFreeN(this, "fragment_elements");
40
}
41
void
apply_to
(
pixelmap_editor_t
& editor)
const override
{
42
apply_font
(editor);
43
// apply_stroke(editor);
44
apply_fill
(editor);
45
46
Cairo::FontExtents fextents;
47
editor->get_font_extents(fextents);
48
49
Cairo::TextExtents extents;
50
editor->get_text_extents(
_text
, extents);
51
52
editor->save();
53
editor->translate(
origin_x
+
_x
+
_pivot_x
,
origin_y
+
_y
-
_pivot_y
);
54
editor->rotate(
_rotate
* std::numbers::pi / 180.0);
55
editor->scale(
_scale_x
,
_scale_y
);
56
editor->move_to(-
_pivot_x
,
_pivot_y
);
57
set_source_to_fill
(editor);
58
editor->show_text(
_text
);
59
editor->restore();
60
61
// editor->move_to(origin_x + _x, origin_y + _y + fextents.ascent);
62
// editor->show_text(_text);
63
// editor->move_to(origin_x + _x + 5, origin_y + _y + fextents.height);
64
// editor->show_text(_text);
65
// editor->move_to(origin_x + _x + 10, origin_y + _y + extents.height);
66
// editor->show_text(_text);
67
}
68
69
footprint
get_footprint
()
const override
{
70
pixelmap_t
pm{0, 0};
71
pixelmap_editor_t
pe{pm};
72
73
apply_font
(pe);
74
apply_fill
(pe);
75
76
Cairo::FontExtents fextents;
77
pe->get_font_extents(fextents);
78
79
Cairo::TextExtents extents;
80
pe->get_text_extents(
_text
, extents);
81
82
return
{
83
.x =
static_cast<
int
>
(
_x
),
84
.
y
=
static_cast<
int
>
(
_y
- fextents.ascent),
85
.w =
static_cast<
int
>
(extents.x_advance),
86
.
h
=
static_cast<
int
>
(fextents.height),
87
};
88
}
89
90
font_extents_t
get_font_extents
()
const
{
91
pixelmap_t
pm{0, 0};
92
pixelmap_editor_t
pe{pm};
93
94
apply_font
(pe);
95
96
Cairo::FontExtents fextents;
97
pe->get_font_extents(fextents);
98
99
return
fextents;
100
}
101
102
text_extents_t
get_text_extents
()
const
{
103
pixelmap_t
pm{0, 0};
104
pixelmap_editor_t
pe{pm};
105
106
apply_font
(pe);
107
108
Cairo::TextExtents extents;
109
pe->get_text_extents(
_text
, extents);
110
111
return
extents;
112
}
113
};
114
}
// namespace vg
pixelmap_editor_t
Definition
pixelmap_editor.cppm:14
cydui.dimensions
cydui.graphics.vector.element
cydui.graphics.vector.elements.text
vg
Definition
attributes.cppm:14
vg::text_extents_t
Cairo::TextExtents text_extents_t
Definition
text.cppm:17
vg::font_extents_t
Cairo::FontExtents font_extents_t
Definition
text.cppm:16
pixelmap_t
Definition
pixelmap.cppm:19
vg::attr_h
height
Definition
attributes.cppm:367
vg::attr_h< text >::h
text & h(const quantify::quantity_t< UNIT, T > &_h_)
Definition
attributes.cppm:367
vg::attr_pivot_x
pivot_x - rotate pivot x-axis coordinate
Definition
attributes.cppm:345
vg::attr_pivot_x< text >::_pivot_x
int _pivot_x
Definition
attributes.cppm:345
vg::attr_pivot_y
pivot_y - rotate pivot y-axis coordinate
Definition
attributes.cppm:347
vg::attr_pivot_y< text >::_pivot_y
int _pivot_y
Definition
attributes.cppm:347
vg::attr_rotate
rotate - angle of rotation in degrees
Definition
attributes.cppm:343
vg::attr_rotate< text >::_rotate
double _rotate
Definition
attributes.cppm:343
vg::attr_scale_x
rotate - angle of rotation in degrees
Definition
attributes.cppm:353
vg::attr_scale_x< text >::_scale_x
double _scale_x
Definition
attributes.cppm:353
vg::attr_scale_y
rotate - angle of rotation in degrees
Definition
attributes.cppm:355
vg::attr_scale_y< text >::_scale_y
double _scale_y
Definition
attributes.cppm:355
vg::attr_w
width
Definition
attributes.cppm:365
vg::attr_x
x - x-axis coordinate
Definition
attributes.cppm:321
vg::attr_x< text >::_x
int _x
Definition
attributes.cppm:321
vg::attr_y
y - y-axis coordinate
Definition
attributes.cppm:323
vg::attr_y< text >::_y
int _y
Definition
attributes.cppm:323
vg::attr_y< text >::y
text & y(const quantify::quantity_t< UNIT, T > &_y_)
Definition
attributes.cppm:323
vg::attrs_core
Definition
attributes.cppm:529
vg::attrs_fill
Definition
attributes.cppm:494
vg::attrs_fill< text >::apply_fill
void apply_fill(pixelmap_editor_t &editor) const
Definition
attributes.cppm:496
vg::attrs_fill< text >::set_source_to_fill
void set_source_to_fill(pixelmap_editor_t &editor) const
Definition
attributes.cppm:500
vg::attrs_font
Definition
attributes.cppm:515
vg::attrs_font< text >::apply_font
void apply_font(pixelmap_editor_t &editor) const
Definition
attributes.cppm:517
vg::element_t::footprint
Definition
element.cppm:31
vg::element_t
Definition
element.cppm:19
vg::element_t::origin_y
int origin_y
Definition
element.cppm:21
vg::element_t::origin_x
int origin_x
Definition
element.cppm:20
vg::text::apply_to
void apply_to(pixelmap_editor_t &editor) const override
Definition
text.cppm:41
vg::text::text
text(std::string _text)
Definition
text.cppm:34
vg::text::get_font_extents
font_extents_t get_font_extents() const
Definition
text.cppm:90
vg::text::_text
std::string _text
Definition
text.cppm:33
vg::text::~text
~text() override
Definition
text.cppm:38
vg::text::get_footprint
footprint get_footprint() const override
Definition
text.cppm:69
vg::text::get_text_extents
text_extents_t get_text_extents() const
Definition
text.cppm:102
include
cyd_ui
graphics
vector
elements
text.cppm
Generated by
1.13.2