Skip to content

Commit

Permalink
BeginPopupContextWindow() in_empty_space_only -> !also_over_items (#126
Browse files Browse the repository at this point in the history
…)+ comments

Sorry if you used this parameter already.
  • Loading branch information
ocornut committed May 31, 2015
1 parent bda0269 commit 374d160
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3180,26 +3180,26 @@ void ImGui::EndPopup()
ImGui::PopStyleVar();
}

bool ImGui::BeginPopupContextItem(const char* str_id, int button)
bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
{
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(button))
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(mouse_button))
ImGui::OpenPopup(str_id);
return ImGui::BeginPopup(str_id);
}

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

bool ImGui::BeginPopupContextVoid(const char* str_id, int button)
bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
{
if (!str_id) str_id = "void_context_menu";
if (!ImGui::IsMouseHoveringAnyWindow() && ImGui::IsMouseClicked(button))
if (!ImGui::IsMouseHoveringAnyWindow() && ImGui::IsMouseClicked(mouse_button))
ImGui::OpenPopup(str_id);
return ImGui::BeginPopup(str_id);
}
Expand Down
8 changes: 4 additions & 4 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ namespace ImGui
// Popup
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_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 bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // open and begin popup when clicked on last item
IMGUI_API bool BeginPopupContextWindow(bool also_over_items = true, const char* str_id = NULL, int mouse_button = 1); // open and begin popup when clicked on current window
IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // open and begin 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 Expand Up @@ -315,7 +315,7 @@ namespace ImGui
IMGUI_API void EndMenuBar();
IMGUI_API bool BeginMenu(const char* label, bool enabled = true); // create a sub-menu entry. only call EndMenu() if this returns true!
IMGUI_API void EndMenu();
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui
IMGUI_API bool MenuItem(const char* label, const char* shortcut = NULL, bool selected = false, bool enabled = true); // return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment
IMGUI_API bool MenuItem(const char* label, const char* shortcut, bool* p_selected, bool enabled = true); // return true when activated + toggle (*p_selected) if p_selected != NULL

// Widgets: Value() Helpers. Output single value in "name: value" format (tip: freely declare more in your code to handle your types. you can add functions to the ImGui namespace)
Expand Down

0 comments on commit 374d160

Please sign in to comment.