Skip to content

Commit 8ca10ba

Browse files
committed
new example
1 parent 9131496 commit 8ca10ba

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

examples/breakpoints.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from textual.app import App, ComposeResult
2+
from textual.containers import Grid
3+
from textual.widgets import Footer, Markdown, Placeholder
4+
5+
HELP = """\
6+
## Breakpoints
7+
8+
A demonstration of how to make an app respond to the dimensions of the terminal.
9+
10+
Try resizing the terminal, then have a look at the source to see how it works!
11+
12+
`ctrl+q` to quit.
13+
14+
"""
15+
16+
17+
class BreakpointApp(App):
18+
19+
HORIZONTAL_BREAKPOINTS = [
20+
(0, "-narrow"),
21+
(40, "-normal"),
22+
(80, "-wide"),
23+
(120, "-very-wide"),
24+
]
25+
26+
CSS = """
27+
Screen {
28+
overflow-y: auto;
29+
Placeholder { padding: 2; }
30+
Grid { grid-rows: auto; height: auto; }
31+
&.-narrow {
32+
Grid { grid-size: 1; }
33+
}
34+
&.-normal {
35+
Grid { grid-size: 2; }
36+
}
37+
&.-wide {
38+
Grid { grid-size: 4; }
39+
}
40+
&.-very-wide {
41+
Grid { grid-size: 6; }
42+
}
43+
}
44+
"""
45+
46+
def compose(self) -> ComposeResult:
47+
yield Markdown(HELP)
48+
with Grid():
49+
for n in range(16):
50+
yield Placeholder(f"Placeholder {n+1}")
51+
yield Footer()
52+
53+
54+
if __name__ == "__main__":
55+
BreakpointApp().run()

0 commit comments

Comments
 (0)