From 9f006bb770e2d80132c1bf6c6fbf9efd6bf5ab8d Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 17 May 2022 14:32:15 +0100 Subject: [PATCH] docstringd and comments --- src/textual/_compositor.py | 4 +++- src/textual/geometry.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/textual/_compositor.py b/src/textual/_compositor.py index a49843808..4e054a0db 100644 --- a/src/textual/_compositor.py +++ b/src/textual/_compositor.py @@ -63,6 +63,7 @@ class MapGeometry(NamedTuple): return self.clip.intersection(self.region) +# Maps a widget on to its geometry (information that describes its position in the composition) CompositorMap: TypeAlias = "dict[Widget, MapGeometry]" @@ -171,10 +172,11 @@ class Compositor: Iterable[tuple[int, int, int]]: Yields tuples of (Y, X1, X2) """ inline_ranges: dict[int, list[tuple[int, int]]] = {} + setdefault = inline_ranges.setdefault for region_x, region_y, width, height in regions: span = (region_x, region_x + width) for y in range(region_y, region_y + height): - inline_ranges.setdefault(y, []).append(span) + setdefault(y, []).append(span) for y, ranges in sorted(inline_ranges.items()): if len(ranges) == 1: diff --git a/src/textual/geometry.py b/src/textual/geometry.py index 9e4480306..2fab41600 100644 --- a/src/textual/geometry.py +++ b/src/textual/geometry.py @@ -484,13 +484,13 @@ class Region(NamedTuple): ) def intersection(self, region: Region) -> Region: - """Get that covers both regions. + """Get the overlapping portion of the two regions. Args: region (Region): A region that overlaps this region. Returns: - Region: A new region that fits within ``region``. + Region: A new region that covers when the two regions overlap. """ # Unrolled because this method is used a lot x1, y1, w1, h1 = self @@ -511,10 +511,10 @@ class Region(NamedTuple): """Get a new region that contains both regions. Args: - region (Region): [description] + region (Region): Another region. Returns: - Region: [description] + Region: An optimally sized region to cover both regions. """ x1, y1, x2, y2 = self.corners ox1, oy1, ox2, oy2 = region.corners