fret_render_text/
line_layout.rs1use crate::geometry::{TextLineCluster, TextLineDecorationGeometry, TextLineGeometry};
2use fret_core::geometry::Px;
3use std::sync::Arc;
4
5#[derive(Debug, Clone)]
6pub struct TextLineLayout {
7 start: usize,
8 end: usize,
9 width: Px,
10 y_top: Px,
11 y_baseline: Px,
13 height: Px,
14 ascent: Px,
15 descent: Px,
16 ink_ascent: Px,
17 ink_descent: Px,
18 caret_stops: Vec<(usize, Px)>,
19 clusters: Arc<[TextLineCluster]>,
20}
21
22impl TextLineLayout {
23 #[allow(clippy::too_many_arguments)]
24 pub(crate) fn new(
25 start: usize,
26 end: usize,
27 width: Px,
28 y_top: Px,
29 y_baseline: Px,
30 height: Px,
31 ascent: Px,
32 descent: Px,
33 ink_ascent: Px,
34 ink_descent: Px,
35 caret_stops: Vec<(usize, Px)>,
36 clusters: Arc<[TextLineCluster]>,
37 ) -> Self {
38 Self {
39 start,
40 end,
41 width,
42 y_top,
43 y_baseline,
44 height,
45 ascent,
46 descent,
47 ink_ascent,
48 ink_descent,
49 caret_stops,
50 clusters,
51 }
52 }
53
54 pub fn start(&self) -> usize {
55 self.start
56 }
57
58 pub fn end(&self) -> usize {
59 self.end
60 }
61
62 pub fn width(&self) -> Px {
63 self.width
64 }
65
66 pub fn y_top(&self) -> Px {
67 self.y_top
68 }
69
70 pub fn y_baseline(&self) -> Px {
71 self.y_baseline
72 }
73
74 pub fn height(&self) -> Px {
75 self.height
76 }
77
78 pub fn ascent(&self) -> Px {
79 self.ascent
80 }
81
82 pub fn descent(&self) -> Px {
83 self.descent
84 }
85
86 pub fn ink_ascent(&self) -> Px {
87 self.ink_ascent
88 }
89
90 pub fn ink_descent(&self) -> Px {
91 self.ink_descent
92 }
93
94 pub fn caret_stops(&self) -> &[(usize, Px)] {
95 self.caret_stops.as_ref()
96 }
97
98 pub fn caret_stops_capacity(&self) -> usize {
99 self.caret_stops.capacity()
100 }
101
102 pub fn clusters(&self) -> &[TextLineCluster] {
103 self.clusters.as_ref()
104 }
105}
106
107impl TextLineGeometry for TextLineLayout {
108 fn start(&self) -> usize {
109 self.start()
110 }
111
112 fn end(&self) -> usize {
113 self.end()
114 }
115
116 fn y_top(&self) -> Px {
117 self.y_top()
118 }
119
120 fn height(&self) -> Px {
121 self.height()
122 }
123
124 fn caret_stops(&self) -> &[(usize, Px)] {
125 self.caret_stops()
126 }
127
128 fn clusters(&self) -> &[TextLineCluster] {
129 self.clusters()
130 }
131}
132
133impl TextLineDecorationGeometry for TextLineLayout {
134 fn y_baseline(&self) -> Px {
135 self.y_baseline()
136 }
137}