diff --git a/src/textual/widget.py b/src/textual/widget.py index fca6e3aec..753f74821 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -974,7 +974,7 @@ class Widget(DOMNode): else: self.refresh() - def _render_lines(self) -> None: + def _render_content(self) -> None: """Render all lines.""" width, height = self.content_size renderable = self.render_styled() @@ -985,14 +985,17 @@ class Widget(DOMNode): self._render_cache = RenderCache(self.content_size, lines) self._dirty_regions.clear() - def _crop_lines(self, lines: Lines, x1, x2) -> Lines: - width = self.size.width - if (x1, x2) != (0, width): - _line_crop = line_crop - lines = [_line_crop(line, x1, x2, width) for line in lines] - return lines + def render_line(self, y: int) -> list[Segment]: + """Render a line of content. - def render_line(self, y) -> list[Segment]: + Args: + y (int): Y Coordinate of line. + + Returns: + list[Segment]: A rendered line. + """ + if self._dirty_regions: + self._render_content() line = self._render_cache.lines[y] return line @@ -1005,9 +1008,6 @@ class Widget(DOMNode): Returns: Lines: A list of list of segments """ - if self._dirty_regions: - self._render_lines() - lines = self._styles_cache.render_widget(self, crop) return lines diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index 94d86cbec..1b04ac790 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -499,6 +499,14 @@ class DataTable(ScrollView, Generic[CellType]): return segments def render_line(self, y: int) -> list[Segment]: + """Render a line of content. + + Args: + y (int): Y Coordinate of line. + + Returns: + list[Segment]: A rendered line. + """ width, height = self.content_size scroll_x, scroll_y = self.scroll_offset fixed_top_row_count = sum( @@ -515,6 +523,14 @@ class DataTable(ScrollView, Generic[CellType]): return self._render_line(y, scroll_x, scroll_x + width, style) def render_lines(self, crop: Region) -> Lines: + """Render the widget in to lines. + + Args: + crop (Region): Region within visible area to. + + Returns: + Lines: A list of list of segments + """ lines = self._styles_cache.render_widget(self, crop) return lines diff --git a/tests/test_styles_cache.py b/tests/test_styles_cache.py index 5f3ed09a4..ea892f189 100644 --- a/tests/test_styles_cache.py +++ b/tests/test_styles_cache.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from rich.segment import Segment from textual.color import Color