Skip to content

Commit eab073e

Browse files
authored
Layer scroll fix (#2196)
* fix scroll spacing * fix and snapshot * changelog
1 parent e4d158d commit eab073e

File tree

8 files changed

+220
-10
lines changed

8 files changed

+220
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [0.17.3] - 2023-04-02
9+
10+
### [Fixed]
11+
12+
- Fixed scrollable area not taking in to account dock https://github.com/Textualize/textual/issues/2188
13+
814
## [0.17.2] - 2023-04-02
915

1016
### [Fixed]
@@ -693,6 +699,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
693699
- New handler system for messages that doesn't require inheritance
694700
- Improved traceback handling
695701

702+
[0.17.3]: https://github.com/Textualize/textual/compare/v0.17.2...v0.17.3
696703
[0.17.2]: https://github.com/Textualize/textual/compare/v0.17.1...v0.17.2
697704
[0.17.1]: https://github.com/Textualize/textual/compare/v0.17.0...v0.17.1
698705
[0.17.0]: https://github.com/Textualize/textual/compare/v0.16.0...v0.17.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "0.17.2"
3+
version = "0.17.3"
44
homepage = "https://github.com/Textualize/textual"
55
description = "Modern Text User Interface framework"
66
authors = ["Will McGugan <[email protected]>"]

src/textual/_arrange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ def arrange(
128128

129129
placements.extend(layout_placements)
130130

131-
return DockArrangeResult(placements, arrange_widgets)
131+
return DockArrangeResult(placements, arrange_widgets, scroll_spacing)

src/textual/_compositor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,24 +504,25 @@ def add_widget(
504504
}
505505
get_layer_index = layers_to_index.get
506506

507+
scroll_spacing = arrange_result.scroll_spacing
508+
507509
# Add all the widgets
508510
for sub_region, margin, sub_widget, z, fixed in reversed(
509511
placements
510512
):
513+
layer_index = get_layer_index(sub_widget.layer, 0)
511514
# Combine regions with children to calculate the "virtual size"
512515
if fixed:
513516
widget_region = sub_region + placement_offset
514517
else:
515-
total_region = total_region.union(sub_region.grow(margin))
518+
total_region = total_region.union(
519+
sub_region.grow(
520+
margin if layer_index else margin + scroll_spacing
521+
)
522+
)
516523
widget_region = sub_region + placement_scroll_offset
517524

518-
widget_order = order + (
519-
(
520-
get_layer_index(sub_widget.layer, 0),
521-
z,
522-
layer_order,
523-
),
524-
)
525+
widget_order = order + ((layer_index, z, layer_order),)
525526

526527
add_widget(
527528
sub_widget,

src/textual/_layout.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class DockArrangeResult:
2121
"""A `WidgetPlacement` for every widget to describe it's location on screen."""
2222
widgets: set[Widget]
2323
"""A set of widgets in the arrangement."""
24+
scroll_spacing: Spacing
25+
"""Spacing to reduce scrollable area."""
2426

2527
_spatial_map: SpatialMap[WidgetPlacement] | None = None
2628
"""A Spatial map to query widget placements."""

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 164 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from textual.app import App
2+
from textual.widgets import Header, Label, Footer
3+
4+
5+
class TestApp(App):
6+
BINDINGS = [("ctrl+q", "app.quit", "Quit")]
7+
CSS = """
8+
9+
Label {
10+
border: solid red;
11+
}
12+
Footer {
13+
height: 4;
14+
}
15+
"""
16+
17+
def compose(self):
18+
text = (
19+
"this is a sample sentence and here are some words".replace(" ", "\n") * 2
20+
)
21+
yield Header()
22+
yield Label(text)
23+
yield Footer()
24+
25+
def on_mount(self):
26+
self.dark = False
27+
28+
29+
if __name__ == "__main__":
30+
app = TestApp()
31+
app.run()

tests/snapshot_tests/test_snapshots.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,8 @@ def test_modal_dialog_bindings(snap_compare):
381381
SNAPSHOT_APPS_DIR / "modal_screen_bindings.py",
382382
press=["enter", "tab", "h", "i", "tab", "enter"],
383383
)
384+
385+
386+
def test_dock_scroll(snap_compare):
387+
# https://github.com/Textualize/textual/issues/2188
388+
assert snap_compare(SNAPSHOT_APPS_DIR / "dock_scroll.py", terminal_size=(80, 25))

0 commit comments

Comments
 (0)