Skip to content

Commit

Permalink
Don't store line height in cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 15, 2023
1 parent bc04e19 commit 4251b1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/rendering/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ pub struct Cursor {
bottom: i32,

line_width: u32,
line_height: u32,
line_spacing: i32,
tab_width: u32,
}
Expand All @@ -122,7 +121,6 @@ impl Cursor {
- base_line_height.saturating_as::<i32>(),

line_width: bounds.size.width,
line_height: base_line_height,
line_spacing: line_height.to_absolute(base_line_height).saturating_as(),
tab_width,
}
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>();
let display_range_count = display_range.count() as u32;
let display_size = Size::new(cursor.line_width(), display_range_count);
Expand All @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions src/style/height_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
pub(crate) fn calculate_displayed_row_range(
self,
cursor: &Cursor,
line_height: u32,
) -> Range<u32> {
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)
}
}
7 changes: 5 additions & 2 deletions src/style/vertical_overdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
let line_height = cursor.line_height();
pub(crate) fn calculate_displayed_row_range(
self,
cursor: &Cursor,
line_height: u32,
) -> Range<u32> {
match self {
VerticalOverdraw::FullRowsOnly => {
if cursor.in_display_area() {
Expand Down

0 comments on commit 4251b1a

Please sign in to comment.