Skip to content

Commit

Permalink
Add 'Vertical'.
Browse files Browse the repository at this point in the history
Related issues: #1957.
  • Loading branch information
rodrigogiraoserrao committed Mar 9, 2023
1 parent 38c7cc1 commit 5674b4b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Renamed `Vertical` to `VerticalScroll` https://github.com/Textualize/textual/issues/1957
- Default `overflow` style for `Horizontal` changed to `hidden hidden` https://github.com/Textualize/textual/issues/1957
- 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 `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


## [0.14.0] - 2023-03-09
Expand Down
12 changes: 12 additions & 0 deletions src/textual/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ class Container(Widget):
"""


class Vertical(Widget):
"""A container which lays children vertically."""

DEFAULT_CSS = """
Vertical {
width: 1fr;
layout: vertical;
overflow: hidden hidden;
}
"""


class VerticalScroll(Widget):
"""A container which aligns children vertically and overflows automatically."""

Expand Down
38 changes: 37 additions & 1 deletion tests/test_containers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
"""Test basic functioning of some containers."""

from textual.app import App, ComposeResult
from textual.containers import Center, Horizontal, HorizontalScroll, Middle
from textual.containers import (
Center,
Horizontal,
HorizontalScroll,
Middle,
Vertical,
VerticalScroll,
)
from textual.widgets import Label


Expand Down Expand Up @@ -34,6 +41,35 @@ def compose(self) -> ComposeResult:
assert horizontal_scroll.scrollbars_enabled == (False, True)


async def test_vertical_vs_verticalscroll_scrolling():
"""Check the default scrollbar behaviours for `Vertical` and `VerticalScroll`."""

class VerticalsApp(App[None]):
CSS = """
Screen {
layout: horizontal;
}
"""

def compose(self) -> ComposeResult:
with Vertical():
for _ in range(10):
yield Label("How is life going?\n" * 3 + "\n\n")
with VerticalScroll():
for _ in range(10):
yield Label("How is life going?\n" * 3 + "\n\n")

WIDTH = 80
HEIGHT = 24
app = VerticalsApp()
async with app.run_test(size=(WIDTH, HEIGHT)):
vertical = app.query_one(Vertical)
vertical_scroll = app.query_one(VerticalScroll)
assert vertical.size.width == vertical_scroll.size.width
assert vertical.scrollbars_enabled == (False, False)
assert vertical_scroll.scrollbars_enabled == (True, False)


async def test_center_container():
"""Check the size of the container `Center`."""

Expand Down

0 comments on commit 5674b4b

Please sign in to comment.