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

Margin and fr don't mix well #2220

Closed
rodrigogiraoserrao opened this issue Apr 5, 2023 · 5 comments · Fixed by #2221
Closed

Margin and fr don't mix well #2220

rodrigogiraoserrao opened this issue Apr 5, 2023 · 5 comments · Fixed by #2221
Labels
bug Something isn't working Task

Comments

@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented Apr 5, 2023

Edit: original MRE was wrong.
See the real issue below

@rodrigogiraoserrao rodrigogiraoserrao added bug Something isn't working Task labels Apr 5, 2023
@willmcgugan
Copy link
Collaborator

This seems to work as I would expect. A blank line, followed by the lines with text.

What do you get?

@rodrigogiraoserrao rodrigogiraoserrao changed the title Margin pushes content Margin and fr don't mix well Apr 5, 2023
@rodrigogiraoserrao
Copy link
Contributor Author

Don't mind me, I got the MRE mixed up.

Real issue: setting margins in widgets inside a container doesn't mix well with also using fr in those widgets.

The labels in the MRE below have 3 lines each. Each sets a margin to 1.
We set the outer container to height: 8.
Instead of splitting the 8 lines 4-4, the fr gives 4 lines to each label and then we need two extra lines for the margins.

What we get:

gh

Expected output:

gh

  • margin.css:
Container {
    height: 8;
    background: pink;
}

#top {
    background: red;
    margin-top: 1;
    height: 1fr;
}

#bot {
    background: blue;
    margin-bottom: 1;
    height: 1fr;
}
  • margin.py:
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import Label


class MyApp(App[None]):
    CSS_PATH = "margin.css"

    def compose(self) -> ComposeResult:
        with Container():
            yield Label("one\ntwo\nthree", id="top")
            yield Label("four\nfive\nsix", id="bot")

@rodrigogiraoserrao
Copy link
Contributor Author

I have had all sorts of weird interactions with margin in the past. May be related with the above.

@willmcgugan
Copy link
Collaborator

Awesome, looks like my branch fixes that.

Screenshot 2023-04-05 at 18 38 33

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

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
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants