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 alignment in auto container #5360

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 1 addition & 12 deletions src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,7 @@ def get_content_height(
if not widget._nodes:
height = 0
else:
# Use a height of zero to ignore relative heights
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may have been a workaround for an issue that was since fixed in another (likely better) way.

Only a single text broke, but the output was as I'd expect.

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))
arrangement = widget._arrange(Size(width, 0))
height = arrangement.total_region.bottom

return height
Expand Down
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;
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())
Loading