Skip to content

Commit b56f349

Browse files
committed
docs
1 parent c1c94cc commit b56f349

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

docs/api/compose.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
title: "textual.compose"
33
---
44

5-
::: textual.compose
5+
::: textual.compose.compose

src/textual/compose.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
"""
2-
3-
The compose method allows you to mount widgets using the same syntax as the [compose][textual.widget.Widget.compose] method.
4-
5-
```python
6-
7-
def on_key(self, event:events.Key) -> None:
8-
9-
def add_key(key:str) -> ComposeResult:
10-
with containers.HorizontalGroup():
11-
yield Label("You pressed:")
12-
yield Label(key)
13-
14-
self.mount_all(
15-
compose(self, add_key(event.key)),
16-
)
17-
18-
```
19-
20-
21-
"""
22-
231
from __future__ import annotations
242

253
from typing import TYPE_CHECKING
@@ -34,7 +12,21 @@ def add_key(key:str) -> ComposeResult:
3412
def compose(
3513
node: App | Widget, compose_result: ComposeResult | None = None
3614
) -> list[Widget]:
37-
"""Compose child widgets.
15+
"""Compose child widgets from a generator in the same way as [compose][textual.widget.Widget.compose].
16+
17+
Example:
18+
```python
19+
def on_key(self, event:events.Key) -> None:
20+
21+
def add_key(key:str) -> ComposeResult:
22+
with containers.HorizontalGroup():
23+
yield Label("You pressed:")
24+
yield Label(key)
25+
26+
self.mount_all(
27+
compose(self, add_key(event.key)),
28+
)
29+
```
3830
3931
Args:
4032
node: The parent node.

0 commit comments

Comments
 (0)