From 0a8b001c625f1964ce3818d85880c4ab67f069ac Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 4 Dec 2022 17:17:27 +0700 Subject: [PATCH 1/4] fix for layer ordering --- src/textual/_arrange.py | 1 + .../snapshot_apps/order_independence.py | 71 +++++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 10 +++ 3 files changed, 82 insertions(+) create mode 100644 tests/snapshot_tests/snapshot_apps/order_independence.py diff --git a/src/textual/_arrange.py b/src/textual/_arrange.py index 2bf706e0f..1ef708619 100644 --- a/src/textual/_arrange.py +++ b/src/textual/_arrange.py @@ -51,6 +51,7 @@ def arrange( styles = widget.styles for widgets in dock_layers.values(): + region = size.region layout_widgets, dock_widgets = partition(get_dock, widgets) diff --git a/tests/snapshot_tests/snapshot_apps/order_independence.py b/tests/snapshot_tests/snapshot_apps/order_independence.py new file mode 100644 index 000000000..0c682c859 --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/order_independence.py @@ -0,0 +1,71 @@ +from textual.app import App, ComposeResult +from textual.screen import Screen +from textual.widgets import Header, Footer, Label +from textual.containers import Vertical, Container + + +class Overlay(Container): + def compose(self) -> ComposeResult: + yield Label("This should float over the top") + + +class Body1(Vertical): + def compose(self) -> ComposeResult: + yield Label("My God! It's full of stars! " * 300) + + +class Body2(Vertical): + def compose(self) -> ComposeResult: + yield Label("I'm sorry, Dave. I'm afraid I can't do that. " * 300) + + +class Good(Screen): + def compose(self) -> ComposeResult: + yield Header() + yield Overlay() + yield Body1() + yield Footer() + + +class Bad(Screen): + def compose(self) -> ComposeResult: + yield Overlay() + yield Header() + yield Body2() + yield Footer() + + +class Layers(App[None]): + + CSS = """ + Screen { + layers: base higher; + } + + Overlay { + layer: higher; + dock: top; + width: auto; + height: auto; + padding: 2; + border: solid yellow; + background: red; + color: yellow; + } + """ + + SCREENS = {"good": Good, "bad": Bad} + + BINDINGS = [("t", "toggle", "Toggle Screen")] + + def on_mount(self): + self.push_screen("good") + + def action_toggle(self): + self.switch_screen( + "bad" if self.screen.__class__.__name__ == "Good" else "good" + ) + + +if __name__ == "__main__": + Layers().run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index aae9669db..e287186c7 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -126,6 +126,16 @@ def test_multiple_css(snap_compare): assert snap_compare("snapshot_apps/multiple_css/multiple_css.py") +def test_order_independence(snap_compare): + # Interaction between multiple CSS files and app-level/classvar CSS + assert snap_compare("snapshot_apps/order_independence.py") + + +def test_order_independence_toggle(snap_compare): + # Interaction between multiple CSS files and app-level/classvar CSS + assert snap_compare("snapshot_apps/order_independence.py", press="t") + + # --- Other --- From eab69a773921b3ff1092b04ca07807ce75e3c373 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 4 Dec 2022 17:18:42 +0700 Subject: [PATCH 2/4] snapshots --- .../__snapshots__/test_snapshots.ambr | 320 ++++++++++++++++++ 1 file changed, 320 insertions(+) diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr index 977ab4286..a92a00f7a 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr +++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr @@ -6637,6 +6637,326 @@ ''' # --- +# name: test_order_independence + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layers + + + + + + + + + + ┌────────────────────────────────────────┐ + ull of stars! My God! It's full of  +  It's full of stars! My God! It's  + This should float over the top My God! It's full of stars! My God! + tars! My God! It's full of stars! My +  of stars! My God! It's full of ▄▄ + └────────────────────────────────────────┘ It's full of stars! My God! It's  + full of stars! My God! It's full of stars! My God! It's full of stars! My God! + It's full of stars! My God! It's full of stars! My God! It's full of stars! My + God! It's full of stars! My God! It's full of stars! My God! It's full of  + stars! My God! It's full of stars! My God! It's full of stars! My God! It's  + full of stars! My God! It's full of stars! My God! It's full of stars! My God! + It's full of stars! My God! It's full of stars! My God! It's full of stars! My + God! It's full of stars! My God! It's full of stars! My God! It's full of  + stars! My God! It's full of stars! My God! It's full of stars! My God! It's  + full of stars! My God! It's full of stars! My God! It's full of stars! My God! + It's full of stars! My God! It's full of stars! My God! It's full of stars! My + God! It's full of stars! My God! It's full of stars! My God! It's full of  + stars! My God! It's full of stars! My God! It's full of stars! My God! It's  + full of stars! My God! It's full of stars! My God! It's full of stars! My God! + It's full of stars! My God! It's full of stars! My God! It's full of stars! My + God! It's full of stars! My God! It's full of stars! My God! It's full of  + stars! My God! It's full of stars! My God! It's full of stars! My God! It's  +  T  Toggle Screen  + + + + + ''' +# --- +# name: test_order_independence_toggle + ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Layers + + + + + + + + + + ┌────────────────────────────────────────┐ + t. I'm sorry, Dave. I'm afraid I  +  I can't do that. I'm sorry, Dave.  + This should float over the tope. I'm afraid I can't do that. I'm ▂▂ + 'm sorry, Dave. I'm afraid I can't  + 't do that. I'm sorry, Dave. I'm  + └────────────────────────────────────────┘'m afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  + do that. I'm sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm  + afraid I can't do that. I'm sorry, Dave. I'm afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  + do that. I'm sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm  + afraid I can't do that. I'm sorry, Dave. I'm afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  + do that. I'm sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm  + afraid I can't do that. I'm sorry, Dave. I'm afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  + do that. I'm sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm  + afraid I can't do that. I'm sorry, Dave. I'm afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  + do that. I'm sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm  + afraid I can't do that. I'm sorry, Dave. I'm afraid I can't do that. I'm  + sorry, Dave. I'm afraid I can't do that. I'm sorry, Dave. I'm afraid I can't  +  T  Toggle Screen  + + + + + ''' +# --- # name: test_textlog_max_lines ''' From cc6f1c248d72226657c31979a8f9ca71521e0551 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 4 Dec 2022 17:22:51 +0700 Subject: [PATCH 3/4] tiny optimiztion --- src/textual/_arrange.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/textual/_arrange.py b/src/textual/_arrange.py index 1ef708619..eb9818ee7 100644 --- a/src/textual/_arrange.py +++ b/src/textual/_arrange.py @@ -41,7 +41,6 @@ def arrange( placements: list[WidgetPlacement] = [] add_placement = placements.append - region = size.region _WidgetPlacement = WidgetPlacement top_z = TOP_Z @@ -50,8 +49,9 @@ def arrange( get_dock = attrgetter("styles.dock") styles = widget.styles + layer_region = size.region for widgets in dock_layers.values(): - region = size.region + region = layer_region layout_widgets, dock_widgets = partition(get_dock, widgets) From 962b7d64b41b9c2247f98a6ac5537bf78357c7f7 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sun, 4 Dec 2022 17:25:09 +0700 Subject: [PATCH 4/4] pause --- tests/snapshot_tests/test_snapshots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index e287186c7..338d3fb5d 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -133,7 +133,7 @@ def test_order_independence(snap_compare): def test_order_independence_toggle(snap_compare): # Interaction between multiple CSS files and app-level/classvar CSS - assert snap_compare("snapshot_apps/order_independence.py", press="t") + assert snap_compare("snapshot_apps/order_independence.py", press="t,_") # --- Other ---