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..1f6c0563 100644 --- a/src/rendering/mod.rs +++ b/src/rendering/mod.rs @@ -58,9 +58,10 @@ where &self, display: &mut D, ) -> Result<&'a str, D::Error> { + let line_height = self.character_style.line_height(); let mut cursor = Cursor::new( self.bounds, - self.character_style.line_height(), + line_height, self.style.line_height, self.style.tab_size.into_pixels(&self.character_style), ); @@ -110,7 +111,7 @@ where let display_range = self .style .height_mode - .calculate_displayed_row_range(&cursor); + .calculate_displayed_row_range(&cursor, 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 +135,7 @@ where &mut display, &self.character_style, None, - Rectangle::new(line_start, Size::new(0, cursor.line_height())), + Rectangle::new(line_start, Size::new(0, 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() {