From 580edb4f4b189ba7b4b5648aa7fb99b8a80efd7c Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 6 May 2022 16:39:03 +0100 Subject: [PATCH] comment and tests --- src/textual/widget.py | 3 +++ tests/test_geometry.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/textual/widget.py b/src/textual/widget.py index 96b02a10c..ece019f25 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -423,8 +423,11 @@ class Widget(DOMNode): container_region = self.content_region + container_geometry.region.origin if widget_region in container_region: + # Widget is visible, nothing to do return False + # We can either scroll so the widget is at the top of the container, or so that + # it is at the bottom. We want to pick which has the shortest distance top_delta = widget_region.origin - container_region.origin bottom_delta = widget_region.origin - ( container_region.origin diff --git a/tests/test_geometry.py b/tests/test_geometry.py index 72d5de462..26b7a330b 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -132,6 +132,18 @@ def test_region_origin(): assert Region(1, 2, 3, 4).origin == Offset(1, 2) +def test_region_bottom_left(): + assert Region(1, 2, 3, 4).bottom_left == Offset(1, 6) + + +def test_region_top_right(): + assert Region(1, 2, 3, 4).top_right == Offset(4, 2) + + +def test_region_bottom_right(): + assert Region(1, 2, 3, 4).bottom_right == Offset(4, 6) + + def test_region_add(): assert Region(1, 2, 3, 4) + (10, 20) == Region(11, 22, 3, 4) with pytest.raises(TypeError):