mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Make docs comply with new containers.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Horizontal, VerticalScroll
|
from textual.containers import Horizontal, Vertical
|
||||||
from textual.widgets import Static
|
from textual.widgets import Static
|
||||||
|
|
||||||
|
|
||||||
@@ -8,12 +8,12 @@ class UtilityContainersExample(App):
|
|||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Horizontal(
|
yield Horizontal(
|
||||||
VerticalScroll(
|
Vertical(
|
||||||
Static("One"),
|
Static("One"),
|
||||||
Static("Two"),
|
Static("Two"),
|
||||||
classes="column",
|
classes="column",
|
||||||
),
|
),
|
||||||
VerticalScroll(
|
Vertical(
|
||||||
Static("Three"),
|
Static("Three"),
|
||||||
Static("Four"),
|
Static("Four"),
|
||||||
classes="column",
|
classes="column",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Horizontal, VerticalScroll
|
from textual.containers import Horizontal, Vertical
|
||||||
from textual.widgets import Static
|
from textual.widgets import Static
|
||||||
|
|
||||||
|
|
||||||
@@ -8,10 +8,10 @@ class UtilityContainersExample(App):
|
|||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
with Horizontal():
|
with Horizontal():
|
||||||
with VerticalScroll(classes="column"):
|
with Vertical(classes="column"):
|
||||||
yield Static("One")
|
yield Static("One")
|
||||||
yield Static("Two")
|
yield Static("Two")
|
||||||
with VerticalScroll(classes="column"):
|
with Vertical(classes="column"):
|
||||||
yield Static("Three")
|
yield Static("Three")
|
||||||
yield Static("Four")
|
yield Static("Four")
|
||||||
|
|
||||||
|
|||||||
@@ -134,11 +134,11 @@ exceeds the available horizontal space in the parent container.
|
|||||||
|
|
||||||
## Utility containers
|
## Utility containers
|
||||||
|
|
||||||
Textual comes with several "container" widgets.
|
Textual comes with [several "container" widgets][textual.containers].
|
||||||
These are [VerticalScroll][textual.containers.VerticalScroll], [Horizontal][textual.containers.Horizontal], and [Grid][textual.containers.Grid] which have the corresponding layout.
|
Among them, we have [Vertical][textual.containers.Vertical], [Horizontal][textual.containers.Horizontal], and [Grid][textual.containers.Grid] which have the corresponding layout.
|
||||||
|
|
||||||
The example below shows how we can combine these containers to create a simple 2x2 grid.
|
The example below shows how we can combine these containers to create a simple 2x2 grid.
|
||||||
Inside a single `Horizontal` container, we place two `VerticalScroll` containers.
|
Inside a single `Horizontal` container, we place two `Vertical` containers.
|
||||||
In other words, we have a single row containing two columns.
|
In other words, we have a single row containing two columns.
|
||||||
|
|
||||||
=== "Output"
|
=== "Output"
|
||||||
@@ -163,8 +163,8 @@ However, Textual comes with a more powerful mechanism for achieving this known a
|
|||||||
|
|
||||||
## Composing with context managers
|
## Composing with context managers
|
||||||
|
|
||||||
In the previous section we've show how you add children to a container (such as `Horizontal` and `VerticalScroll`) using positional arguments.
|
In the previous section, we've shown how you add children to a container (such as `Horizontal` and `Vertical`) using positional arguments.
|
||||||
It's fine to do it this way, but Textual offers a simplified syntax using [context managers](https://docs.python.org/3/reference/datamodel.html#context-managers) which is generally easier to write and edit.
|
It's fine to do it this way, but Textual offers a simplified syntax using [context managers](https://docs.python.org/3/reference/datamodel.html#context-managers), which is generally easier to write and edit.
|
||||||
|
|
||||||
When composing a widget, you can introduce a container using Python's `with` statement.
|
When composing a widget, you can introduce a container using Python's `with` statement.
|
||||||
Any widgets yielded within that block are added as a child of the container.
|
Any widgets yielded within that block are added as a child of the container.
|
||||||
@@ -202,7 +202,7 @@ Let's update the [utility containers](#utility-containers) example to use the co
|
|||||||
```{.textual path="docs/examples/guide/layout/utility_containers_using_with.py"}
|
```{.textual path="docs/examples/guide/layout/utility_containers_using_with.py"}
|
||||||
```
|
```
|
||||||
|
|
||||||
Note how the end result is the same, but the code with context managers is a little easer to read. It is up to you which method you want to use, and you can mix context managers with positional arguments if you like!
|
Note how the end result is the same, but the code with context managers is a little easier to read. It is up to you which method you want to use, and you can mix context managers with positional arguments if you like!
|
||||||
|
|
||||||
## Grid
|
## Grid
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user