fix(input): dispatch hover-exit when the cursor leaves the window
closes #363 Hover was driven exclusively by sf::Event::MouseMoved -> PyScene::do_mouse_hover. Nothing anywhere handled sf::Event::MouseLeft, so when the cursor left the window while over a drawable, no further MouseMoved arrived and the hover state simply froze: on_exit / on_cell_exit never fired, and Grid.hovered_cell kept reporting a cell the mouse was nowhere near. Any hover-driven affordance (tile highlight, tooltip, range preview) stayed stranded in its hovered visual until the player re-entered the window AND crossed a boundary. Pre-existing gap in the input layer -- it hit Frame.on_exit too. #355 only made it observable, by giving grids hover callbacks that could get stuck. The fix reuses the machinery rather than adding a parallel teardown path. do_mouse_hover's walk becomes dispatch_hover(pos, in_window); a window-leave is just that walk with hit_allowed=false at the root, which is precisely "the mouse is over nothing": every hovered drawable takes its ordinary exit path, and none can enter. So grid cells, frames, and grid overlay children all clear through the code that already knows how to clear them. sf::Event::MouseLeft carries no coordinates, so exit callbacks get the last position seen by do_mouse_hover (the convention the DOM's mouseleave uses). There is no more recent position, and inventing one would be a lie. All three backends feed this: desktop SFML emits MouseLeft natively, SDL2Renderer already translated SDL_WINDOWEVENT_LEAVE to it (and had nobody listening), and headless reaches it via the new automation.mouseLeave(), which takes no position for the same reason the event carries none. Test asserts the cell exit fires, hovered_cell goes None, a redundant leave does not double-fire, and re-entering the SAME cell fires on_cell_enter again -- that last one is what distinguishes a real clear from a faked one. api_surface golden re-baselined: +1 line, automation.mouseLeave. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
461dcf7f29
commit
4bb1966b97
8 changed files with 205 additions and 3 deletions
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue