gpui/text_system/text_layout.rs
1use crate::{Pixels, ResolvedDirection, TextAlign, TextRun, UnicodeBidi};
2
3/// The paragraph base-direction policy supplied to a text backend.
4#[doc(hidden)]
5#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
6pub enum ParagraphDirection {
7 /// Determine paragraph direction from its source text.
8 #[default]
9 Auto,
10 /// Use an explicit left-to-right paragraph base direction.
11 LeftToRight,
12 /// Use an explicit right-to-left paragraph base direction.
13 RightToLeft,
14}
15
16impl From<ResolvedDirection> for ParagraphDirection {
17 fn from(direction: ResolvedDirection) -> Self {
18 match direction {
19 ResolvedDirection::LeftToRight => Self::LeftToRight,
20 ResolvedDirection::RightToLeft => Self::RightToLeft,
21 }
22 }
23}
24
25/// Direction, wrapping, and alignment options for a complete text document.
26#[doc(hidden)]
27#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
28pub struct TextLayoutOptions {
29 /// Optional soft-wrap width.
30 pub wrap_width: Option<Pixels>,
31 /// Soft-wrap line budget. Hard paragraph breaks are preserved; `Some(0)` behaves
32 /// like `Some(1)`. See [`WindowTextSystem::shape_text`].
33 pub line_clamp: Option<usize>,
34 /// Width used for horizontal alignment, independently of wrapping.
35 pub alignment_width: Option<Pixels>,
36 /// Horizontal text alignment.
37 pub text_align: TextAlign,
38 /// Paragraph base-direction policy.
39 pub direction: ParagraphDirection,
40 /// Bidirectional behavior applied to the complete document.
41 pub unicode_bidi: UnicodeBidi,
42}
43
44/// Complete input for one backend-owned text document layout.
45#[derive(Clone, Copy, Debug)]
46pub struct TextLayoutRequest<'a> {
47 /// UTF-8 source text.
48 pub text: &'a str,
49 /// Font size shared by all style runs.
50 pub font_size: Pixels,
51 /// Complete shaping and paint styles covering `text`.
52 pub runs: &'a [TextRun],
53 /// Wrapping, alignment, and bidirectional layout options.
54 pub options: TextLayoutOptions,
55}