Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add containers #2030

Merged
merged 20 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed
### Changed

- Fixed container not resizing when a widget is removed https://github.com/Textualize/textual/issues/2007
- Fixes issue where the horizontal scrollbar would be incorrectly enabled https://github.com/Textualize/textual/pull/2024
- Breaking change: changed default behaviour of `Vertical` (see `VerticalScroll`) https://github.com/Textualize/textual/issues/1957
- The default `overflow` style for `Horizontal` was changed to `hidden hidden` https://github.com/Textualize/textual/issues/1957

### Added

- Added a LoadingIndicator widget https://github.com/Textualize/textual/pull/2018
- Added `HorizontalScroll` https://github.com/Textualize/textual/issues/1957
- Added `Center` https://github.com/Textualize/textual/issues/1957
- Added `Middle` https://github.com/Textualize/textual/issues/1957
- Added `VerticalScroll` (mimicking the old behaviour of `Vertical`) https://github.com/Textualize/textual/issues/1957

### Fixed

- Fixed container not resizing when a widget is removed https://github.com/Textualize/textual/issues/2007
- Fixes issue where the horizontal scrollbar would be incorrectly enabled https://github.com/Textualize/textual/pull/2024

## [0.14.0] - 2023-03-09

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from random import randint
import time
from random import randint

from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, Vertical
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label

Expand All @@ -28,7 +28,7 @@ class MyApp(App[None]):
def compose(self) -> ComposeResult:
yield Grid(
ColourChanger(),
Vertical(id="log"),
VerticalScroll(id="log"),
)
yield Footer()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
from random import randint
import time
from random import randint

from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, Vertical
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label

Expand All @@ -29,7 +29,7 @@ class MyApp(App[None]):
def compose(self) -> ComposeResult:
yield Grid(
ColourChanger(),
Vertical(id="log"),
VerticalScroll(id="log"),
)
yield Footer()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
from random import randint
import time
from random import randint

from textual.app import App, ComposeResult
from textual.color import Color
from textual.containers import Grid, Vertical
from textual.containers import Grid, VerticalScroll
from textual.widget import Widget
from textual.widgets import Footer, Label

Expand All @@ -29,7 +29,7 @@ class MyApp(App[None]):
def compose(self) -> ComposeResult:
yield Grid(
ColourChanger(),
Vertical(id="log"),
VerticalScroll(id="log"),
)
yield Footer()

Expand Down
7 changes: 4 additions & 3 deletions docs/examples/events/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
raise ImportError("Please install httpx with 'pip install httpx' ")

from rich.json import JSON

from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widgets import Static, Input
from textual.containers import VerticalScroll
from textual.widgets import Input, Static


class DictionaryApp(App):
Expand All @@ -18,7 +19,7 @@ class DictionaryApp(App):

def compose(self) -> ComposeResult:
yield Input(placeholder="Search for a word")
yield Vertical(Static(id="results"), id="results-container")
yield VerticalScroll(Static(id="results"), id="results-container")

async def on_input_changed(self, message: Input.Changed) -> None:
"""A coroutine to handle a text changed message."""
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/guide/layout/combining_layouts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical
from textual.containers import Container, Horizontal, VerticalScroll
from textual.widgets import Header, Static


Expand All @@ -9,7 +9,7 @@ class CombiningLayoutsExample(App):
def compose(self) -> ComposeResult:
yield Header()
with Container(id="app-grid"):
with Vertical(id="left-pane"):
with VerticalScroll(id="left-pane"):
for number in range(15):
yield Static(f"Vertical layout, child {number}")
with Horizontal(id="top-right"):
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/styles/height_comparison.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.app import App
from textual.containers import Vertical
from textual.widgets import Placeholder, Label, Static
from textual.containers import VerticalScroll
from textual.widgets import Label, Placeholder, Static


class Ruler(Static):
Expand All @@ -11,7 +11,7 @@ def compose(self):

class HeightComparisonApp(App):
def compose(self):
yield Vertical(
yield VerticalScroll(
Placeholder(id="cells"), # (1)!
Placeholder(id="percent"),
Placeholder(id="w"),
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/styles/max_width.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from textual.app import App
from textual.containers import Vertical
from textual.containers import VerticalScroll
from textual.widgets import Placeholder


class MaxWidthApp(App):
def compose(self):
yield Vertical(
yield VerticalScroll(
Placeholder("max-width: 50h", id="p1"),
Placeholder("max-width: 999", id="p2"),
Placeholder("max-width: 50%", id="p3"),
Expand Down
5 changes: 3 additions & 2 deletions docs/examples/styles/min_width.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Vertical {
VerticalScroll {
height: 100%;
width: 100%;
overflow-x: auto;
Expand All @@ -10,7 +10,8 @@ Placeholder {
}

#p1 {
min-width: 25%; /* (1)! */
min-width: 25%;
/* (1)! */
}

#p2 {
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/styles/min_width.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from textual.app import App
from textual.containers import Vertical
from textual.containers import VerticalScroll
from textual.widgets import Placeholder


class MinWidthApp(App):
def compose(self):
yield Vertical(
yield VerticalScroll(
Placeholder("min-width: 25%", id="p1"),
Placeholder("min-width: 75%", id="p2"),
Placeholder("min-width: 100", id="p3"),
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/styles/overflow.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Screen {
color: black;
}

Vertical {
VerticalScroll {
width: 1fr;
}

Expand All @@ -13,7 +13,7 @@ Static {
border: green wide;
color: white 90%;
height: auto;
}
}

#right {
overflow-y: hidden;
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/styles/overflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textual.app import App
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Static
from textual.containers import Horizontal, Vertical

TEXT = """I must not fear.
Fear is the mind-killer.
Expand All @@ -14,8 +14,8 @@
class OverflowApp(App):
def compose(self):
yield Horizontal(
Vertical(Static(TEXT), Static(TEXT), Static(TEXT), id="left"),
Vertical(Static(TEXT), Static(TEXT), Static(TEXT), id="right"),
VerticalScroll(Static(TEXT), Static(TEXT), Static(TEXT), id="left"),
VerticalScroll(Static(TEXT), Static(TEXT), Static(TEXT), id="right"),
)


Expand Down
4 changes: 2 additions & 2 deletions docs/examples/styles/visibility_containers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from textual.app import App
from textual.containers import Horizontal, Vertical
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Placeholder


class VisibilityContainersApp(App):
def compose(self):
yield Vertical(
yield VerticalScroll(
Horizontal(
Placeholder(),
Placeholder(),
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/widgets/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Button {
margin: 1 2;
}

Horizontal > Vertical {
Horizontal>VerticalScroll {
rodrigogiraoserrao marked this conversation as resolved.
Show resolved Hide resolved
width: 24;
}

Expand Down
6 changes: 3 additions & 3 deletions docs/examples/widgets/button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Button, Static


Expand All @@ -8,15 +8,15 @@ class ButtonsApp(App[str]):

def compose(self) -> ComposeResult:
yield Horizontal(
Vertical(
VerticalScroll(
Static("Standard Buttons", classes="header"),
Button("Default"),
Button("Primary!", variant="primary"),
Button.success("Success!"),
Button.warning("Warning!"),
Button.error("Error!"),
),
Vertical(
VerticalScroll(
Static("Disabled Buttons", classes="header"),
Button("Default", disabled=True),
Button("Primary!", variant="primary", disabled=True),
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/widgets/checkbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Screen {
align: center middle;
}

Vertical {
VerticalScroll {
width: auto;
height: auto;
border: solid $primary;
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/widgets/checkbox.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.containers import VerticalScroll
from textual.widgets import Checkbox


class CheckboxApp(App[None]):
CSS_PATH = "checkbox.css"

def compose(self) -> ComposeResult:
with Vertical():
with VerticalScroll():
yield Checkbox("Arrakis :sweat:")
yield Checkbox("Caladan")
yield Checkbox("Chusuk")
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/widgets/placeholder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from textual.app import App, ComposeResult
from textual.containers import Container, Horizontal, Vertical
from textual.containers import Container, Horizontal, VerticalScroll
from textual.widgets import Placeholder


class PlaceholderApp(App):

CSS_PATH = "placeholder.css"

def compose(self) -> ComposeResult:
yield Vertical(
yield VerticalScroll(
Container(
Placeholder("This is a custom label for p1.", id="p1"),
Placeholder("Placeholder p2 here!", id="p2"),
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/widgets/radio_set_changed.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Vertical {
VerticalScroll {
align: center middle;
}

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/widgets/radio_set_changed.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Label, RadioButton, RadioSet


class RadioSetChangedApp(App[None]):
CSS_PATH = "radio_set_changed.css"

def compose(self) -> ComposeResult:
with Vertical():
with VerticalScroll():
with Horizontal():
with RadioSet():
yield RadioButton("Battlestar Galactica")
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ exceeds the available horizontal space in the parent container.

## Utility containers

Textual comes with several "container" widgets.
These are [Vertical][textual.containers.Vertical], [Horizontal][textual.containers.Horizontal], and [Grid][textual.containers.Grid] which have the corresponding layout.
Textual comes with [several "container" widgets][textual.containers].
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.
Inside a single `Horizontal` container, we place two `Vertical` containers.
Expand Down Expand Up @@ -163,8 +163,8 @@ However, Textual comes with a more powerful mechanism for achieving this known a

## Composing with context managers

In the previous section we've show 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.
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.

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.
Expand Down Expand Up @@ -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"}
```

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

Expand Down
4 changes: 2 additions & 2 deletions docs/styles/height.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Open the CSS file tab to see the comments that explain how each height is comput

1. This sets the height to 2 lines.
2. This sets the height to 12.5% of the space made available by the container. The container is 24 lines tall, so 12.5% of 24 is 3.
3. This sets the height to 5% of the width of the direct container, which is the `Vertical` container. Because it expands to fit all of the terminal, the width of the `Vertical` is 80 and 5% of 80 is 4.
4. This sets the height to 12.5% of the height of the direct container, which is the `Vertical` container. Because it expands to fit all of the terminal, the height of the `Vertical` is 24 and 12.5% of 24 is 3.
3. This sets the height to 5% of the width of the direct container, which is the `VerticalScroll` container. Because it expands to fit all of the terminal, the width of the `VerticalScroll` is 80 and 5% of 80 is 4.
4. This sets the height to 12.5% of the height of the direct container, which is the `VerticalScroll` container. Because it expands to fit all of the terminal, the height of the `VerticalScroll` is 24 and 12.5% of 24 is 3.
5. This sets the height to 6.25% of the viewport width, which is 80. 6.25% of 80 is 5.
6. This sets the height to 12.5% of the viewport height, which is 24. 12.5% of 24 is 3.
7. This sets the height of the placeholder to be the optimal size that fits the content without scrolling.
Expand Down
2 changes: 1 addition & 1 deletion docs/styles/overflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The default setting for containers is `overflow: auto auto`.

!!! warning

Some built-in containers like `Horizontal` and `Vertical` override these defaults.
Some built-in containers like `Horizontal` and `VerticalScroll` override these defaults.

## Example

Expand Down
Loading