From 6a656e9a0fa22c16401292b253e61548cc332628 Mon Sep 17 00:00:00 2001 From: grovesNL Date: Fri, 24 Feb 2023 11:27:45 -0330 Subject: [PATCH] Exclude line y offset in height comparison We start `line_y` at an initial offset, so we need to account for this later when checking if the total height is beyond the buffer height. --- src/buffer.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 7bd6554..2f7f920 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -207,7 +207,7 @@ impl<'a, 'b> LayoutRunIter<'a, 'b> { line_i: 0, layout_i: 0, remaining_len: bottom_cropped_layout_lines as usize, - line_y: buffer.metrics.font_size - buffer.metrics.line_height, + line_y: buffer.metrics.y_offset(), total_layout: 0, } } @@ -234,7 +234,7 @@ impl<'a, 'b> Iterator for LayoutRunIter<'a, 'b> { } self.line_y += self.buffer.metrics.line_height; - if self.line_y > self.buffer.height { + if self.line_y - self.buffer.metrics.y_offset() > self.buffer.height { return None; } @@ -281,6 +281,10 @@ impl Metrics { line_height: self.line_height * scale, } } + + fn y_offset(&self) -> i32 { + self.font_size - self.line_height + } } impl fmt::Display for Metrics {