Skip to content

Commit 40cc2db

Browse files
authored
Fix for viewport units, remove DataTable max-height (#2247)
* Add viewport units snapshot test * Fix snapshot app * Update snapshots * Update DataTable max-height to 100% * Update CHANGELOG.md * Remove max height from DataTable CSS
1 parent b8468ff commit 40cc2db

File tree

8 files changed

+188
-9
lines changed

8 files changed

+188
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fix viewport units using wrong viewport size https://github.com/Textualize/textual/pull/2247
13+
14+
815
## [0.19.0] - 2023-04-07
916

1017
### Added

src/textual/_resolve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def resolve_box_models(
8282
dimensions: list[Scalar | None],
8383
widgets: list[Widget],
8484
size: Size,
85-
parent_size: Size,
85+
viewport_size: Size,
8686
margin: Size,
8787
dimension: Literal["width", "height"] = "width",
8888
) -> list[BoxModel]:
@@ -92,7 +92,7 @@ def resolve_box_models(
9292
dimensions: A list of Scalars or Nones for each dimension.
9393
widgets: Widgets in resolve.
9494
size: Size of container.
95-
parent_size: Size of parent.
95+
viewport_size: Viewport size.
9696
margin: Total space occupied by margin
9797
dimensions: Which dimension to resolve.
9898
@@ -111,7 +111,7 @@ def resolve_box_models(
111111
None
112112
if dimension is not None and dimension.is_fraction
113113
else widget._get_box_model(
114-
size, parent_size, fraction_width, fraction_height
114+
size, viewport_size, fraction_width, fraction_height
115115
)
116116
)
117117
for (dimension, widget) in zip(dimensions, widgets)
@@ -148,7 +148,7 @@ def resolve_box_models(
148148
box_model
149149
or widget._get_box_model(
150150
size,
151-
parent_size,
151+
viewport_size,
152152
width_fraction,
153153
height_fraction,
154154
)

src/textual/layouts/horizontal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def arrange(
2525
placements: list[WidgetPlacement] = []
2626
add_placement = placements.append
2727
x = max_height = Fraction(0)
28-
parent_size = parent.outer_size
2928

3029
child_styles = [child.styles for child in children]
3130
box_margins: list[Spacing] = [styles.margin for styles in child_styles]
@@ -52,7 +51,7 @@ def arrange(
5251
[styles.width for styles in child_styles],
5352
children,
5453
size,
55-
parent_size,
54+
parent.app.size,
5655
resolve_margin,
5756
dimension="width",
5857
)

src/textual/layouts/vertical.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def arrange(
2222
) -> ArrangeResult:
2323
placements: list[WidgetPlacement] = []
2424
add_placement = placements.append
25-
parent_size = parent.outer_size
2625

2726
child_styles = [child.styles for child in children]
2827
box_margins: list[Spacing] = [styles.margin for styles in child_styles]
@@ -49,7 +48,7 @@ def arrange(
4948
[styles.height for styles in child_styles],
5049
children,
5150
size,
52-
parent_size,
51+
parent.app.size,
5352
resolve_margin,
5453
dimension="height",
5554
)

src/textual/widgets/_data_table.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
249249
background: $surface ;
250250
color: $text;
251251
height: auto;
252-
max-height: 100vh;
253252
}
254253
DataTable > .datatable--header {
255254
text-style: bold;

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 156 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import Static
3+
4+
5+
class ViewportUnits(App):
6+
CSS = """Static {width: 100vw; height: 100vh; border: solid cyan;} """
7+
8+
def compose(self) -> ComposeResult:
9+
yield Static("Hello, world!")
10+
11+
12+
app = ViewportUnits()
13+
if __name__ == '__main__':
14+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ def test_css_property(file_name, snap_compare):
211211
assert snap_compare(path_to_app)
212212

213213

214+
def test_viewport_height_and_width_properties(snap_compare):
215+
path_to_app = SNAPSHOT_APPS_DIR / "viewport_units.py"
216+
assert snap_compare(path_to_app)
217+
218+
214219
def test_multiple_css(snap_compare):
215220
# Interaction between multiple CSS files and app-level/classvar CSS
216221
assert snap_compare("snapshot_apps/multiple_css/multiple_css.py")

0 commit comments

Comments
 (0)