Improve text-align example.

Replace statics with labels; change to a 2 x 2 grid layout to make it easier to see the difference between 'center' and 'justify'; increase readability by setting 'color: auto' in the labels.
This commit is contained in:
Rodrigo Girão Serrão
2023-01-06 10:40:31 +00:00
parent 7743feadff
commit 042bc3b3fe
3 changed files with 27 additions and 28 deletions

View File

@@ -1,24 +1,29 @@
#one {
text-align: left;
background: lightblue;
text-align: left;
background: lightblue;
}
#two {
text-align: center;
background: indianred;
text-align: center;
background: indianred;
}
#three {
text-align: right;
background: palegreen;
text-align: right;
background: palegreen;
}
#four {
text-align: justify;
background: palevioletred;
text-align: justify;
background: palevioletred;
}
Static {
padding: 1;
Label {
padding: 1 2;
height: 100%;
color: auto;
}
Grid {
grid-size: 2 2;
}

View File

@@ -1,7 +1,6 @@
from __future__ import annotations
from textual.app import App, ComposeResult
from textual.widgets import Static
from textual.app import App
from textual.containers import Grid
from textual.widgets import Label
TEXT = (
"I must not fear. Fear is the mind-killer. Fear is the little-death that "
@@ -11,18 +10,13 @@ TEXT = (
class TextAlign(App):
def compose(self) -> ComposeResult:
left = Static("[b]Left aligned[/]\n" + TEXT, id="one")
yield left
right = Static("[b]Center aligned[/]\n" + TEXT, id="two")
yield right
center = Static("[b]Right aligned[/]\n" + TEXT, id="three")
yield center
full = Static("[b]Justified[/]\n" + TEXT, id="four")
yield full
def compose(self):
yield Grid(
Label("[b]Left aligned[/]\n" + TEXT, id="one"),
Label("[b]Center aligned[/]\n" + TEXT, id="two"),
Label("[b]Right aligned[/]\n" + TEXT, id="three"),
Label("[b]Justified[/]\n" + TEXT, id="four"),
)
app = TextAlign(css_path="text_align.css")

View File

@@ -35,7 +35,7 @@ This example shows, from top to bottom: `left`, `center`, `right`, and `justify`
=== "text_align.css"
```css
```css hl_lines="2 7 12 17"
--8<-- "docs/examples/styles/text_align.css"
```