浏览代码

Added context menu example on a DragFloat widget

ocornut 10 年之前
父节点
当前提交
90db64d4e3
共有 1 个文件被更改,包括 14 次插入1 次删除
  1. 14 1
      imgui.cpp

+ 14 - 1
imgui.cpp

@@ -10609,12 +10609,25 @@ void ImGui::ShowTestWindow(bool* opened)
             }
 
             if (ImGui::Button("Popup Menu.."))
+                ImGui::OpenPopup("popup from button");
+            if (ImGui::BeginPopup("popup from button"))
+            {
+                ShowExampleMenuFile();
+                ImGui::EndPopup();
+            }
+
+            static float value = 0.5f;
+            ImGui::PushItemWidth(100); ImGui::DragFloat("Context Menu", &value); ImGui::PopItemWidth();
+            if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(1))
                 ImGui::OpenPopup("context menu");
+            ImGui::SameLine(); ImGui::Text("<-- right-click");
             if (ImGui::BeginPopup("context menu"))
             {
-                ShowExampleMenuFile();
+                if (ImGui::Selectable("Set to zero")) value = 0.0f; 
+                if (ImGui::Selectable("Set to PI")) value = PI; 
                 ImGui::EndPopup();
             }
+
             ImGui::TreePop();
         }