mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
optimize from_union add docstrings
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
scrollbar-size-vertical: 2;
|
scrollbar-size-vertical: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
*:hover {
|
/* *:hover {
|
||||||
tint: red 30%;
|
tint: red 30%;
|
||||||
}
|
} */
|
||||||
|
|
||||||
App > Screen {
|
App > Screen {
|
||||||
layout: dock;
|
layout: dock;
|
||||||
|
|||||||
@@ -186,6 +186,8 @@ class Border:
|
|||||||
if has_bottom and lines:
|
if has_bottom and lines:
|
||||||
lines.pop(-1)
|
lines.pop(-1)
|
||||||
|
|
||||||
|
# TODO: Divide is probably quite inefficient here,
|
||||||
|
# It could be much faster for the specific case of one off the start end end
|
||||||
divide = Segment.divide
|
divide = Segment.divide
|
||||||
if has_left and has_right:
|
if has_left and has_right:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
from operator import itemgetter, attrgetter
|
||||||
from typing import Any, Collection, NamedTuple, Tuple, TypeVar, Union, cast
|
from typing import Any, Collection, NamedTuple, Tuple, TypeVar, Union, cast
|
||||||
|
|
||||||
if sys.version_info >= (3, 10):
|
if sys.version_info >= (3, 10):
|
||||||
@@ -93,7 +94,10 @@ class Offset(NamedTuple):
|
|||||||
"""
|
"""
|
||||||
x1, y1 = self
|
x1, y1 = self
|
||||||
x2, y2 = destination
|
x2, y2 = destination
|
||||||
return Offset(int(x1 + (x2 - x1) * factor), int((y1 + (y2 - y1) * factor)))
|
return Offset(
|
||||||
|
int(x1 + (x2 - x1) * factor),
|
||||||
|
int(y1 + (y2 - y1) * factor),
|
||||||
|
)
|
||||||
|
|
||||||
def get_distance_to(self, other: Offset) -> float:
|
def get_distance_to(self, other: Offset) -> float:
|
||||||
"""Get the distance to another offset.
|
"""Get the distance to another offset.
|
||||||
@@ -195,7 +199,14 @@ class Region(NamedTuple):
|
|||||||
height: int = 0
|
height: int = 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_union(cls, regions: Collection[Region]) -> Region:
|
def from_union(
|
||||||
|
cls,
|
||||||
|
regions: Collection[Region],
|
||||||
|
_get_x=itemgetter(0),
|
||||||
|
_get_y=itemgetter(1),
|
||||||
|
_get_right=attrgetter("right"),
|
||||||
|
_get_bottom=attrgetter("bottom"),
|
||||||
|
) -> Region:
|
||||||
"""Create a Region from the union of other regions.
|
"""Create a Region from the union of other regions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -206,10 +217,10 @@ class Region(NamedTuple):
|
|||||||
"""
|
"""
|
||||||
if not regions:
|
if not regions:
|
||||||
raise ValueError("At least one region expected")
|
raise ValueError("At least one region expected")
|
||||||
min_x = min([region.x for region in regions])
|
min_x = min(regions, key=_get_x).x
|
||||||
max_x = max([x + width for x, _y, width, _height in regions])
|
max_x = max(regions, key=_get_right).right
|
||||||
min_y = min([region.y for region in regions])
|
min_y = min(regions, key=_get_y).y
|
||||||
max_y = max([y + height for _x, y, _width, height in regions])
|
max_y = max(regions, key=_get_bottom).bottom
|
||||||
return cls(min_x, min_y, max_x - min_x, max_y - min_y)
|
return cls(min_x, min_y, max_x - min_x, max_y - min_y)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -428,14 +428,17 @@ class Widget(DOMNode):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _set_dirty(self, *regions: Region) -> None:
|
def _set_dirty(self, *regions: Region) -> None:
|
||||||
"""Set the Widget as 'dirty' (requiring re-render)."""
|
"""Set the Widget as 'dirty' (requiring re-paint).
|
||||||
|
|
||||||
# self._dirty_regions.clear()
|
Regions should be specified as positional args. If no regions are added, then
|
||||||
# # TODO: Does this need to be content region?
|
the entire widget will be considered dirty.
|
||||||
# self._dirty_regions.append(self.size.region)
|
|
||||||
|
Args:
|
||||||
|
*regions (Region): Regions which require a repaint.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
if regions:
|
if regions:
|
||||||
content_offset = self.content_offset
|
|
||||||
self._dirty_regions.update(regions)
|
self._dirty_regions.update(regions)
|
||||||
else:
|
else:
|
||||||
self._dirty_regions.clear()
|
self._dirty_regions.clear()
|
||||||
@@ -444,6 +447,11 @@ class Widget(DOMNode):
|
|||||||
self._dirty_regions.add(self.size.region)
|
self._dirty_regions.add(self.size.region)
|
||||||
|
|
||||||
def get_dirty_regions(self) -> Collection[Region]:
|
def get_dirty_regions(self) -> Collection[Region]:
|
||||||
|
"""Get regions which require a repaint.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Collection[Region]: Regions to repaint.
|
||||||
|
"""
|
||||||
regions = self._dirty_regions.copy()
|
regions = self._dirty_regions.copy()
|
||||||
return regions
|
return regions
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user