fix: Correct canvas mouse position tracking and add regression tests

This commit is contained in:
scawful
2025-10-10 13:37:08 -04:00
parent d894434495
commit 5cc650053d
3 changed files with 348 additions and 25 deletions

View File

@@ -411,6 +411,15 @@ void Canvas::DrawBackground(ImVec2 canvas_size) {
ImGui::InvisibleButton(canvas_id_.c_str(), scaled_size, kMouseFlags);
// CRITICAL FIX: Always update hover mouse position when hovering over canvas
// This fixes the regression where CheckForCurrentMap() couldn't track hover
if (IsItemHovered()) {
const ImGuiIO& io = GetIO();
const ImVec2 origin(canvas_p0_.x + scrolling_.x, canvas_p0_.y + scrolling_.y);
const ImVec2 mouse_pos(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
mouse_pos_in_canvas_ = mouse_pos;
}
if (config_.is_draggable && IsItemHovered()) {
const ImGuiIO& io = GetIO();
const bool is_active = IsItemActive(); // Held