fix drag polling during overlay updates

This commit is contained in:
2026-05-23 10:31:27 +02:00
parent 815d8a2d88
commit d0ba8c4218
3 changed files with 56 additions and 1 deletions

View File

@@ -196,6 +196,31 @@ def handle_mouse_wheel(
)
def update_drag_from_button_state(
state: MapState,
*,
mouse_pos: tuple[float, float],
hit_rect: HitRect,
is_down: bool,
) -> None:
"""Poll left-button state and keep drag interaction moving."""
with state.lock:
active_drag = state.interaction.active_drag
if not is_down:
if active_drag:
handle_mouse_release(state)
return
if active_drag:
handle_mouse_drag(state, mouse_pos)
return
if hit_rect.contains(mouse_pos[0], mouse_pos[1]):
handle_mouse_down(state, mouse_pos, hit_rect)
def wheel_delta_from_app_data(app_data: Any) -> float:
"""Normalize Dear PyGui mouse wheel callback data."""

View File

@@ -8,7 +8,7 @@ from typing import Any
from .commands import CommandKind, MapCommand
from .draw_layers import DrawLayerTags, clear_draw_layer, ensure_draw_layers
from .interaction import HitRect, calculate_hit_rect
from .interaction import HitRect, calculate_hit_rect, update_drag_from_button_state
from .overlays import MarkerOverlay, Overlay, PolylineOverlay, TrajectoryOverlay
from .projection import latlon_to_world
from .sizing import SizeMeasurement, apply_size_measurement
@@ -53,6 +53,7 @@ class MapRenderer:
commands = drain_renderer_commands(self.state)
self.last_drained_commands = tuple(commands)
self._update_size_from_dpg()
self._poll_mouse_drag()
with self.state.lock:
dirty = self.state.dirty
@@ -132,6 +133,21 @@ class MapRenderer:
with self.state.lock:
self.last_hit_rect = calculate_hit_rect(self.state, (draw_pos[0], draw_pos[1]))
def _poll_mouse_drag(self) -> None:
if self.last_hit_rect is None:
return
try:
is_down = bool(self._dpg.is_mouse_button_down(self._dpg.mvMouseButton_Left))
mouse_pos = self._dpg.get_mouse_pos(local=False)
except Exception:
return
update_drag_from_button_state(
self.state,
mouse_pos=(float(mouse_pos[0]), float(mouse_pos[1])),
hit_rect=self.last_hit_rect,
is_down=is_down,
)
def _measure_child_content(self) -> tuple[int, int]:
try:
width, height = self._dpg.get_item_rect_size(self.state.child_window_tag)