mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-11-04 07:01:04 +01:00 
			
		
		
		
	Add user-facing IsPopupOpen function
This commit is contained in:
		
							
								
								
									
										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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user