Skip to content

Commit df77f68

Browse files
committed
docs update
1 parent 0f3de98 commit df77f68

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

docs/guide/CSS.md

+25-10
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,25 @@ With a header and a footer widget the DOM looks like this:
100100
--8<-- "docs/images/dom2.excalidraw.svg"
101101
</div>
102102

103-
!!! note
103+
!!! note "What we didn't show"
104104

105105
We've simplified the above example somewhat. Both the Header and Footer widgets contain children of their own. When building an app with pre-built widgets you rarely need to know how they are constructed unless you plan on changing the styles of individual components.
106106

107107
Both Header and Footer are children of the Screen object.
108108

109109
To further explore the DOM, we're going to build a simple dialog with a question and two buttons. To do this we're going to import and use a few more builtin widgets:
110110

111-
- `textual.layout.Container` For our top-level dialog.
112-
- `textual.layout.Horizontal` To arrange widgets left to right.
113-
- `textual.widgets.Static` For simple content.
114-
- `textual.widgets.Button` For a clickable button.
111+
- [`textual.containers.Container`][textual.containers.Container] For our top-level dialog.
112+
- [`textual.containers.Horizontal`][textual.containers.Horizontal] To arrange widgets left to right.
113+
- [`textual.widgets.Static`][textual.widgets.Static] For simple content.
114+
- [`textual.widgets.Button`][textual.widgets.Button] For a clickable button.
115115

116116

117117
```python hl_lines="12 13 14 15 16 17 18 19 20" title="dom3.py"
118118
--8<-- "docs/examples/guide/dom3.py"
119119
```
120120

121-
We've added a Container to our DOM which (as the name suggests) is a container for other widgets. The container has a number of other widgets passed as positional arguments which will be added as the children of the container. Not all widgets accept child widgets in this way. A Button widget doesn't require any children, for example.
121+
We've added a Container to our DOM which (as the name suggests) contains other widgets. The container has a number of other widgets passed as positional arguments which will be added as the children of the container. Not all widgets accept child widgets in this way. A Button widget doesn't require any children, for example.
122122

123123
Here's the DOM created by the above code:
124124

@@ -139,7 +139,7 @@ You may recognize some elements in the above screenshot, but it doesn't quite lo
139139
To add a stylesheet set the `CSS_PATH` classvar to a relative path:
140140

141141

142-
!!! note
142+
!!! note "What are TCSS files?"
143143

144144
Textual CSS files are typically given the extension `.tcss` to differentiate them from browser CSS (`.css`).
145145

@@ -223,7 +223,7 @@ Static {
223223
}
224224
```
225225

226-
!!! note
226+
!!! note "This is different to browser CSS"
227227

228228
The fact that the type selector matches base classes is a departure from browser CSS which doesn't have the same concept.
229229

@@ -312,6 +312,18 @@ For example, the following will draw a red outline around all widgets:
312312
}
313313
```
314314

315+
While it is rare to need to style all widgets, you can combine the universal selector with a parent, to select all children of that parent.
316+
317+
For instance, here's how we would make all children of a `VerticalScroll` have a red background:
318+
319+
```css
320+
VerticalScroll * {
321+
background: red;
322+
}
323+
```
324+
325+
See [Combinators](#combinators) for more details on combining selectors like this.
326+
315327
### Pseudo classes
316328

317329
Pseudo classes can be used to match widgets in a particular state. Pseudo classes are set automatically by Textual. For instance, you might want a button to have a green background when the mouse cursor moves over it. We can do this with the `:hover` pseudo selector.
@@ -403,7 +415,7 @@ It is possible that several selectors match a given widget. If the same style is
403415

404416
The specificity rules are usually enough to fix any conflicts in your stylesheets. There is one last way of resolving conflicting selectors which applies to individual rules. If you add the text `!important` to the end of a rule then it will "win" regardless of the specificity.
405417

406-
!!! warning
418+
!!! warning "If everything is Important, nothing is Important"
407419

408420
Use `!important` sparingly (if at all) as it can make it difficult to modify your CSS in the future.
409421

@@ -445,7 +457,7 @@ This will be translated into:
445457
Variables allow us to define reusable styling in a single place.
446458
If we decide we want to change some aspect of our design in the future, we only have to update a single variable.
447459

448-
!!! note
460+
!!! note "Where can variables be used?"
449461

450462
Variables can only be used in the _values_ of a CSS declaration. You cannot, for example, refer to a variable inside a selector.
451463

@@ -576,3 +588,6 @@ If we were to add other selectors for additional screens or widgets, it would be
576588
### Why use nesting?
577589

578590
There is no requirement to use nested CSS, but it can help to group related rule sets together (which makes it easier to edit). Nested CSS can also help you avoid some repetition in your selectors, i.e. in the nested CSS we only need to type `#questions` once, rather than four times in the non-nested CSS.
591+
592+
Nesting CSS will also make rules that are *more* specific.
593+
This is useful if you find your rules are applying to widgets that you didn't intend.

docs/guide/app.md

+8-16
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ When you call [App.run()][textual.app.App.run] Textual puts the terminal into a
3434

3535
If you hit ++ctrl+q++ Textual will exit application mode and return you to the command prompt. Any content you had in the terminal prior to application mode will be restored.
3636

37-
!!! tip
38-
39-
A side effect of application mode is that you may no longer be able to select and copy text in the usual way. Terminals typically offer a way to bypass this limit with a key modifier. On iTerm you can select text if you hold the ++option++ key. See the documentation for your terminal software for how to select text in application mode.
4037

4138
#### Run inline
4239

@@ -65,14 +62,10 @@ We recommend the default behavior for full-screen apps, but you may want to pres
6562

6663
## Events
6764

68-
Textual has an event system you can use to respond to key presses, mouse actions, and internal state changes. Event handlers are methods prefixed with `on_` followed by the name of the event.
65+
Textual has an [event system](./events.md) you can use to respond to key presses, mouse actions, and internal state changes. Event handlers are methods prefixed with `on_` followed by the name of the event.
6966

7067
One such event is the *mount* event which is sent to an application after it enters application mode. You can respond to this event by defining a method called `on_mount`.
7168

72-
!!! info
73-
74-
You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. See [events](./events.md) for details.
75-
7669
Another such event is the *key* event which is sent when the user presses a key. The following example contains handlers for both those events:
7770

7871
```python title="event01.py"
@@ -84,13 +77,12 @@ The `on_mount` handler sets the `self.screen.styles.background` attribute to `"d
8477
```{.textual path="docs/examples/app/event01.py" hl_lines="23-25"}
8578
```
8679

87-
The key event handler (`on_key`) has an `event` parameter which will receive a [Key][textual.events.Key] instance. Every event has an associated event object which will be passed to the handler method if it is present in the method's parameter list.
80+
When you press a key, the key event handler (`on_key`) which will receive a [Key][textual.events.Key] instance.
81+
If you don't require the event in your handler, you can omit it.
8882

89-
!!! note
90-
91-
It is unusual (but not unprecedented) for a method's parameters to affect how it is called. Textual accomplishes this by inspecting the method prior to calling it.
92-
93-
Some events contain additional information you can inspect in the handler. The [Key][textual.events.Key] event has a `key` attribute which is the name of the key that was pressed. The `on_key` method above uses this attribute to change the background color if any of the keys from ++0++ to ++9++ are pressed.
83+
Events may contain additional information which you can inspect in the handler.
84+
In the case of the [Key][textual.events.Key] event, there is a `key` attribute which is the name of the key that was pressed.
85+
The `on_key` method above uses this attribute to change the background color if any of the keys from ++0++ to ++9++ are pressed.
9486

9587
### Async events
9688

@@ -224,7 +216,7 @@ You may have noticed that we subclassed `App[str]` rather than the usual `App`.
224216

225217
The addition of `[str]` tells mypy that `run()` is expected to return a string. It may also return `None` if [App.exit()][textual.app.App.exit] is called without a return value, so the return type of `run` will be `str | None`. Replace the `str` in `[str]` with the type of the value you intend to call the exit method with.
226218

227-
!!! note
219+
!!! note "Typing in Textual"
228220

229221
Type annotations are entirely optional (but recommended) with Textual.
230222

@@ -317,7 +309,7 @@ For example:
317309

318310
## CSS
319311

320-
Textual apps can reference [CSS](CSS.md) files which define how your app and widgets will look, while keeping your Python code free of display related code (which tends to be messy).
312+
Textual apps can reference [CSS](CSS.md) files which define how your app and widgets will look, while keeping your project free of messy display related code.
321313

322314
!!! info
323315

docs/guide/styles.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ This code produces the following result.
134134
```{.textual path="docs/examples/guide/styles/dimensions01.py"}
135135
```
136136

137-
Note how the text wraps in the widget, and is cropped because it doesn't fit in the space provided.
137+
Note how the text wraps, but doesn't fit in the 10 lines provided, resulting in the last line being omitted entirely.
138138

139139
#### Auto dimensions
140140

@@ -189,22 +189,26 @@ With the width set to `"50%"` and the height set to `"80%"`, the widget will kee
189189

190190
Percentage units can be problematic for some relative values. For instance, if we want to divide the screen into thirds, we would have to set a dimension to `33.3333333333%` which is awkward. Textual supports `fr` units which are often better than percentage-based units for these situations.
191191

192-
When specifying `fr` units for a given dimension, Textual will divide the available space by the sum of the `fr` units on that dimension. That space will then be divided amongst the widgets as a proportion of their individual `fr` values.
192+
When specifying `fr` units for a given dimension, Textual will divide the available space by the sum of the `fr` units for that dimension. That space is then assigned according to each widget's `fr` values.
193193

194194
Let's look at an example. We will create two widgets, one with a height of `"2fr"` and one with a height of `"1fr"`.
195195

196196
```python title="dimensions04.py" hl_lines="24-25"
197197
--8<-- "docs/examples/guide/styles/dimensions04.py"
198198
```
199199

200-
The total `fr` units for height is 3. The first widget will have a screen height of two thirds because its height style is set to `2fr`. The second widget's height style is `1fr` so its screen height will be one third. Here's what that looks like.
200+
The total `fr` units for height is 3.
201+
The first widget has a height ot `2fr`, which results in the height being two thirds of the total height.
202+
The second widget has a height of `1fr` which makes it take up the remaining third of the height.
203+
Here's what that looks like.
201204

202205
```{.textual path="docs/examples/guide/styles/dimensions04.py"}
203206
```
204207

205208
### Maximum and minimums
206209

207-
The same units may also be used to set limits on a dimension. The following styles set minimum and maximum sizes and can accept any of the values used in width and height.
210+
The same units may also be used to set limits on a dimension.
211+
The following styles set minimum and maximum sizes and can accept any of the values used in width and height.
208212

209213
- [min-width](../styles/min_width.md) sets a minimum width.
210214
- [max-width](../styles/max_width.md) sets a maximum width.
@@ -345,12 +349,12 @@ Notice how each widget has an additional two rows and columns around the border.
345349
```{.textual path="docs/examples/guide/styles/margin01.py"}
346350
```
347351

348-
!!! note
352+
!!! note "Margins overlap"
349353

350354
In the above example both widgets have a margin of 2, but there are only 2 lines of space between the widgets. This is because margins of consecutive widgets *overlap*. In other words when there are two widgets next to each other Textual picks the greater of the two margins.
351355

352356
## More styles
353357

354-
We've covered the most fundamental styles used by Textual apps, but there are many more which you can use to customize many aspects of how your app looks. See the [Styles reference](../styles/index.md) for a comprehensive list.
358+
We've covered some fundamental styles used by Textual apps, but there are many more which you can use to customize all aspects of how your app looks. See the [Styles reference](../styles/index.md) for a comprehensive list.
355359

356360
In the next chapter we will discuss Textual CSS which is a powerful way of applying styles to widgets that keeps your code free of style attributes.

mkdocs-nav.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ nav:
1010
- "guide/app.md"
1111
- "guide/styles.md"
1212
- "guide/CSS.md"
13-
- "guide/design.md"
1413
- "guide/queries.md"
1514
- "guide/layout.md"
1615
- "guide/events.md"
1716
- "guide/input.md"
1817
- "guide/actions.md"
1918
- "guide/reactivity.md"
19+
- "guide/design.md"
2020
- "guide/widgets.md"
2121
- "guide/content.md"
2222
- "guide/animation.md"

src/textual/containers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
can_maximize: bool | None = None,
8686
) -> None:
8787
"""
88+
Construct a scrollable container.
8889
8990
Args:
9091
*children: Child widgets.
@@ -242,7 +243,7 @@ class Grid(Widget, inherit_bindings=False):
242243

243244

244245
class ItemGrid(Widget, inherit_bindings=False):
245-
"""A container with grid layout."""
246+
"""A container with grid layout and automatic columns."""
246247

247248
DEFAULT_CSS = """
248249
ItemGrid {
@@ -268,6 +269,7 @@ def __init__(
268269
regular: bool = False,
269270
) -> None:
270271
"""
272+
Construct a ItemGrid.
271273
272274
Args:
273275
*children: Child widgets.

0 commit comments

Comments
 (0)