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

Button label not centered when buttons are in nested horizontals #4961

Closed
matkudela opened this issue Sep 2, 2024 · 3 comments
Closed

Button label not centered when buttons are in nested horizontals #4961

matkudela opened this issue Sep 2, 2024 · 3 comments

Comments

@matkudela
Copy link

matkudela commented Sep 2, 2024

My example:

from __future__ import annotations

from textual.app import App, ComposeResult
from textual.widgets import Button, Static
from textual.containers import Horizontal


class MyApp(App):

    DEFAULT_CSS = """
    #main {
        width: auto;
        Button {
          width: 33%;
        }
    }
    #second {
      width: 3fr;
    }
    #third {
      width: 3fr;
    }
    #middle-one {
      margin: 0 1;
    }
    """
    def compose(self) -> ComposeResult:
        with Horizontal(id="main"):
            yield Horizontal(Static("One"), id="first")
            yield Horizontal(Static("Three"), id="second")
            with Horizontal(id="third"):
                yield Button("This", variant="success")
                yield Button("is", variant="primary", id="middle-one")
                yield Button("example1", variant="error")

MyApp().run()

Output (on 132x43 terminal, textual 0.76.0):
image

As you can see label of third button is not centered. This happens only in nested horizontals and number of characters of label has to be even.

Without nesting everything works fine:
image


from __future__ import annotations

from textual.app import App, ComposeResult
from textual.widgets import Button
from textual.containers import Horizontal


class MyApp(App):

    DEFAULT_CSS = """
    #third {
      width: 100%;
      Button {
          width: 33%;
      }
      
    }
    #middle-one {
      margin: 0 1;
    }
    """
    def compose(self) -> ComposeResult:
            with Horizontal(id="third"):
                yield Button("This", variant="success")
                yield Button("is", variant="primary", id="middle-one")
                yield Button("example1", variant="error")

MyApp().run()
Copy link

github-actions bot commented Sep 2, 2024

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

@willmcgugan
Copy link
Collaborator

It is centered as much as is possible in the terminal. Terminals are a grid of characters, and you can only position text on integer coordinates. You can't have the half a space to position it visually perfectly.

@darrenburns darrenburns closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2024
Copy link

github-actions bot commented Sep 3, 2024

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

No branches or pull requests

3 participants