mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-03 21:59:15 +08:00
Add user-facing IsPopupOpen function
This commit is contained in:
parent
43e6c46c8d
commit
32dbe836d0
28
imgui.cpp
28
imgui.cpp
@ -687,7 +687,7 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_
|
||||
static void CloseInactivePopups();
|
||||
static void ClosePopupToLevel(int remaining);
|
||||
static void ClosePopup(ImGuiID id);
|
||||
static bool IsPopupOpen(ImGuiID id);
|
||||
static bool IsPopupIdOpen(ImGuiID id);
|
||||
static ImGuiWindow* GetFrontMostModalRootWindow();
|
||||
static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, int* last_dir, const ImRect& rect_to_avoid);
|
||||
|
||||
@ -3367,7 +3367,7 @@ void ImGui::EndTooltip()
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static bool IsPopupOpen(ImGuiID id)
|
||||
static bool IsPopupIdOpen(ImGuiID id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
return g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].PopupId == id;
|
||||
@ -3451,7 +3451,7 @@ static void ClosePopupToLevel(int remaining)
|
||||
|
||||
static void ClosePopup(ImGuiID id)
|
||||
{
|
||||
if (!IsPopupOpen(id))
|
||||
if (!IsPopupIdOpen(id))
|
||||
return;
|
||||
ImGuiContext& g = *GImGui;
|
||||
ClosePopupToLevel(g.OpenPopupStack.Size - 1);
|
||||
@ -3481,7 +3481,7 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
const ImGuiID id = window->GetID(str_id);
|
||||
if (!IsPopupOpen(id))
|
||||
if (!IsPopupIdOpen(id))
|
||||
{
|
||||
ClearSetNextWindowData(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
@ -3515,12 +3515,20 @@ bool ImGui::BeginPopup(const char* str_id)
|
||||
return BeginPopupEx(str_id, ImGuiWindowFlags_ShowBorders);
|
||||
}
|
||||
|
||||
bool ImGui::IsPopupOpen(const char* str_id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
const ImGuiID id = window->GetID(str_id);
|
||||
return IsPopupIdOpen(id);
|
||||
}
|
||||
|
||||
bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags extra_flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
const ImGuiID id = window->GetID(name);
|
||||
if (!IsPopupOpen(id))
|
||||
if (!IsPopupIdOpen(id))
|
||||
{
|
||||
ClearSetNextWindowData(); // We behave like Begin() and need to consume those values
|
||||
return false;
|
||||
@ -8415,7 +8423,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
|
||||
|
||||
const float arrow_size = (g.FontSize + style.FramePadding.x * 2.0f);
|
||||
const bool hovered = IsHovered(frame_bb, id);
|
||||
bool popup_open = IsPopupOpen(id);
|
||||
bool popup_open = IsPopupIdOpen(id);
|
||||
bool popup_opened_now = false;
|
||||
|
||||
const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
|
||||
@ -8439,7 +8447,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
|
||||
if (g.IO.MouseClicked[0])
|
||||
{
|
||||
SetActiveID(0);
|
||||
if (IsPopupOpen(id))
|
||||
if (IsPopupIdOpen(id))
|
||||
{
|
||||
ClosePopup(id);
|
||||
}
|
||||
@ -8453,7 +8461,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
|
||||
}
|
||||
|
||||
bool value_changed = false;
|
||||
if (IsPopupOpen(id))
|
||||
if (IsPopupIdOpen(id))
|
||||
{
|
||||
// Size default to hold ~7 items
|
||||
if (height_in_items < 0)
|
||||
@ -8799,7 +8807,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
ImGuiWindow* backed_focused_window = g.FocusedWindow;
|
||||
|
||||
bool pressed;
|
||||
bool menu_is_open = IsPopupOpen(id);
|
||||
bool menu_is_open = IsPopupIdOpen(id);
|
||||
bool menuset_is_open = !(window->Flags & ImGuiWindowFlags_Popup) && (g.OpenPopupStack.Size > g.CurrentPopupStack.Size && g.OpenPopupStack[g.CurrentPopupStack.Size].ParentMenuSet == window->GetID("##menus"));
|
||||
if (menuset_is_open)
|
||||
g.FocusedWindow = window;
|
||||
@ -8865,7 +8873,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
want_open = true;
|
||||
if (!enabled) // explicitly close if an open menu becomes disabled, facilitate users code a lot in pattern such as 'if (BeginMenu("options", has_object)) { ..use object.. }'
|
||||
want_close = true;
|
||||
if (want_close && IsPopupOpen(id))
|
||||
if (want_close && IsPopupIdOpen(id))
|
||||
ClosePopupToLevel(GImGui->CurrentPopupStack.Size);
|
||||
|
||||
if (!menu_is_open && want_open && g.OpenPopupStack.Size > g.CurrentPopupStack.Size)
|
||||
|
1
imgui.h
1
imgui.h
@ -371,6 +371,7 @@ namespace ImGui
|
||||
|
||||
// Popups
|
||||
IMGUI_API void OpenPopup(const char* str_id); // mark popup as open. 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).
|
||||
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 (can't close them 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!
|
||||
|
Loading…
Reference in New Issue
Block a user