mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
styled strips
This commit is contained in:
@@ -254,7 +254,7 @@ class RichVisual(Visual):
|
||||
def __init__(self, widget: Widget, renderable: RenderableType) -> None:
|
||||
self._widget = widget
|
||||
self._renderable = renderable
|
||||
self._post_renderable: RenderableType | None = None
|
||||
|
||||
self._measurement: Measurement | None = None
|
||||
|
||||
def __rich_repr__(self) -> rich.repr.Result:
|
||||
@@ -309,20 +309,24 @@ class RichVisual(Visual):
|
||||
width=width,
|
||||
height=height,
|
||||
)
|
||||
if self._post_renderable is None:
|
||||
self._post_renderable = widget.post_render(self._renderable)
|
||||
renderable = self._post_renderable
|
||||
|
||||
renderable = widget.post_render(self._renderable)
|
||||
|
||||
segments = console.render(renderable, options)
|
||||
rich_style = style.rich_style
|
||||
if rich_style:
|
||||
segments = Segment.apply_style(segments, post_style=rich_style)
|
||||
# if rich_style:
|
||||
# segments = Segment.apply_style(segments, post_style=rich_style)
|
||||
|
||||
# lines = console.render_lines(renderable, options, style=rich_style)
|
||||
|
||||
strips = [
|
||||
Strip(line)
|
||||
Strip(line).apply_style(rich_style)
|
||||
for line in islice(
|
||||
Segment.split_and_crop_lines(
|
||||
segments, width, include_new_lines=False, pad=False
|
||||
segments,
|
||||
width,
|
||||
include_new_lines=False,
|
||||
pad=False,
|
||||
),
|
||||
None,
|
||||
height,
|
||||
|
||||
@@ -473,9 +473,9 @@ class OptionList(ScrollView, can_focus=True):
|
||||
A list of strips.
|
||||
"""
|
||||
|
||||
# cache_key = (option_index, style, width)
|
||||
# if (strips := self._content_render_cache.get(cache_key, None)) is not None:
|
||||
# return strips
|
||||
cache_key = (option_index, component_class, width)
|
||||
if (strips := self._content_render_cache.get(cache_key, None)) is not None:
|
||||
return strips
|
||||
|
||||
visual = visualize(self, content)
|
||||
padding = self.get_component_styles("option-list--option").padding
|
||||
@@ -501,11 +501,13 @@ class OptionList(ScrollView, can_focus=True):
|
||||
# lines = self.app.console.render_lines(renderable, options, style=style)
|
||||
|
||||
style_meta = Style.from_meta({"option": option_index})
|
||||
strips = [strip.apply_style(style_meta) for strip in strips]
|
||||
strips = [
|
||||
strip.adjust_cell_length(width).apply_style(style_meta) for strip in strips
|
||||
]
|
||||
|
||||
# strips = [Strip(line, width).apply_style(style_meta) for line in lines]
|
||||
|
||||
# self._content_render_cache[cache_key] = strips
|
||||
self._content_render_cache[cache_key] = strips
|
||||
return strips
|
||||
|
||||
def _duplicate_id_check(self, candidate_items: list[OptionListContent]) -> None:
|
||||
|
||||
Reference in New Issue
Block a user