OpenPopupEx() internal tweaks to receive an ImGuiID, BeginPopupContextXXX shortening unnecessarily long identifier.
This commit is contained in:
parent
a9915681eb
commit
a85a14370b
20
imgui.cpp
20
imgui.cpp
@ -3400,11 +3400,10 @@ void ImGui::EndTooltip()
|
||||
// Popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
|
||||
// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
|
||||
// One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL)
|
||||
void ImGui::OpenPopupEx(const char* str_id, bool reopen_existing)
|
||||
void ImGui::OpenPopupEx(ImGuiID id, bool reopen_existing)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
ImGuiID id = window->GetID(str_id);
|
||||
int current_stack_size = g.CurrentPopupStack.Size;
|
||||
ImGuiPopupRef popup_ref = ImGuiPopupRef(id, window, window->GetID("##menus"), g.IO.MousePos); // Tagged as new ref because constructor sets Window to NULL (we are passing the ParentWindow info here)
|
||||
if (g.OpenPopupStack.Size < current_stack_size + 1)
|
||||
@ -3418,7 +3417,8 @@ void ImGui::OpenPopupEx(const char* str_id, bool reopen_existing)
|
||||
|
||||
void ImGui::OpenPopup(const char* str_id)
|
||||
{
|
||||
ImGui::OpenPopupEx(str_id, false);
|
||||
ImGuiContext& g = *GImGui;
|
||||
OpenPopupEx(g.CurrentWindow->GetID(str_id), false);
|
||||
}
|
||||
|
||||
static void CloseInactivePopups()
|
||||
@ -3494,6 +3494,7 @@ void ImGui::CloseCurrentPopup()
|
||||
|
||||
static inline void ClearSetNextWindowData()
|
||||
{
|
||||
// FIXME-OPT
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.SetNextWindowPosCond = g.SetNextWindowSizeCond = g.SetNextWindowContentSizeCond = g.SetNextWindowCollapsedCond = 0;
|
||||
g.SetNextWindowSizeConstraint = g.SetNextWindowFocus = false;
|
||||
@ -3538,6 +3539,7 @@ bool ImGui::BeginPopup(const char* str_id)
|
||||
return BeginPopupEx(g.CurrentWindow->GetID(str_id), ImGuiWindowFlags_ShowBorders);
|
||||
}
|
||||
|
||||
// FIXME
|
||||
bool ImGui::IsPopupOpen(ImGuiID id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -3590,31 +3592,31 @@ void ImGui::EndPopup()
|
||||
// 2. If you want right-clicking on the same item to reopen the popup at new location, use the same code replacing IsItemHovered() with IsItemHoveredRect()
|
||||
// and passing true to the OpenPopupEx().
|
||||
// Because: hovering an item in a window below the popup won't normally trigger is hovering behavior/coloring. The pattern of ignoring the fact that
|
||||
// the item isn't interactable (because it is blocked by the active popup) may useful in some situation when e.g. large canvas as one item, content of menu
|
||||
// the item can be interacted with (because it is blocked by the active popup) may useful in some situation when e.g. large canvas as one item, content of menu
|
||||
// driven by click position.
|
||||
bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
|
||||
{
|
||||
if (IsItemHovered() && IsMouseClicked(mouse_button))
|
||||
OpenPopupEx(str_id, false);
|
||||
OpenPopupEx(GImGui->CurrentWindow->GetID(str_id), false);
|
||||
return BeginPopup(str_id);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextWindow(const char* str_id, int mouse_button, bool also_over_items)
|
||||
{
|
||||
if (!str_id)
|
||||
str_id = "window_context_menu";
|
||||
str_id = "window_context";
|
||||
if (IsMouseHoveringWindow() && IsMouseClicked(mouse_button))
|
||||
if (also_over_items || !IsAnyItemHovered())
|
||||
OpenPopupEx(str_id, true);
|
||||
OpenPopupEx(GImGui->CurrentWindow->GetID(str_id), true);
|
||||
return BeginPopup(str_id);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
|
||||
{
|
||||
if (!str_id)
|
||||
str_id = "void_context_menu";
|
||||
str_id = "void_context";
|
||||
if (!IsMouseHoveringAnyWindow() && IsMouseClicked(mouse_button))
|
||||
OpenPopupEx(str_id, true);
|
||||
OpenPopupEx(GImGui->CurrentWindow->GetID(str_id), true);
|
||||
return BeginPopup(str_id);
|
||||
}
|
||||
|
||||
|
2
imgui.h
2
imgui.h
@ -382,13 +382,13 @@ namespace ImGui
|
||||
|
||||
// Popups
|
||||
IMGUI_API void OpenPopup(const char* str_id); // call to mark popup as open (don't call every frame!). popups are closed when user click outside, or if CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. By default, Selectable()/MenuItem() are calling CloseCurrentPopup(). Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
|
||||
IMGUI_API bool IsPopupOpen(const char* str_id); // return true if the popup is open
|
||||
IMGUI_API bool BeginPopup(const char* str_id); // return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returned true!
|
||||
IMGUI_API bool BeginPopupModal(const char* name, bool* p_open = NULL, ImGuiWindowFlags extra_flags = 0); // modal dialog (block interactions behind the modal window, can't close the modal window by clicking outside)
|
||||
IMGUI_API bool BeginPopupContextItem(const char* str_id, int mouse_button = 1); // helper to open and begin popup when clicked on last item. read comments in .cpp!
|
||||
IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, int mouse_button = 1, bool also_over_items = true); // helper to open and begin popup when clicked on current window.
|
||||
IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, int mouse_button = 1); // helper to open and begin popup when clicked in void (no window).
|
||||
IMGUI_API void EndPopup();
|
||||
IMGUI_API bool IsPopupOpen(const char* str_id); // return true if the popup is open
|
||||
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
|
||||
|
||||
// Logging: all text output from interface is redirected to tty/file/clipboard. By default, tree nodes are automatically opened during logging.
|
||||
|
@ -745,7 +745,7 @@ namespace ImGui
|
||||
IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);
|
||||
IMGUI_API float CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x);
|
||||
|
||||
IMGUI_API void OpenPopupEx(const char* str_id, bool reopen_existing);
|
||||
IMGUI_API void OpenPopupEx(ImGuiID id, bool reopen_existing);
|
||||
IMGUI_API bool IsPopupOpen(ImGuiID id);
|
||||
|
||||
// NB: All position are in absolute pixels coordinates (never using window coordinates internally)
|
||||
|
Loading…
Reference in New Issue
Block a user