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

New Footer missing space between key and description #4557

Closed
TomJGooding opened this issue May 25, 2024 · 5 comments · Fixed by #4651
Closed

New Footer missing space between key and description #4557

TomJGooding opened this issue May 25, 2024 · 5 comments · Fixed by #4651

Comments

@TomJGooding
Copy link
Contributor

TomJGooding commented May 25, 2024

Originally discussed in #4555, it looks like the new Footer doesn't have any space between the key and the description, which doesn't as nice if you've added a background style for the key.

I appreciate however that the default styling (without any background for the key) would perhaps then look like it has too much spacing.

What do you think?

from textual.app import App, ComposeResult
from textual.widgets import ClassicFooter, Footer, Label


class FooterApp(App):
    BINDINGS = [("space", "switch_footer", "Switch Footer")]

    CSS = """
    Screen {
        align: center middle;
    }

    Footer {
        background: $accent;
    }

    Footer > FooterKey {
        background: $accent;
        color: $text;
        .footer-key--key {
            background: $accent-darken-2;
            color: $text;
        }
    }
    """

    footer_type = "classic"

    def compose(self) -> ComposeResult:
        yield Label(
            f"{self.footer_type.title()} Footer",
            id="footer-type-label",
        )
        yield ClassicFooter()

    def action_switch_footer(self) -> None:
        if self.footer_type == "classic":
            self.query_one(ClassicFooter).remove()
            self.mount(Footer())
            self.footer_type = "new"
        else:
            self.query_one(Footer).remove()
            self.mount(ClassicFooter())
            self.footer_type = "classic"

        self.query_one(Label).update(
            f"{self.footer_type.title()} Footer",
        )


if __name__ == "__main__":
    app = FooterApp()
    app.run()
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@jessebot
Copy link

In case anyone is following up on this. I think the current suggested solution is this, #4601 (comment):

The component style could have padding, which you could look up like this:

self.get_component_style("footer-key--key").padding

The user could then add the space with something like this:

Footer>footer-key--key {
    padding-right: 1;
}

But it still needs a PR.

@TomJGooding
Copy link
Contributor Author

TomJGooding commented Jun 14, 2024

My understanding of component classes is that they are intended for Rich Style objects to allow styling of non-Widget` renderables in Textual. Using the component class to add padding just feels wrong to me, and might set the wrong precedent for other component classes in Textual.

Perhaps my understanding is wrong and I confess I don't have any better suggestions. If it helps I'm happy to look at a PR that adds the Padding instances or similar, but wanted to check I had fully understood the suggested solution first.

@willmcgugan
Copy link
Collaborator

Generally it is, but you can extract any CSS attribute from a component style, and use that in any way you like. Pretty sure there is precedence in the builtin widgets.

A downside is that you have to handle these things manually. i.e. if the widget doesn't explicitly handle padding in a component class then it won't appear. That can be solved by documenting the styles that work.

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
None yet
Projects
None yet
3 participants