cranpose_text/layout_input.rs
1use crate::{layout_options::TextLayoutOptions, shaping_span::ShapingSpan, style::ParagraphStyle};
2
3/// A paragraph to lay out and how.
4#[derive(Clone, Debug)]
5pub struct LayoutInput<'a> {
6 /// The text.
7 pub text: &'a str,
8 /// The spans of the text, covering it in order with no gap.
9 pub spans: &'a [ShapingSpan<'a>],
10 /// The paragraph settings: direction, alignment and line height style.
11 pub paragraph: &'a ParagraphStyle,
12 /// The paragraph's lengths in pixels.
13 pub lengths: ParagraphLengths,
14 /// The narrowest the paragraph may be, in pixels.
15 pub min_width: f32,
16 /// The widest the paragraph may be, in pixels; infinite for lines that
17 /// end only at line breaks. As Compose sizes a paragraph, it takes its
18 /// max intrinsic width rounded up to whole device pixels, within these
19 /// two, and the widest only when they are equal; its lines wrap at that
20 /// width when they soft wrap, and ellipses cut to it.
21 pub max_width: f32,
22 /// Soft wrapping, the line limits and what shows where text overflows.
23 pub options: TextLayoutOptions,
24}
25
26/// A paragraph style's lengths resolved to pixels.
27#[derive(Clone, Copy, Debug)]
28pub struct ParagraphLengths {
29 /// The line height the style asks for, `None` for the fonts' own.
30 pub line_height: Option<f32>,
31 /// The indent of the first line of each paragraph.
32 pub first_line_indent: f32,
33 /// The indent of the other lines.
34 pub rest_line_indent: f32,
35 /// Device pixels per pixel of the layout, finite and positive: line boxes
36 /// round to whole device pixels, as Android's do.
37 pub grid: f32,
38}
39
40impl Default for ParagraphLengths {
41 fn default() -> Self {
42 Self {
43 line_height: None,
44 first_line_indent: 0.0,
45 rest_line_indent: 0.0,
46 grid: 1.0,
47 }
48 }
49}