Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
24.09k stars 742 forks source link

`grid-rows: auto` does not consider height for rows that are spanned #4585

Open awtimmering opened 1 month ago

awtimmering commented 1 month ago

In a situation where a grid-cell is spanned across multiple rows, it is possible for that row to require more height than neighbouring regular cells. grid-rows: auto seems to currently ignore spanned rows, and as result the grid is sized too small.

MRE:

from textual.app import App, ComposeResult
from textual.containers import Grid, Container
from textual.widgets import Placeholder, Static

class MyGrid(Grid):

    DEFAULT_CSS = """
        MyGrid {
            border: solid cornflowerblue;
            grid-size: 2 4;
            grid-rows: auto;
            height: auto;

            #grid-header {
                column-span: 2;
                background: darkred;
                Static {
                    text-align: center;
                    text-style: bold;
                }
            }
            #block-1 {
                row-span: 2;
                background: cornflowerblue;
            }
            #block-2 {
                background: lightsalmon;
            }

            Container {
              height: auto;
            }

        }
    """

    def compose(self) -> ComposeResult:
        with Container(id="grid-header"):
            yield Static("Header (column-span: 2)")

        with Container(id="block-1", classes="block"):
            yield Static("Block 1 (row-span 2, 16 lines height, but not showing)")
            for i in range(15):
                yield Static(f" - line {i+1:02} / 15")

        with Container(id="block-2", classes="block"):
            yield Static("Block 2 (single cell, total of 4 lines height)")
            for i in range(3):
                yield Static(f" - line {i+1} / 3")

        with Container(id="block-3", classes="block"):
            yield Static("Block 3 (single cell, total of 4 lines height)")
            for i in range(3):
                yield Static(f" - line {i+1} / 3")

class GridSizeApp(App[None]):

    CSS = """
        Placeholder {
            height: 5;
        }
    """

    def compose(self) -> ComposeResult:
        with Container():
            yield Placeholder()
            yield MyGrid()
            yield Placeholder()

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

image

github-actions[bot] commented 1 month ago

We found the following entries 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