Skip to content

Commit

Permalink
Merge pull request #5360 from Textualize/fix-auto-alignment
Browse files Browse the repository at this point in the history
Fix alignment in auto container
  • Loading branch information
willmcgugan authored Dec 8, 2024
2 parents 5c65cb9 + 455c085 commit 8cccd7d
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Change default quit key to `ctrl+q` https://github.com/Textualize/textual/pull/5352
- Changed delete line binding on TextArea to use `ctrl+shift+x` https://github.com/Textualize/textual/pull/5352

### Fixed

- Fixed issue with alignment in auto containers https://github.com/Textualize/textual/pull/5360

## [0.89.1] - 2024-11-05

### Fixed
Expand Down
19 changes: 4 additions & 15 deletions src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,11 @@ def get_content_height(
Returns:
Content height (in lines).
"""
if not widget._nodes:
height = 0
else:
# Use a height of zero to ignore relative heights
styles_height = widget.styles.height
if widget._parent and len(widget._nodes) == 1:
# If it is an only child with height auto we want it to expand
height = (
container.height
if styles_height is not None and styles_height.is_auto
else 0
)
else:
height = 0
arrangement = widget._arrange(Size(width, height))
if widget._nodes:
arrangement = widget._arrange(Size(width, 0))
height = arrangement.total_region.bottom
else:
height = 0

return height

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion tests/snapshot_tests/snapshot_apps/max_height_100.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@


class HappyDataTableFunApp(App[None]):
"""The DataTable should expand as if it has height 1fr."""
"""The DataTable should expand to full the screen and show a horizontal scrollbar."""

CSS = """
#s {
max-height: 100%;
}
DataTable {
max-height: 100%;
}
Expand Down
39 changes: 38 additions & 1 deletion tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ def test_vertical_max_height(snap_compare):


def test_max_height_100(snap_compare):
"""Test vertical max height takes border in to account."""
"""Test a datatable with max height 100%."""
assert snap_compare(SNAPSHOT_APPS_DIR / "max_height_100.py")


Expand Down Expand Up @@ -3074,3 +3074,40 @@ def compose(self):
yield MainContainer()

snap_compare(Test1())


def test_auto_parent_with_alignment(snap_compare):
class Sidebar(Vertical):
DEFAULT_CSS = """
Sidebar {
dock: right; # Not strictly required to replicate the issue
width: auto;
height: auto;
background: blue;
align-vertical: bottom;
#contents {
width: auto;
height: auto;
background: red;
border: white;
}
}
"""

def compose(self) -> ComposeResult:
with Vertical(id="contents"):
yield Button("Start")
yield Button("Stop")

class FloatSidebarApp(App):
CSS = """
Screen {
layers: base sidebar;
}
"""

def compose(self) -> ComposeResult:
yield Sidebar()

snap_compare(FloatSidebarApp())

0 comments on commit 8cccd7d

Please sign in to comment.