mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix align
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from rich.console import RenderableType
|
||||
from rich.style import Style
|
||||
|
||||
|
||||
from ..widget import Widget
|
||||
|
||||
|
||||
Reference in New Issue
Block a user