From 70aee154d6ee5e770c014b670287d24d26ef342a Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:11:44 +0000 Subject: [PATCH 1/5] fix(scrollbar): fix scroll background opacity --- src/textual/scrollbar.py | 2 ++ tests/snapshot_tests/test_snapshots.py | 27 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index a9e1bddcb4..df9093e39b 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -286,6 +286,8 @@ def render(self) -> RenderableType: else: background = styles.scrollbar_background color = styles.scrollbar_color + base_background, _ = self.parent._opacity_background_colors + background = base_background + background color = background + color scrollbar_style = Style.from_color(color.rich_color, background.rich_color) if self.screen.styles.scrollbar_color.a == 0: diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index b5982ef127..abaf0d35db 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -3251,3 +3251,30 @@ async def run_before(pilot: Pilot) -> None: terminal_size=(175, 50), run_before=run_before, ) + + +def test_scrollbar_background_with_opacity(snap_compare): + """Regression test for https://github.com/Textualize/textual/issues/5458 + The scrollbar background should match the background of the widget.""" + + class ScrollbarOpacityApp(App): + CSS = """ + Screen { + align: center middle; + } + + VerticalScroll { + width: 50%; + height: 50%; + background: blue 10%; + scrollbar-background: blue 10%; + scrollbar-color: cyan; + scrollbar-size-vertical: 10; + } + """ + + def compose(self) -> ComposeResult: + with VerticalScroll(): + yield Static("\n".join(f"This is some text {n}" for n in range(100))) + + assert snap_compare(ScrollbarOpacityApp()) From 1a7082f840784c6ce294b9614c13005733ce9a5d Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:26:48 +0000 Subject: [PATCH 2/5] tests: update snapshots with scrollbar test --- ...test_scrollbar_background_with_opacity.svg | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_scrollbar_background_with_opacity.svg diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_scrollbar_background_with_opacity.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_scrollbar_background_with_opacity.svg new file mode 100644 index 0000000000..af3a2d58f3 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_scrollbar_background_with_opacity.svg @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ScrollbarOpacityApp + + + + + + + + + + + + + + + +This is some text 0 +This is some text 1▄▄▄▄▄▄▄▄▄▄ +This is some text 2 +This is some text 3 +This is some text 4 +This is some text 5 +This is some text 6 +This is some text 7 +This is some text 8 +This is some text 9 +This is some text 10 +This is some text 11 + + + + + + + + + From 152b6c22efcb1f5f67c7d8b79f2dd71ade1dc868 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:33:54 +0000 Subject: [PATCH 3/5] docs: update changelog with scrollbar fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c58476aaf8..dca4cd7425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed `Pilot.click` not working with `times` parameter https://github.com/Textualize/textual/pull/5398 - Fixed select refocusing itself too late https://github.com/Textualize/textual/pull/5420 - Fixed Log widget not refreshing on resize https://github.com/Textualize/textual/pull/5460 +- Fixed scrollbars ignoring background opacity https://github.com/Textualize/textual/issues/5458 ## [1.0.0] - 2024-12-12 From a35d48a59a8268f76762ddb9748f3185c0a9d6f3 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:56:57 +0000 Subject: [PATCH 4/5] perf: optimize scrollbar background for alpha --- src/textual/scrollbar.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index df9093e39b..52fc98ba16 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -286,8 +286,9 @@ def render(self) -> RenderableType: else: background = styles.scrollbar_background color = styles.scrollbar_color - base_background, _ = self.parent._opacity_background_colors - background = base_background + background + if background.a > 0: + base_background, _ = self.parent._opacity_background_colors + background = base_background + background color = background + color scrollbar_style = Style.from_color(color.rich_color, background.rich_color) if self.screen.styles.scrollbar_color.a == 0: From 8bb22917c0aa3e1102caa7c7794e8122ab24bd59 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Thu, 9 Jan 2025 09:09:27 +0000 Subject: [PATCH 5/5] fix(scrollbar): fix background alpha optimization --- src/textual/scrollbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index 52fc98ba16..6602d9cba3 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -286,7 +286,7 @@ def render(self) -> RenderableType: else: background = styles.scrollbar_background color = styles.scrollbar_color - if background.a > 0: + if background.a < 1: base_background, _ = self.parent._opacity_background_colors background = base_background + background color = background + color