You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/work-with-containers.md
+94-10Lines changed: 94 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,11 @@
1
-
# Work with containers
1
+
# Save time with Textual containers
2
+
3
+
Textual's [containers][textual.containers] provide a convenient way of arranging your widgets. Let's look at them in a little detail.
4
+
5
+
!!! info "Are you in the right place?"
6
+
7
+
We are talking about Textual container widgets here. Not to be confused with [containerization](https://en.wikipedia.org/wiki/Containerization_(computing))—which is something else entirely!
2
8
3
-
Textual's [containers][textual.containers] provide a convenient way of arranging your widgets. Let's look at them in a little detail!
4
9
5
10
## What are containers?
6
11
@@ -30,7 +35,7 @@ Before I describe some of the other containers, I would like to show how contain
30
35
The following is the actual source of the `Horizontal` widget:
31
36
32
37
```python
33
-
classHorizontal(Widget, inherit_bindings=False):
38
+
classHorizontal(Widget):
34
39
"""An expanding container with horizontal layout and no scrollbars."""
35
40
36
41
DEFAULT_CSS="""
@@ -47,8 +52,6 @@ That's it!
47
52
A simple widget with a few preset styles.
48
53
The other containers are just as simple.
49
54
50
-
You can customize the container with TCSS in the same way as other widgets.
51
-
52
55
## Horizontal and Vertical
53
56
54
57
We've seen the `Horizontal` container in action.
@@ -69,6 +72,10 @@ And here's the output:
69
72
70
73
Three boxes, vertically stacked.
71
74
75
+
!!! tip "Styling layout"
76
+
77
+
You can set the layout of a compound widget with the [layout](../styles/layout.md) rule.
78
+
72
79
### Size behavior
73
80
74
81
Something to keep in mind when using `Horizontal` or `Vertical` is that they will consume the remaining space in the screen. Let's look at an example to illustrate that.
@@ -100,7 +107,7 @@ And here's the result:
100
107
```
101
108
102
109
Two horizontal containers divide the remaining screen space in two.
103
-
If you were to add another horizontal it would divide the screen space in to thirds--and so on.
110
+
If you were to add another horizontal it would divide the screen space in to thirds—and so on.
104
111
105
112
This makes `Horizontal` and `Vertical` excellent for designing the macro layout of your app's interface, but not for making tightly packed rows or columns. For that you need the *group* containers which I'll cover next.
106
113
@@ -132,7 +139,7 @@ We can see that the widgets are arranged horizontally as before, but they only u
132
139
Something to watch out for regarding the previous containers we have discussed, is that they don't scroll by default.
133
140
Let's see what happens if we add more boxes than could fit on the screen.
134
141
135
-
In the following example, we will add boxes:
142
+
In the following example, we will add 10 boxes:
136
143
137
144
```python hl_lines="28 29"
138
145
--8<--"docs/examples/how-to/containers06.py"
@@ -161,7 +168,84 @@ Here's the output:
161
168
162
169
We now have a scrollbar we can click and drag to see all the boxes.
163
170
164
-
!!! tip "Automatic scrollbars"
171
+
!!! tip "Automatic scrollbars"
172
+
173
+
You can also implement automatic scrollbars with the [overflow](../styles/overflow.md) style.
174
+
175
+
176
+
## Center, Right, and Middle
177
+
178
+
The [Center][textual.containers.Center], [Right][textual.containers.Right], and [Middle][textual.containers.Middle] containers are handy for setting the alignment of select widgets.
179
+
180
+
First lets look at `Center` and `Right` which align their children on the horizontal axis (there is no `Left` container, as this is the default).
0 commit comments