1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Text measurement for components. Every call is keyed by size and weight and
//! resolves to the same cached layout that painting and carets use.
use super::Context;
use crate::{
text::{StyleRun, TextFont, TextLayout},
FontWeight, MonospaceMetrics, Vec2,
};
use std::sync::Arc;
impl Context {
pub(crate) fn centered_line_offset(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
) -> f32 {
self.text.centered_line_offset(text, size, font)
}
pub(crate) fn text_carets(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
) -> Vec<(usize, f32)> {
self.text.carets(text, size, font)
}
pub(crate) fn measure_text(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
wrap: f32,
) -> Vec2 {
self.text.measure(text, size, font, wrap)
}
pub(crate) fn measure_text_layout(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
wrap: f32,
) -> (Vec2, f32) {
self.text.measure_with_wrap(text, size, font, wrap)
}
/// [`Context::measure_text_layout`] for text painted with an explicit tab width.
pub(crate) fn measure_text_layout_tab(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
wrap: f32,
tab: u16,
) -> (Vec2, f32) {
self.text.measure_with_wrap_tab(text, size, font, wrap, tab)
}
/// Shape one paragraph (no line breaks) through the same cache that painting uses.
pub(crate) fn paragraph_layout(
&mut self,
text: &str,
size: f32,
font: impl Into<TextFont>,
wrap: f32,
tab: u16,
) -> Arc<TextLayout> {
self.text.layout_with_tab(text, size, font, wrap, tab)
}
/// [`Self::paragraph_layout`] for a paragraph whose `runs` (see [`StyleRun::cover`]) differ
/// in weight, family or color.
pub(crate) fn rich_paragraph_layout(
&mut self,
text: &str,
runs: &Arc<[StyleRun]>,
size: f32,
font: impl Into<TextFont>,
wrap: f32,
tab: u16,
) -> Arc<TextLayout> {
self.text.rich_layout(text, runs, size, font, wrap, tab)
}
/// Cell width and line height of the monospace family at `size` and `weight`, for sizing
/// code views and [`ScrollArea::show_rows`](crate::ScrollArea::show_rows) without
/// estimates. They come from the layout that paints monospace text: a string of `n`
/// ASCII characters is `n * cell_width` wide.
pub fn monospace_metrics(&mut self, size: f32, weight: FontWeight) -> MonospaceMetrics {
self.text.monospace_metrics(size, weight)
}
/// Paragraph layouts shaped from scratch so far; cache reuse never increments it.
pub fn text_layouts_built(&self) -> u64 {
self.text.builds
}
}