step 3: add widget shell sizing and frame pump
This commit is contained in:
@@ -1 +1,36 @@
|
||||
"""Map interaction state and handlers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .sizing import effective_draw_size
|
||||
from .state import MapState
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class HitRect:
|
||||
"""Screen-space rectangle used for map interaction tests."""
|
||||
|
||||
x: float
|
||||
y: float
|
||||
width: float
|
||||
height: float
|
||||
|
||||
@property
|
||||
def right(self) -> float:
|
||||
return self.x + self.width
|
||||
|
||||
@property
|
||||
def bottom(self) -> float:
|
||||
return self.y + self.height
|
||||
|
||||
def contains(self, x: float, y: float) -> bool:
|
||||
return self.x <= x <= self.right and self.y <= y <= self.bottom
|
||||
|
||||
|
||||
def calculate_hit_rect(state: MapState, drawlist_pos: tuple[float, float]) -> HitRect:
|
||||
"""Return the map interaction rectangle for a drawlist position."""
|
||||
|
||||
width, height = effective_draw_size(state)
|
||||
return HitRect(float(drawlist_pos[0]), float(drawlist_pos[1]), float(width), float(height))
|
||||
|
||||
Reference in New Issue
Block a user