Added BeginPopupContextItem() / BeginPopupContextWindow() (#126)
This commit is contained in:
parent
5b0861768e
commit
938528e5ee
20
imgui.cpp
20
imgui.cpp
@ -3171,6 +3171,21 @@ void ImGui::EndPopup()
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, int button)
|
||||
{
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(button))
|
||||
ImGui::OpenPopup(str_id);
|
||||
return ImGui::BeginPopup(str_id);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, bool void_only, int button)
|
||||
{
|
||||
if (ImGui::IsMouseHoveringWindow() && ImGui::IsMouseClicked(button))
|
||||
if (!void_only || !ImGui::IsAnyItemHovered())
|
||||
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;
|
||||
@ -11694,6 +11709,11 @@ struct ExampleAppConsole
|
||||
// NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
|
||||
// If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
|
||||
ImGui::BeginChild("ScrollingRegion", ImVec2(0,-ImGui::GetTextLineHeightWithSpacing()*2));
|
||||
if (ImGui::BeginPopupContextWindow())
|
||||
{
|
||||
if (ImGui::Selectable("Clear")) ClearLog();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
|
||||
for (size_t i = 0; i < Items.size(); i++)
|
||||
{
|
||||
|
2
imgui.h
2
imgui.h
@ -169,6 +169,8 @@ 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(const char* str_id = "window_context_menu", bool void_only = false, int button = 1); // open popup when clicked on current 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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user