Responsible for rendering CSS Styles and keeping a cache of rendered lines. The render method applies border, outline, and padding set in the Styles object to widget content. The diagram below shows content (possibly from a Rich renderable) with padding and border. The labels A. B. and
| 35 | |
| 36 | @rich.repr.auto(angular=True) |
| 37 | class StylesCache: |
| 38 | """Responsible for rendering CSS Styles and keeping a cache of rendered lines. |
| 39 | |
| 40 | The render method applies border, outline, and padding set in the Styles object to widget content. |
| 41 | |
| 42 | The diagram below shows content (possibly from a Rich renderable) with padding and border. The |
| 43 | labels A. B. and C. indicate the code path (see comments in render_line below) chosen to render |
| 44 | the indicated lines. |
| 45 | |
| 46 | ``` |
| 47 | ┏━━━━━━━━━━━━━━━━━━━━━━┓◀── A. border |
| 48 | ┃ ┃◀┐ |
| 49 | ┃ ┃ └─ B. border + padding + |
| 50 | ┃ Lorem ipsum dolor ┃◀┐ border |
| 51 | ┃ sit amet, ┃ │ |
| 52 | ┃ consectetur ┃ └─ C. border + padding + |
| 53 | ┃ adipiscing elit, ┃ content + padding + |
| 54 | ┃ sed do eiusmod ┃ border |
| 55 | ┃ tempor incididunt ┃ |
| 56 | ┃ ┃ |
| 57 | ┃ ┃ |
| 58 | ┗━━━━━━━━━━━━━━━━━━━━━━┛ |
| 59 | ``` |
| 60 | """ |
| 61 | |
| 62 | def __init__(self) -> None: |
| 63 | self._cache: dict[int, Strip] = {} |
| 64 | self._dirty_lines: set[int] = set() |
| 65 | self._width = 1 |
| 66 | self._simple_strip: Strip | None = None |
| 67 | """A simple strip consisting of left border + background + right border, which may be reused in a render.""" |
| 68 | |
| 69 | def __rich_repr__(self) -> rich.repr.Result: |
| 70 | if self._dirty_lines: |
| 71 | yield "dirty", self._dirty_lines |
| 72 | yield "width", self._width, 1 |
| 73 | |
| 74 | def set_dirty(self, *regions: Region) -> None: |
| 75 | """Add a dirty regions.""" |
| 76 | if regions: |
| 77 | for region in regions: |
| 78 | self._dirty_lines.update(region.line_range) |
| 79 | else: |
| 80 | self.clear() |
| 81 | |
| 82 | def is_dirty(self, y: int) -> bool: |
| 83 | """Check if a given line is dirty (needs to be rendered again). |
| 84 | |
| 85 | Args: |
| 86 | y: Y coordinate of line. |
| 87 | |
| 88 | Returns: |
| 89 | True if line requires a render, False if can be cached. |
| 90 | """ |
| 91 | return y in self._dirty_lines |
| 92 | |
| 93 | def clear(self) -> None: |
| 94 | """Clear the styles cache (will cause the content to re-render).""" |
no outgoing calls
searching dependent graphs…