mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
geometry refinements
This commit is contained in:
@@ -119,15 +119,19 @@ class Size(NamedTuple):
|
|||||||
width, height = self
|
width, height = self
|
||||||
return Region(0, 0, width, height)
|
return Region(0, 0, width, height)
|
||||||
|
|
||||||
def __add__(self, other: tuple[int, int]) -> Size:
|
def __add__(self, other: object) -> Size:
|
||||||
width, height = self
|
if isinstance(other, tuple):
|
||||||
width2, height2 = other
|
width, height = self
|
||||||
return Size(width + width2, height + height2)
|
width2, height2 = other
|
||||||
|
return Size(width + width2, height + height2)
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
def __sub__(self, other: tuple[int, int]) -> Size:
|
def __sub__(self, other: object) -> Size:
|
||||||
width, height = self
|
if isinstance(other, tuple):
|
||||||
width2, height2 = other
|
width, height = self
|
||||||
return Size(width - width2, height - height2)
|
width2, height2 = other
|
||||||
|
return Size(width - width2, height - height2)
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
def contains(self, x: int, y: int) -> bool:
|
def contains(self, x: int, y: int) -> bool:
|
||||||
"""Check if a point is in the size.
|
"""Check if a point is in the size.
|
||||||
@@ -274,14 +278,14 @@ class Region(NamedTuple):
|
|||||||
"""A range object for Y coordinates"""
|
"""A range object for Y coordinates"""
|
||||||
return range(self.y, self.y + self.height)
|
return range(self.y, self.y + self.height)
|
||||||
|
|
||||||
def __add__(self, other: Any) -> Region:
|
def __add__(self, other: object) -> Region:
|
||||||
if isinstance(other, tuple):
|
if isinstance(other, tuple):
|
||||||
ox, oy = other
|
ox, oy = other
|
||||||
x, y, width, height = self
|
x, y, width, height = self
|
||||||
return Region(x + ox, y + oy, width, height)
|
return Region(x + ox, y + oy, width, height)
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
|
|
||||||
def __sub__(self, other: Any) -> Region:
|
def __sub__(self, other: object) -> Region:
|
||||||
if isinstance(other, tuple):
|
if isinstance(other, tuple):
|
||||||
ox, oy = other
|
ox, oy = other
|
||||||
x, y, width, height = self
|
x, y, width, height = self
|
||||||
|
|||||||
Reference in New Issue
Block a user