|
| 1 | +from textual.app import App |
| 2 | +from textual.containers import Container, Grid |
| 3 | +from textual.widgets import Label |
| 4 | + |
| 5 | + |
| 6 | +def make_label_container( # (11)! |
| 7 | + text: str, id: str, border_title: str, border_subtitle: str |
| 8 | +) -> Container: |
| 9 | + lbl = Label(text, id=id) |
| 10 | + lbl.border_title = border_title |
| 11 | + lbl.border_subtitle = border_subtitle |
| 12 | + return Container(lbl) |
| 13 | + |
| 14 | + |
| 15 | +class BorderSubTitleAlignAll(App[None]): |
| 16 | + def compose(self): |
| 17 | + with Grid(): |
| 18 | + yield make_label_container( # (1)! |
| 19 | + "This is the story of", |
| 20 | + "lbl1", |
| 21 | + "[b]Border [i]title[/i][/]", |
| 22 | + "[u][r]Border[/r] subtitle[/]", |
| 23 | + ) |
| 24 | + yield make_label_container( # (2)! |
| 25 | + "a Python", |
| 26 | + "lbl2", |
| 27 | + "[b red]Left, but it's loooooooooooong", |
| 28 | + "[reverse]Center, but it's loooooooooooong", |
| 29 | + ) |
| 30 | + yield make_label_container( # (3)! |
| 31 | + "developer that", |
| 32 | + "lbl3", |
| 33 | + "[b i on purple]Left[/]", |
| 34 | + "[r u white on black]@@@[/]", |
| 35 | + ) |
| 36 | + yield make_label_container( |
| 37 | + "had to fill up", |
| 38 | + "lbl4", |
| 39 | + "", # (4)! |
| 40 | + "[link=https://textual.textualize.io]Left[/]", # (5)! |
| 41 | + ) |
| 42 | + yield make_label_container( # (6)! |
| 43 | + "nine labels", "lbl5", "Title", "Subtitle" |
| 44 | + ) |
| 45 | + yield make_label_container( # (7)! |
| 46 | + "and ended up redoing it", |
| 47 | + "lbl6", |
| 48 | + "Title", |
| 49 | + "Subtitle", |
| 50 | + ) |
| 51 | + yield make_label_container( # (8)! |
| 52 | + "because the first try", |
| 53 | + "lbl7", |
| 54 | + "Title, but really loooooooooong!", |
| 55 | + "Subtitle, but really loooooooooong!", |
| 56 | + ) |
| 57 | + yield make_label_container( # (9)! |
| 58 | + "had some labels", |
| 59 | + "lbl8", |
| 60 | + "Title, but really loooooooooong!", |
| 61 | + "Subtitle, but really loooooooooong!", |
| 62 | + ) |
| 63 | + yield make_label_container( # (10)! |
| 64 | + "that were too long.", |
| 65 | + "lbl9", |
| 66 | + "Title, but really loooooooooong!", |
| 67 | + "Subtitle, but really loooooooooong!", |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +app = BorderSubTitleAlignAll(css_path="border_sub_title_align_all.css") |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + app.run() |
0 commit comments