From e14c7e55102d78eef0d94516262dc0a0819a25c5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 18 Mar 2015 13:15:11 +0000 Subject: [PATCH] ShowTestWindow(): Added simple dragging widget example. --- imgui.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index c74f0e98d..76e998d95 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9376,6 +9376,26 @@ void ImGui::ShowTestWindow(bool* opened) ImGui::Indent(); ImGui::TreePop(); } + + if (ImGui::TreeNode("Dragging")) + { + // You can use ImGui::GetItemActiveDragDelta() to query for the dragged amount on any widget. + static ImVec2 value(0.0f, 0.0f); + ImGui::Button("Drag Me"); + if (ImGui::IsItemActive()) + { + value = ImGui::GetItemActiveDragDelta(); + //ImGui::SetTooltip("Delta: %.1f, %.1f", value.x, value.y); + + // Draw a line between the button and the mouse cursor + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->PushClipRectFullScreen(); + draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 2.0f); + draw_list->PopClipRect(); + } + ImGui::SameLine(); ImGui::Text("Value: %.1f, %.1f", value.x, value.y); + ImGui::TreePop(); + } } if (ImGui::CollapsingHeader("Graphs widgets"))