Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrollbars appear to ignore the background colour percentage #5458

Closed
davep opened this issue Jan 6, 2025 · 5 comments · Fixed by #5462
Closed

Scrollbars appear to ignore the background colour percentage #5458

davep opened this issue Jan 6, 2025 · 5 comments · Fixed by #5462

Comments

@davep
Copy link
Contributor

davep commented Jan 6, 2025

Each of the scrollbar styles say that they take a percentage that is the opacity to use. However, it appears that this value gets ignored. With this code:

from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Static

class ScrollBarPercentageApp(App[None]):

    CSS = """
    Screen {
        layout: horizontal;
    }

    VerticalScroll {
        scrollbar-size-vertical: 10;

        &#no-pcent {
            background: $surface;
            scrollbar-background: $surface;
            scrollbar-background-active: $surface;
            scrollbar-background-hover: $surface;
        }

        &#pcent {
            background: $surface 10%;
            scrollbar-background: $surface 10%;
            scrollbar-background-active: $surface 10%;
            scrollbar-background-hover: $surface 10%;
        }
    }
    """

    def compose(self) -> ComposeResult:
        with VerticalScroll(id="no-pcent"):
            yield Static(
                "\n".join(
                    f"This is some text {n}" for n in range(100)
                )
            )
        with VerticalScroll(id="pcent"):
            yield Static(
                "\n".join(
                    f"This is some text {n}" for n in range(100)
                )
            )

if __name__ == "__main__":
    ScrollBarPercentageApp().run()

the result is this:

Screenshot 2025-01-06 at 11 30 51

Note that on the left the scrollbar background and the container are set to $surface and they match; on the right they're set to $surface 10% and they don't match, which the scrollbar background appearing to still be just $surface.

@TomJGooding
Copy link
Contributor

I think I've found the cause, but I wanted to double-check before submitting a PR: when the scrollbar background has opacity, should it blend with the 'base' background or the background of its widget?

In other words, should the scrollbar background actually match the widget background in the above example?

@davep
Copy link
Contributor Author

davep commented Jan 8, 2025

From a "user of the library" perspective I think I'd expect this:

background: $surface 10%;
scrollbar-background: $surface 10%;

to result in the widget background and the widget's scrollbar's background to come out the same colour; it feels like that follows the rule of least astonishment. Or did I perhaps misunderstand?

@TomJGooding
Copy link
Contributor

TomJGooding commented Jan 8, 2025

Here's a silly example which hopefully clarifies what I mean. Should the scrollbar background be some shade of purple where it is blended with the red screen background? You might consider the scrollbar part of the widget itself, so the background should be blended with the green widget background.

from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Static


class ScrollBarPercentageApp(App[None]):

    CSS = """
    Screen {
        align: center middle;
        background: #ff0000;
    }

    VerticalScroll {
        width: 50%;
        height: 50%;
        background: #00ff00;

        scrollbar-size-vertical: 10;
        scrollbar-color: #0000ff;
        scrollbar-background: #0000ff 50%;
    }
    """

    def compose(self) -> ComposeResult:
        with VerticalScroll():
            yield Static("\n".join(f"This is some text {n}" for n in range(100)))


if __name__ == "__main__":
    ScrollBarPercentageApp().run()

@davep
Copy link
Contributor Author

davep commented Jan 8, 2025

I think I'd expect it to be blend with whatever the widget's background would blend with if it was somewhat transparent; so in this case with the screen. I think that would be my expectation.

Copy link

github-actions bot commented Jan 9, 2025

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants