BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-base / src / input / base / layout.rs

layout.rs

eef6c0a4 History
layout.rs 1.6 KiB Download Raw
1use std::{ops::Range, rc::Rc};
2
3use gpui::{Bounds, Half, Pixels, ShapedLine, TextAlign, px};
4
5use super::{WrappingIndent, display_map::LineLayout};
6
7#[derive(Clone, Default)]
8pub(crate) struct WhitespaceIndicators {
9 pub(crate) space: ShapedLine,
10 pub(crate) tab: ShapedLine,
11}
12
13#[derive(Clone)]
14pub(super) struct LastLayout {
15 pub(super) visible_range: Range<usize>,
16 pub(super) visible_buffer_lines: Vec<usize>,
17 pub(super) visible_line_byte_offsets: Vec<usize>,
18 pub(super) visible_top: Pixels,
19 pub(super) visible_range_offset: Range<usize>,
20 pub(super) lines: Rc<Vec<LineLayout>>,
21 pub(super) line_height: Pixels,
22 pub(super) wrap_width: Option<Pixels>,
23 pub(super) wrapping_indent: WrappingIndent,
24 pub(super) line_number_width: Pixels,
25 /// Width of one space in the editor font.
26 ///
27 /// Past the end of a line there are no glyphs to hit-test against, so this is the
28 /// step used to measure how far past the end a pointer sits.
29 pub(super) space_width: Pixels,
30 pub(super) cursor_bounds: Option<Bounds<Pixels>>,
31 pub(super) text_align: TextAlign,
32 pub(super) content_width: Pixels,
33}
34
35impl LastLayout {
36 pub(crate) fn line(&self, row: usize) -> Option<&LineLayout> {
37 let pos = self.visible_buffer_lines.binary_search(&row).ok()?;
38 self.lines.get(pos)
39 }
40
41 pub(super) fn alignment_offset(&self, line_width: Pixels) -> Pixels {
42 match self.text_align {
43 TextAlign::Left => px(0.),
44 TextAlign::Center => (self.content_width - line_width).half().max(px(0.)),
45 TextAlign::Right => (self.content_width - line_width).max(px(0.)),
46 }
47 }
48}