From ac501102fc7524433c2343f2fa2cc47ea08f548e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 1 May 2016 17:43:17 +0200 Subject: [PATCH] Added IsItemClicked() helper (#581) --- imgui.cpp | 8 ++++++-- imgui.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7aff89cc..0c7ef495 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1722,8 +1722,7 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id) ImGuiWindow* window = GetCurrentWindow(); window->DC.LastItemID = id ? *id : 0; window->DC.LastItemRect = bb; - window->DC.LastItemHoveredAndUsable = false; - window->DC.LastItemHoveredRect = false; + window->DC.LastItemHoveredAndUsable = window->DC.LastItemHoveredRect = false; if (IsClippedEx(bb, id, false)) return false; @@ -3056,6 +3055,11 @@ bool ImGui::IsItemActive() return false; } +bool ImGui::IsItemClicked(int mouse_button) +{ + return IsMouseClicked(mouse_button) && IsItemHovered(); +} + bool ImGui::IsAnyItemHovered() { return GImGui->HoveredId != 0 || GImGui->HoveredIdPreviousFrame != 0; diff --git a/imgui.h b/imgui.h index 11b63b8f..7e0d9b54 100644 --- a/imgui.h +++ b/imgui.h @@ -378,6 +378,7 @@ namespace ImGui IMGUI_API bool IsItemHovered(); // was the last item hovered by mouse? IMGUI_API bool IsItemHoveredRect(); // was the last item hovered by mouse? even if another item is active or window is blocked by popup while we are hovering this IMGUI_API bool IsItemActive(); // was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false) + IMGUI_API bool IsItemClicked(int mouse_button = 0); // was the last item clicked? (e.g. button/node just clicked on) IMGUI_API bool IsItemVisible(); // was the last item visible? (aka not out of sight due to clipping/scrolling.) IMGUI_API bool IsAnyItemHovered(); IMGUI_API bool IsAnyItemActive();