Merge pull request #4719 from Textualize/fix-scroll-visible-with-margin

Fix for scroll visible
This commit is contained in:
Will McGugan
2024-07-10 14:08:54 +01:00
committed by GitHub
5 changed files with 262 additions and 61 deletions

View File

@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Fixed
- Fixed scroll_visible with margin https://github.com/Textualize/textual/pull/4719
## [0.72.0] - 2024-07-09
### Changed

View File

@@ -2781,6 +2781,8 @@ class Widget(DOMNode):
region = (
(
region.translate(-scroll_offset)
.translate(container.styles.margin.top_left)
.translate(container.styles.border.spacing.top_left)
.translate(-widget.scroll_offset)
.translate(container.virtual_region_with_margin.offset)
)

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll, Container
from textual.widgets import Button
class ScrollVisibleMargin(App):
CSS = """
Container {
height: auto;
margin-top: 8;
border: solid red;
}
"""
def compose(self) -> ComposeResult:
with VerticalScroll():
with Container():
for index in range(1, 51):
yield Button(f"Hello, world! ({index})", id=f"b{index}")
def key_x(self):
button_twenty = self.query_one("#b26")
button_twenty.scroll_visible()
app = ScrollVisibleMargin()
if __name__ == "__main__":
app.run()

View File

@@ -1300,7 +1300,12 @@ def test_option_list_scrolling_with_multiline_options(snap_compare):
# https://github.com/Textualize/textual/issues/4705
assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py", press=["up"])
def test_bindings_screen_overrides_show(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/4382"""
assert snap_compare(SNAPSHOT_APPS_DIR / "bindings_screen_overrides_show.py")
def test_scroll_visible_with_margin(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/2181"""
assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_visible_margin.py", press=["x"])