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

Fix for viewport units, remove DataTable max-height #2247

Merged
merged 6 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Fixed

- Fix viewport units using wrong viewport size https://github.com/Textualize/textual/pull/2247


## [0.19.0] - 2023-04-07

### Added
Expand Down
8 changes: 4 additions & 4 deletions src/textual/_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def resolve_box_models(
dimensions: list[Scalar | None],
widgets: list[Widget],
size: Size,
parent_size: Size,
viewport_size: Size,
margin: Size,
dimension: Literal["width", "height"] = "width",
) -> list[BoxModel]:
Expand All @@ -92,7 +92,7 @@ def resolve_box_models(
dimensions: A list of Scalars or Nones for each dimension.
widgets: Widgets in resolve.
size: Size of container.
parent_size: Size of parent.
viewport_size: Viewport size.
margin: Total space occupied by margin
dimensions: Which dimension to resolve.

Expand All @@ -111,7 +111,7 @@ def resolve_box_models(
None
if dimension is not None and dimension.is_fraction
else widget._get_box_model(
size, parent_size, fraction_width, fraction_height
size, viewport_size, fraction_width, fraction_height
)
)
for (dimension, widget) in zip(dimensions, widgets)
Expand Down Expand Up @@ -148,7 +148,7 @@ def resolve_box_models(
box_model
or widget._get_box_model(
size,
parent_size,
viewport_size,
width_fraction,
height_fraction,
)
Expand Down
3 changes: 1 addition & 2 deletions src/textual/layouts/horizontal.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def arrange(
placements: list[WidgetPlacement] = []
add_placement = placements.append
x = max_height = Fraction(0)
parent_size = parent.outer_size

child_styles = [child.styles for child in children]
box_margins: list[Spacing] = [styles.margin for styles in child_styles]
Expand All @@ -52,7 +51,7 @@ def arrange(
[styles.width for styles in child_styles],
children,
size,
parent_size,
parent.app.size,
resolve_margin,
dimension="width",
)
Expand Down
3 changes: 1 addition & 2 deletions src/textual/layouts/vertical.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def arrange(
) -> ArrangeResult:
placements: list[WidgetPlacement] = []
add_placement = placements.append
parent_size = parent.outer_size

child_styles = [child.styles for child in children]
box_margins: list[Spacing] = [styles.margin for styles in child_styles]
Expand All @@ -49,7 +48,7 @@ def arrange(
[styles.height for styles in child_styles],
children,
size,
parent_size,
parent.app.size,
resolve_margin,
dimension="height",
)
Expand Down
1 change: 0 additions & 1 deletion src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
background: $surface ;
color: $text;
height: auto;
max-height: 100vh;
}
DataTable > .datatable--header {
text-style: bold;
Expand Down
156 changes: 156 additions & 0 deletions tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions tests/snapshot_tests/snapshot_apps/viewport_units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from textual.app import App, ComposeResult
from textual.widgets import Static


class ViewportUnits(App):
CSS = """Static {width: 100vw; height: 100vh; border: solid cyan;} """

def compose(self) -> ComposeResult:
yield Static("Hello, world!")


app = ViewportUnits()
if __name__ == '__main__':
app.run()
5 changes: 5 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ def test_css_property(file_name, snap_compare):
assert snap_compare(path_to_app)


def test_viewport_height_and_width_properties(snap_compare):
path_to_app = SNAPSHOT_APPS_DIR / "viewport_units.py"
assert snap_compare(path_to_app)


def test_multiple_css(snap_compare):
# Interaction between multiple CSS files and app-level/classvar CSS
assert snap_compare("snapshot_apps/multiple_css/multiple_css.py")
Expand Down