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

Align doesn't work with height and min-height combination in widget #5608

Open
matkudela opened this issue Mar 4, 2025 · 2 comments · May be fixed by #5612
Open

Align doesn't work with height and min-height combination in widget #5608

matkudela opened this issue Mar 4, 2025 · 2 comments · May be fixed by #5612

Comments

@matkudela
Copy link

matkudela commented Mar 4, 2025

This example shows that align property is not working well. Static widget should be positioned vertically in the middle of CustomWidget. It was broken between 0.83.0 version and 2.1.2.

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.widget import Widget
from textual.widgets import Footer, Static


class CustomWidget(Widget):
    DEFAULT_CSS = """
    CustomWidget {
      width: 1fr;
      background: grey;
      height: auto;
      min-height: 3;
      align: center middle; /* align doesn't work with height and min-height combination */
      
      Static {
        background: red;
      }
    }
    """

class MyApp(App):
    def compose(self) -> ComposeResult:
        with CustomWidget():
            yield Static("Some text")
        yield Footer()


MyApp().run()

With deleted min-height and static height: 3 static widget is positioned properly:

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.widget import Widget
from textual.widgets import Footer, Static


class CustomWidget(Widget):
    DEFAULT_CSS = """
    CustomWidget {
      width: 1fr;
      background: grey;
      height: 3;
      align: center middle; /* now align works properly */
      
      Static {
        background: red;
      }
    }
    """

class MyApp(App):
    def compose(self) -> ComposeResult:
        with CustomWidget():
            yield Static("Some text")
        yield Footer()


MyApp().run()
Copy link

github-actions bot commented Mar 4, 2025

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

TomJGooding added a commit to TomJGooding/textual that referenced this issue Mar 4, 2025
Fix issue with alignment in containers with auto _and_ min height/width.
Currently the size of the parent passed to `_align_size` doesn't account
for any min height/width when the container has auto dimensions.

Fixes Textualize#5608
@TomJGooding TomJGooding linked a pull request Mar 4, 2025 that will close this issue
3 tasks
@TomJGooding
Copy link
Contributor

This issue with auto containers with auto children is proving tricky! The container size seems correct in the latest version at least, hopefully just the alignment need ironing out...

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