Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Code to illustrate Textualize/textual#4073
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Jan 29, 2024
1 parent 9cb93b0 commit 40cb293
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions the_welsh_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""Trying to recreate a rendering bug.
See https://github.com/Textualize/textual/issues/4073
"""

from rich.table import Table
from rich.console import Group

from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.screen import ModalScreen
from textual.widgets import OptionList

NAMES = [
"Cardiff",
"Swansea",
"Aberdare",
"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch",
"Mountain Ash",
"Hirwaun"
]

class Names(ModalScreen[None]):

CSS = """
Names {
align: center middle;
Vertical {
width: auto;
max-width: 60%;
height: auto;
max-height: 80%;
padding: 1 2 0 2;
background: $surface;
border: panel $primary;
border-title-color: $accent;
OptionList {
height: 1fr;
margin: 1 0 1 0;
&> .option-list--option {
padding: 0 5 1 0;
}
}
}
}
"""

def gridify(self, n: int, name: str) -> Group:
question = Table.grid()
question.add_column(width=3, justify="right")
question.add_column(width=1)
question.add_column(ratio=1)
question.add_row(str(n), "", f"{name} is the name of a place in Wales." )
answer = Table.grid()
answer.add_column(width=4)
answer.add_column(ratio=1)
answer.add_row("", "[red]Here is the[/] [green]second line[/]")
return Group(question, answer)

def compose(self) -> ComposeResult:
with Vertical():
yield OptionList(*[self.gridify(n, name) for n, name in enumerate(NAMES)])

class TruncatedTextOptionApp(App[None]):

CSS = """
Screen#_default {
background: red;
}
"""

def on_mount(self) -> None:
self.push_screen(Names())

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

### the_welsh_problem.py ends here

0 comments on commit 40cb293

Please sign in to comment.