Skip to main content

gpui/text_system/
inline.rs

1use crate::{Pixels, Point, ResolvedDirection, Size, TextLayoutOptions, TextRun, UnicodeBidi};
2use std::ops::Range;
3
4/// A directional scope within an inline text document.
5#[doc(hidden)]
6#[derive(Clone, Debug, Eq, Hash, PartialEq)]
7pub struct InlineBidiScope {
8    /// UTF-8 source range covered by this scope.
9    pub range: Range<usize>,
10    /// Resolved direction used by the scope.
11    pub direction: ResolvedDirection,
12    /// The CSS `unicode-bidi` behavior for the scope.
13    pub unicode_bidi: UnicodeBidi,
14}
15
16/// An atomic element inserted at a UTF-8 boundary in an inline document.
17#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
18pub struct InlineBoxRequest {
19    /// Identifier returned with the positioned box.
20    pub id: u64,
21    /// UTF-8 byte index at which to insert the box.
22    pub index: usize,
23    /// Measured size of the element.
24    pub size: Size<Pixels>,
25    /// Vertical alignment within the line containing this element.
26    pub vertical_align: crate::VerticalAlign,
27}
28
29/// Resolved font size and line height for part of an inline document.
30#[derive(Clone, Debug, Eq, Hash, PartialEq)]
31pub struct InlineTextStyle {
32    /// UTF-8 range receiving these resolved metrics.
33    pub range: Range<usize>,
34    /// Font size for this range.
35    pub font_size: Pixels,
36    /// Absolute line height for this range.
37    pub line_height: Pixels,
38}
39
40/// Complete input for a document containing text and element boxes.
41#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
42pub struct InlineLayoutRequest<'a> {
43    /// UTF-8 source text.
44    pub text: &'a str,
45    /// Complete shaping and paint styles covering `text`.
46    pub runs: &'a [TextRun],
47    /// Resolved font sizes and line heights within the document.
48    pub text_styles: &'a [InlineTextStyle],
49    /// Atomic boxes inserted into the text.
50    pub boxes: &'a [InlineBoxRequest],
51    /// Base font size.
52    pub font_size: Pixels,
53    /// Requested height of an ordinary text row.
54    pub line_height: Pixels,
55    /// Metrics for the inline container's base font.
56    pub text_metrics: InlineTextMetrics,
57    /// Wrapping, alignment, and bidirectional layout options.
58    pub options: TextLayoutOptions,
59    /// Directional scopes established by nested inline elements.
60    pub bidi_scopes: &'a [InlineBidiScope],
61}
62
63/// Font metrics that set the vertical extent of an inline line.
64#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
65pub struct InlineTextMetrics {
66    /// The distance from the baseline up to the top of the tallest glyphs.
67    pub ascent: Pixels,
68    /// The distance from the baseline down to the bottom of the lowest glyphs.
69    pub descent: Pixels,
70    /// The height of a lowercase `x` in the container's font.
71    pub x_height: Pixels,
72}
73
74/// One row of an inline layout, positioned relative to the layout's origin.
75#[derive(Clone, Copy, Debug, Default, PartialEq)]
76pub struct InlineVisualLine {
77    /// The top-left corner of the row, relative to the inline layout.
78    pub origin: Point<Pixels>,
79    /// The size of the row, including the room that atomic boxes need.
80    pub size: Size<Pixels>,
81    /// The baseline of the row, measured down from `origin.y`.
82    pub baseline: Pixels,
83}