Skip to content

Commit

Permalink
Added BeginPopupContextVoid() helper for completeness (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed May 27, 2015
1 parent 235cca4 commit dcc7df2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3185,13 +3185,21 @@ bool ImGui::BeginPopupContextItem(const char* str_id, int button)

bool ImGui::BeginPopupContextWindow(bool in_empty_space_only, const char* str_id, int button)
{
if (str_id == NULL) str_id = "window_context_menu";
if (!str_id) str_id = "window_context_menu";
if (ImGui::IsMouseHoveringWindow() && ImGui::IsMouseClicked(button))
if (!in_empty_space_only || !ImGui::IsAnyItemHovered())
ImGui::OpenPopup(str_id);
return ImGui::BeginPopup(str_id);
}

bool ImGui::BeginPopupContextVoid(const char* str_id, int button)
{
if (!str_id) str_id = "void_context_menu";
if (!ImGui::IsMouseHoveringAnyWindow() && ImGui::IsMouseClicked(button))
ImGui::OpenPopup(str_id);
return ImGui::BeginPopup(str_id);
}

bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags)
{
ImGuiState& g = *GImGui;
Expand Down
3 changes: 2 additions & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ namespace ImGui
IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level). close childs popups if any. will close popup when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
IMGUI_API bool BeginPopup(const char* str_id); // return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
IMGUI_API bool BeginPopupContextItem(const char* str_id, int button = 1); // open popup when clicked on last item
IMGUI_API bool BeginPopupContextWindow(bool in_void_only = false, const char* str_id = "window_context_menu", int button = 1); // open popup when clicked on current window
IMGUI_API bool BeginPopupContextWindow(bool in_empty_space_only = false, const char* str_id = "window_context_menu", int button = 1); // open popup when clicked on current window
IMGUI_API bool BeginPopupContextVoid(const char* str_id = "void_context_menu", int button = 1); // open popup when clicked in void (no window)
IMGUI_API void EndPopup();
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.

Expand Down

0 comments on commit dcc7df2

Please sign in to comment.