From effd6211d3c0e16aff72bfff6b77e0fce0cf6b40 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 28 Sep 2022 10:04:22 +0100 Subject: [PATCH] optimize link highlight --- docs/styles/content_align.md | 6 +++--- src/textual/app.py | 2 +- src/textual/widget.py | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/styles/content_align.md b/docs/styles/content_align.md index 72ec6d132..35a4a4c57 100644 --- a/docs/styles/content_align.md +++ b/docs/styles/content_align.md @@ -1,6 +1,6 @@ # Content-align -The `content-align` property allows you to align content _inside_ a widget. +The `content-align` style aligns content _inside_ a widget. You can specify the alignment of content on both the horizontal and vertical axes. @@ -15,7 +15,7 @@ content-align: ; #### `HORIZONTAL` | Value | Description | -|------------------|----------------------------------------------------| +| ---------------- | -------------------------------------------------- | | `left` (default) | Align content on the left of the horizontal axis | | `center` | Align content in the center of the horizontal axis | | `right` | Align content on the right of the horizontal axis | @@ -23,7 +23,7 @@ content-align: ; #### `VERTICAL` | Value | Description | -|-----------------|--------------------------------------------------| +| --------------- | ------------------------------------------------ | | `top` (default) | Align content at the top of the vertical axis | | `middle` | Align content in the middle of the vertical axis | | `bottom` | Align content at the bottom of the vertical axis | diff --git a/src/textual/app.py b/src/textual/app.py index 48abc106d..fbc69b880 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -977,7 +977,7 @@ class App(Generic[ReturnType], DOMNode): finally: self.mouse_over = None else: - if self.mouse_over != widget: + if self.mouse_over is not widget: try: if self.mouse_over is not None: await self.mouse_over._forward_event(events.Leave(self)) diff --git a/src/textual/widget.py b/src/textual/widget.py index 948a22635..7fb137dc8 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -147,7 +147,8 @@ class Widget(DOMNode): auto_links = Reactive(True) """Widget will highlight links automatically.""" - hover_style: Reactive[Style] = Reactive(Style) + hover_style: Reactive[Style] = Reactive(Style, repaint=False) + highlight_link_id: Reactive[str] = Reactive("") def __init__( self, @@ -446,6 +447,12 @@ class Widget(DOMNode): return height + def watch_hover_style( + self, previous_hover_style: Style, hover_style: Style + ) -> None: + if self.auto_links: + self.highlight_link_id = hover_style.link_id + def watch_scroll_x(self, new_value: float) -> None: self.horizontal_scrollbar.position = int(new_value) self.refresh(layout=True)