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

Consider a :loading pseudo class #3517

Closed
davep opened this issue Oct 12, 2023 · 2 comments
Closed

Consider a :loading pseudo class #3517

davep opened this issue Oct 12, 2023 · 2 comments
Labels
enhancement New feature or request Task

Comments

@davep
Copy link
Contributor

davep commented Oct 12, 2023

It's not uncommon to have an array of widgets where, say, the border is used to help emphasise where focus is, for example:

from textual.app import App, ComposeResult
from textual.containers import Grid, Container

class BusyBox(Container, can_focus=True):

    DEFAULT_CSS = """
    BusyBox {
        border: panel red;
    }
    BusyBox:focus {
        border: panel green;
    }
    """

    def __init__(self, number: int) -> None:
        super().__init__()
        self.border_title = f"Busy box {number}"
        self.loading = bool(number % 3)

class LoadingApp(App[None]):

    CSS = """
    Grid {
        grid-size: 4;
    }
    """

    def compose(self) -> ComposeResult:
        with Grid():
            for n in range(16):
                yield BusyBox(n)

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

I feel it would be very useful if it were possible to also style a widget that is in the loading state. While it's true that a class could be applied when the loading value is set to True, and removed when set to False, allowing it to be done fully in CSS would mean there's no need to manage multiple locations where such changes could be made on a widget. Likewise, while this could be managed by the developer with a watch on loading, that then would generally require subclassing of all widgets that need this functionality; a pure-CSS solution would mean that a couple of rules could handle all sorts of widgets.

@davep davep added enhancement New feature or request Task labels Oct 12, 2023
davep added a commit to davep/textual-sandbox that referenced this issue Oct 12, 2023
@willmcgugan
Copy link
Collaborator

I'm going to say no for now. Just because I don't want to keep adding to the very growing list of pseudo classes.

Happy to reconsider if we are asked for it.

Copy link

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
enhancement New feature or request Task
Projects
None yet
Development

No branches or pull requests

2 participants