diff --git a/src/textual/dom.py b/src/textual/dom.py index 118f1bdef..a5d2ac4f5 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -448,10 +448,7 @@ class DOMNode(MessagePump): def detach(self) -> None: if self._parent and isinstance(self._parent, DOMNode): self._parent.children._remove(self) - print(self.parent.children) self._detach() - print("DETATCH", self) - print(self.app._registry) def get_pseudo_classes(self) -> Iterable[str]: """Get any pseudo classes applicable to this Node, e.g. hover, focus. diff --git a/src/textual/renderables/align.py b/src/textual/renderables/align.py index cb582c137..0e2f86d91 100644 --- a/src/textual/renderables/align.py +++ b/src/textual/renderables/align.py @@ -5,9 +5,9 @@ from rich.measure import Measurement from rich.segment import Segment from rich.style import Style -from ..geometry import Size -from ..css.types import AlignHorizontal, AlignVertical from .._segment_tools import align_lines +from ..css.types import AlignHorizontal, AlignVertical +from ..geometry import Size class Align: diff --git a/src/textual/widget.py b/src/textual/widget.py index e003a6b74..dbac8fe2b 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -1,5 +1,6 @@ from __future__ import annotations +from itertools import islice from fractions import Fraction from operator import attrgetter from typing import ( @@ -989,18 +990,6 @@ class Widget(DOMNode): else: renderable = Styled(renderable, rich_style) - styles = self.styles - horizontal, vertical = styles.content_align - # TODO: This changes the shape of the renderable and breaks alignment - # We need custom functionality that doesn't measure the renderable again - renderable = Align( - renderable, - self.size, - rich_style, - horizontal, - vertical, - ) - return renderable def watch_mouse_over(self, value: bool) -> None: @@ -1043,7 +1032,30 @@ class Widget(DOMNode): options = self.console.options.update_dimensions(width, height).update( highlight=False ) - lines = self.console.render_lines(renderable, options) + + segments = self.console.render(renderable, options) + lines = list( + islice( + Segment.split_and_crop_lines( + segments, width, include_new_lines=False, pad=False + ), + None, + height, + ) + ) + + styles = self.styles + align_horizontal, align_vertical = styles.content_align + lines = list( + align_lines( + lines, + Style(), + self.size, + align_horizontal, + align_vertical, + ) + ) + self._render_cache = RenderCache(self.size, lines) self._dirty_regions.clear() diff --git a/src/textual/widgets/_static.py b/src/textual/widgets/_static.py index 7d617e81f..eb3359dbb 100644 --- a/src/textual/widgets/_static.py +++ b/src/textual/widgets/_static.py @@ -1,7 +1,7 @@ from __future__ import annotations from rich.console import RenderableType -from rich.style import Style + from ..widget import Widget