From ef7694fdc6738f1ccaed568f90bd76d50c6488d0 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 18 Dec 2022 19:23:14 +0100 Subject: [PATCH] only draw visible text --- src/ui/bigtext/bigtext.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/bigtext/bigtext.py b/src/ui/bigtext/bigtext.py index c4a3207..719bb64 100644 --- a/src/ui/bigtext/bigtext.py +++ b/src/ui/bigtext/bigtext.py @@ -131,7 +131,7 @@ class BigText(QWidget): # noinspection PyArgumentList,PyTypeChecker class InnerBigText(QWidget): _byte_offset = 0 - _left_offset = 0 + _left_offset = 0 # number of characters the horizontal scrollbar was moved to the right scroll_lines = 0 longest_line = 0 @@ -504,12 +504,17 @@ class InnerBigText(QWidget): y_line_offset = self.char_height for line in self.lines: text = line.line_prepared_for_display() - painter.drawText(left_offset, y_line_offset, text) + leftmost_visible_char_index = line.column_to_char(self._left_offset - 1) + rightmost_visible_char_index = line.column_to_char(self._left_offset + math.ceil(self.columns_shown())) + text = text[ + leftmost_visible_char_index:rightmost_visible_char_index] # reduce string to the visible section before drawing + painter.drawText(0, y_line_offset, text) + # painter.drawText(left_offset, y_line_offset, text) y_line_offset = y_line_offset + self.char_height painter.end() end_ns = time.process_time_ns() - #print(f"paint took {(end_ns - start_ns) / 1000000.0}") + print(f"paint took {(end_ns - start_ns) / 1000000.0}") def draw_highlights(self, highlights: [HighlightedRange], painter: QPainter, y_line_offset: int):