mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix for spatial calculation
This commit is contained in:
@@ -450,7 +450,7 @@ class Compositor:
|
|||||||
|
|
||||||
if visible_only:
|
if visible_only:
|
||||||
placements = arrange_result.get_visible_placements(
|
placements = arrange_result.get_visible_placements(
|
||||||
widget.size.region + widget.scroll_offset
|
container_size.region + widget.scroll_offset
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
placements = arrange_result.placements
|
placements = arrange_result.placements
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ class SpatialMap(Generic[ValueType]):
|
|||||||
Iterable of grid squares (tuple of 2 values).
|
Iterable of grid squares (tuple of 2 values).
|
||||||
"""
|
"""
|
||||||
x1, y1, width, height = region
|
x1, y1, width, height = region
|
||||||
x2 = x1 + width
|
x2 = x1 + width - 1
|
||||||
y2 = y1 + height
|
y2 = y1 + height - 1
|
||||||
grid_width, grid_height = self._grid_size
|
grid_width, grid_height = self._grid_size
|
||||||
|
|
||||||
return product(
|
return product(
|
||||||
range(x1 // grid_width, 1 + x2 // grid_width),
|
range(x1 // grid_width, x2 // grid_width + 1),
|
||||||
range(y1 // grid_height, 1 + y2 // grid_height),
|
range(y1 // grid_height, y2 // grid_height + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
def insert(
|
def insert(
|
||||||
|
|||||||
@@ -1,8 +1,33 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from textual._spatial_map import SpatialMap
|
from textual._spatial_map import SpatialMap
|
||||||
from textual.geometry import Region
|
from textual.geometry import Region
|
||||||
|
|
||||||
|
|
||||||
def test_region_to_grid():
|
@pytest.mark.parametrize(
|
||||||
spatial_map = SpatialMap()
|
"region,grid",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
Region(0, 0, 10, 10),
|
||||||
|
[
|
||||||
|
(0, 0),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Region(0, 0, 11, 11),
|
||||||
|
[(0, 0), (0, 1), (1, 0), (1, 1)],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Region(5, 5, 15, 3),
|
||||||
|
[(0, 0), (1, 0)],
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Region(5, 5, 2, 15),
|
||||||
|
[(0, 0), (0, 1)],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_region_to_grid(region, grid):
|
||||||
|
spatial_map = SpatialMap(10, 10)
|
||||||
|
|
||||||
assert list(spatial_map._region_to_grid(Region(0, 0, 10, 10))) == [(0, 0)]
|
assert list(spatial_map._region_to_grid(region)) == grid
|
||||||
|
|||||||
Reference in New Issue
Block a user