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

grid-rows: auto seems to be broken when column-span/Pretty is used #4179

Closed
mzebrak opened this issue Feb 19, 2024 · 5 comments · Fixed by #4211
Closed

grid-rows: auto seems to be broken when column-span/Pretty is used #4179

mzebrak opened this issue Feb 19, 2024 · 5 comments · Fixed by #4211

Comments

@mzebrak
Copy link

mzebrak commented Feb 19, 2024

Looks like there is a rendering issue when column-span (or Pretty widget) is used together with grid-rows: auto.

Consider such a example:

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Grid
from textual.widgets import Footer, Pretty, Static


class MyGrid(Grid):
    """A simple grid with 2 columns and 2 rows."""


class MyApp(App):
    BINDINGS = [
        Binding("a", "add", "Add a new item"),
    ]

    DEFAULT_CSS = """
    MyGrid {
        height: auto;
        grid-rows: auto;
        grid-size: 2;
        grid-gutter: 1;
        background: green;
    }

    Pretty {
        background: red;
    }

    Static {
        background: blue;
    }
"""

    def compose(self) -> ComposeResult:
        with MyGrid():
            yield Pretty(["Something that should have colspan=2"])
            yield Static("")
            yield Static("I want this")
            yield Static("... in a single row")
        yield Footer()

    def action_add(self):
        pretty = self.query_one(Pretty)
        before = pretty._renderable._object
        pretty.update([*before, before[0]])


MyApp().run()

Results (correctly) in:

image
image

But not quite correct when we change the terminal size a bit (adds a lot of free green space):

image

When using column-span:

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import Grid
from textual.widgets import Footer, Pretty, Static


class MyGrid(Grid):
    """A simple grid with 2 columns and 2 rows."""


class MyApp(App):
    BINDINGS = [
        Binding("a", "add", "Add a new item"),
    ]

    DEFAULT_CSS = """
    MyGrid {
        height: auto;
        grid-rows: auto;
        grid-size: 2;
        grid-gutter: 1;
        background: green;
    }

    Pretty {
        column-span: 2;
        background: red;
    }

    Static {
        background: blue;
    }
"""

    def compose(self) -> ComposeResult:
        with MyGrid():
            yield Pretty(["Something that should have colspan=2"])
            yield Static("I want this")
            yield Static("... in a single row")
        yield Footer()

    def action_add(self):
        pretty = self.query_one(Pretty)
        before = pretty._renderable._object
        pretty.update([*before, before[0]])


MyApp().run()

Results (correctly) in:

image

But incorrectly when we add something (adds extra green space):
image
image

Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

@rodrigogiraoserrao Would you like to tackle this one? The issue seems to be in grid.py, and it is related to gutter.

@willmcgugan
Copy link
Collaborator

Actually, @rodrigogiraoserrao This may be the fix #4219

Would you mind confirming, and adding a snapshot test? The code on this issue is probably good enough, if you find a terminal size where it breaks.

@rodrigogiraoserrao
Copy link
Contributor

Would you mind confirming, and adding a snapshot test? The code on this issue is probably good enough, if you find a terminal size where it breaks.

Done

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
Development

Successfully merging a pull request may close this issue.

3 participants