From 4251b1ac80eb6f17650126d5aae335bb16aa58ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sun, 15 Oct 2023 10:53:32 +0200 Subject: [PATCH] Don't store line height in cursor --- src/rendering/cursor.rs | 8 -------- src/rendering/mod.rs | 7 +++++-- src/style/height_mode.rs | 8 ++++++-- src/style/vertical_overdraw.rs | 7 +++++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/rendering/cursor.rs b/src/rendering/cursor.rs index f35e8065..018e93f7 100644 --- a/src/rendering/cursor.rs +++ b/src/rendering/cursor.rs @@ -99,7 +99,6 @@ pub struct Cursor { bottom: i32, line_width: u32, - line_height: u32, line_spacing: i32, tab_width: u32, } @@ -122,7 +121,6 @@ impl Cursor { - base_line_height.saturating_as::(), line_width: bounds.size.width, - line_height: base_line_height, line_spacing: line_height.to_absolute(base_line_height).saturating_as(), tab_width, } @@ -162,12 +160,6 @@ impl Cursor { self.line_width } - /// Returns the height of a line. - #[inline] - pub fn line_height(&self) -> u32 { - self.line_height - } - /// Starts a new line. #[inline] pub fn new_line(&mut self) { diff --git a/src/rendering/mod.rs b/src/rendering/mod.rs index eb0c8ce5..9ba9d62c 100644 --- a/src/rendering/mod.rs +++ b/src/rendering/mod.rs @@ -110,7 +110,7 @@ where let display_range = self .style .height_mode - .calculate_displayed_row_range(&cursor); + .calculate_displayed_row_range(&cursor, self.character_style.line_height()); let display_range_start = display_range.start.saturating_as::(); let display_range_count = display_range.count() as u32; let display_size = Size::new(cursor.line_width(), display_range_count); @@ -134,7 +134,10 @@ where &mut display, &self.character_style, None, - Rectangle::new(line_start, Size::new(0, cursor.line_height())), + Rectangle::new( + line_start, + Size::new(0, self.character_style.line_height()), + ), )?; state.plugin.on_rendering_finished(); return Ok(self.text.get(consumed_bytes..).unwrap()); diff --git a/src/style/height_mode.rs b/src/style/height_mode.rs index d3fce6c5..b5dcea81 100644 --- a/src/style/height_mode.rs +++ b/src/style/height_mode.rs @@ -202,12 +202,16 @@ impl HeightMode { /// If a line does not fully fit in the bounding box, some `HeightMode` options allow drawing /// partial lines. For a partial line, this function calculates, which rows of each character /// should be displayed. - pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { + pub(crate) fn calculate_displayed_row_range( + self, + cursor: &Cursor, + line_height: u32, + ) -> Range { let overdraw = match self { HeightMode::Exact(overdraw) | HeightMode::ShrinkToText(overdraw) => overdraw, HeightMode::FitToText => VerticalOverdraw::Visible, }; - overdraw.calculate_displayed_row_range(cursor) + overdraw.calculate_displayed_row_range(cursor, line_height) } } diff --git a/src/style/vertical_overdraw.rs b/src/style/vertical_overdraw.rs index ef0d78a9..5c6c1fc6 100644 --- a/src/style/vertical_overdraw.rs +++ b/src/style/vertical_overdraw.rs @@ -18,8 +18,11 @@ pub enum VerticalOverdraw { impl VerticalOverdraw { /// Calculate the range of rows of the current line that can be drawn. - pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range { - let line_height = cursor.line_height(); + pub(crate) fn calculate_displayed_row_range( + self, + cursor: &Cursor, + line_height: u32, + ) -> Range { match self { VerticalOverdraw::FullRowsOnly => { if cursor.in_display_area() {