Skip to content

Commit

Permalink
Return visible range as u32 range
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 15, 2023
1 parent c331baf commit bc04e19
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,22 @@ where
.style
.height_mode
.calculate_displayed_row_range(&cursor);
let display_range_start = display_range.start;
let display_range_count = (display_range.end - display_range.start).saturating_as();
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);

let line_start = cursor.line_start();

// FIXME: cropping isn't necessary for whole lines, but make sure not to blow up the
// binary size as well.
// binary size as well. We could also use a different way to consume invisible text.
let mut display = display.clipped(&Rectangle::new(
line_start + Point::new(0, display_range_start),
display_size,
));
if display_range_count == 0 {
// Display range can be empty if we are above, or below the visible text section
if anything_drawn {
// We are below, so we won't be drawing anything else
let remaining_bytes = state.parser.as_str().len();
let consumed_bytes = self.text.len() - remaining_bytes;

Expand Down
2 changes: 1 addition & 1 deletion src/style/height_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ 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<i32> {
pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<u32> {
let overdraw = match self {
HeightMode::Exact(overdraw) | HeightMode::ShrinkToText(overdraw) => overdraw,
HeightMode::FitToText => VerticalOverdraw::Visible,
Expand Down
9 changes: 5 additions & 4 deletions src/style/vertical_overdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ 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<i32> {
let line_height = cursor.line_height().saturating_as::<i32>();
pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<u32> {
let line_height = cursor.line_height();
match self {
VerticalOverdraw::FullRowsOnly => {
if cursor.in_display_area() {
Expand All @@ -30,8 +30,9 @@ impl VerticalOverdraw {
}

VerticalOverdraw::Hidden => {
let offset_top = (cursor.top_left().y - cursor.y).max(0);
let offset_bottom = (cursor.bottom() - cursor.y).min(0) + line_height;
let offset_top = (cursor.top_left().y - cursor.y).saturating_as::<u32>();
let offset_bottom =
line_height - (cursor.y - cursor.bottom()).saturating_as::<u32>();

offset_top..offset_bottom
}
Expand Down

0 comments on commit bc04e19

Please sign in to comment.