Closed
Description
Hey Omar,
I've been working on a feature that required me to detect when the mouse was clicked and subsequently dragged. I wrote a small code sequence to help me detect this case:
static bool leftPressed = false, leftReleased = false, leftPrev = false, isDragging = false;
static int dragCount = 0;
ImGuiIO *io = &ImGui::GetIO();
leftPressed = !leftPrev && io->MouseDown[0];
leftReleased = leftPrev && !io->MouseDown[0];
leftPrev = io->MouseDown[0];
if (leftReleased)
{
printf("Left released!\n");
isDragging = false;
}
const float DRAG_RADIUS = 4.0f;
ImVec2 distFromClick(io->MouseClickedPos[0]);
distFromClick -= ImGui::GetMousePos();
if (!isDragging && io->MouseDown[0] && (((distFromClick.x * distFromClick.x) + (distFromClick.y * distFromClick.y)) > (DRAG_RADIUS * DRAG_RADIUS)))
{
printf("Started dragging!\n");
isDragging = true;
}
if (isDragging)
{
printf("Dragging %d\n", ++dragCount);
}
The issue I ran into was that this can detect double clicking as a drag if the mouse is moved quickly between each click (so that the drag threshold is exceeded).
I took a look at the code that sets the click positions
Lines 1829 to 1839 in ff5378b
For now, I work around this issue by keeping track of the click positions on my own.
-Dale Kim
Metadata
Assignees
Labels
No labels
Activity