use std::{ops::Range, rc::Rc};
use gpui::{Bounds, Pixels, ShapedLine, TextAlign, px};
use super::{WrappingIndent, display_map::LineLayout};
#[derive(Clone, Default)]
pub(crate) struct WhitespaceIndicators {
pub(crate) space: ShapedLine,
pub(crate) tab: ShapedLine,
}
#[derive(Clone)]
pub(super) struct LastLayout {
pub(super) visible_range: Range<usize>,
pub(super) visible_buffer_lines: Vec<usize>,
pub(super) visible_line_byte_offsets: Vec<usize>,
pub(super) visible_top: Pixels,
pub(super) anchor_display_row: usize,
pub(super) visible_range_offset: Range<usize>,
pub(super) lines: Rc<Vec<LineLayout>>,
pub(super) line_height: Pixels,
pub(super) wrap_width: Option<Pixels>,
pub(super) wrapping_indent: WrappingIndent,
pub(super) line_number_width: Pixels,
pub(super) space_width: Pixels,
pub(super) cursor_bounds: Option<Bounds<Pixels>>,
pub(super) text_align: TextAlign,
pub(super) content_width: Pixels,
}
impl LastLayout {
pub(crate) fn line(&self, row: usize) -> Option<&LineLayout> {
let pos = self.visible_buffer_lines.binary_search(&row).ok()?;
self.lines.get(pos)
}
pub(super) fn local_row_y(&self, row_offset: isize) -> Pixels {
self.visible_top + self.line_height * (row_offset as f32)
}
pub(super) fn display_row_y(&self, display_row: usize) -> Pixels {
let delta = display_row as f64 - self.anchor_display_row as f64;
self.visible_top + px((f64::from(f32::from(self.line_height)) * delta) as f32)
}
}