From f094588cfbc89f3857bacfc7e11bd2caf0f553ee Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 20 Mar 2024 14:19:50 +0000 Subject: [PATCH 1/4] snapshot --- src/textual/_layout.py | 2 +- .../snapshot_apps/button_widths.py | 25 +++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 5 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot_tests/snapshot_apps/button_widths.py diff --git a/src/textual/_layout.py b/src/textual/_layout.py index c147a0e419..513791038e 100644 --- a/src/textual/_layout.py +++ b/src/textual/_layout.py @@ -161,7 +161,7 @@ def get_content_width(self, widget: Widget, container: Size, viewport: Size) -> width = 0 else: # Use a size of 0, 0 to ignore relative sizes, since those are flexible anyway - arrangement = widget._arrange(Size(0, 0)) + arrangement = widget._arrange(Size(container.width, 0)) return arrangement.total_region.right return width diff --git a/tests/snapshot_tests/snapshot_apps/button_widths.py b/tests/snapshot_tests/snapshot_apps/button_widths.py new file mode 100644 index 0000000000..e01c310187 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/button_widths.py @@ -0,0 +1,25 @@ +from textual.app import App, ComposeResult +from textual.containers import Horizontal +from textual.widgets import Button + + +class HorizontalWidthAutoApp(App[None]): + CSS = """ + Horizontal { + border: solid red; + height: auto; + width: auto; + } + """ + + def compose(self) -> ComposeResult: + with Horizontal(classes="auto"): + yield Button("This is a very wide button") + + with Horizontal(classes="auto"): + yield Button("This is a very wide button") + yield Button("This is a very wide button") + + +if __name__ == "__main__": + HorizontalWidthAutoApp().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 531a9190ef..b80c8af9ae 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1156,3 +1156,8 @@ def test_placeholder_disabled(snap_compare): def test_listview_index(snap_compare): """Tests that ListView scrolls correctly after updating its index.""" assert snap_compare(SNAPSHOT_APPS_DIR / "listview_index.py") + + +def test_button_widths(snap_compare): + """Test that button widths expand auto containers as expected.""" + assert snap_compare(SNAPSHOT_APPS_DIR / "button_widths.py") From 7e3b8d19da91596fbbab9f4d612a540b9426cdb8 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 20 Mar 2024 14:21:42 +0000 Subject: [PATCH 2/4] comment --- tests/snapshot_tests/test_snapshots.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index b80c8af9ae..d33a4178f3 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1160,4 +1160,5 @@ def test_listview_index(snap_compare): def test_button_widths(snap_compare): """Test that button widths expand auto containers as expected.""" + # https://github.com/Textualize/textual/issues/4024 assert snap_compare(SNAPSHOT_APPS_DIR / "button_widths.py") From df99eb9c41cc47c5f3384ac92d97059f1c651716 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 20 Mar 2024 14:30:19 +0000 Subject: [PATCH 3/4] snapshot --- .../__snapshots__/test_snapshots.ambr | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index cfe5b99be1..0d054a47ee 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -2161,6 +2161,166 @@ ''' # --- +# name: test_button_widths + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HorizontalWidthAutoApp + + + + + + + + + + ──────────────────────────── + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + This is a very wide button + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + ──────────────────────────── + ──────────────────────────────────────────────────────── + ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ + This is a very wide buttonThis is a very wide button + ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ + ──────────────────────────────────────────────────────── + + + + + + + + + + + + + + + + + + + ''' +# --- # name: test_buttons_render ''' From 4ff172a3c8b9c835d7d19aaf34c23c916dc894c7 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 20 Mar 2024 14:43:51 +0000 Subject: [PATCH 4/4] remove comment [skip ci] --- src/textual/_layout.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/textual/_layout.py b/src/textual/_layout.py index 513791038e..8048a0f303 100644 --- a/src/textual/_layout.py +++ b/src/textual/_layout.py @@ -160,7 +160,6 @@ def get_content_width(self, widget: Widget, container: Size, viewport: Size) -> if not widget._nodes: width = 0 else: - # Use a size of 0, 0 to ignore relative sizes, since those are flexible anyway arrangement = widget._arrange(Size(container.width, 0)) return arrangement.total_region.right return width