ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.74k stars 10.17k forks source link

IsItemDeactivatedAfterEdit Interrupted By Modal Popup #5184

Open santorac opened 2 years ago

santorac commented 2 years ago

Version/Branch of Dear ImGui:

Version: v1.82 Branch: unknown

Back-end/Renderer/Compiler/OS

Back-ends: working within Open 3D Engine Compiler: Visual Studio 2019 Operating System: Windows 10

My Issue/Question:

I have a slider and only want to apply the changes after the slider is released, so I'm using IsItemDeactivatedAfterEdit(). If a modal popup is opened while the slider is being dragged, then the slider is deactivated when focus is lost, and IsItemDeactivatedAfterEdit() never returns true. I'd like IsItemDeactivatedAfterEdit() to return true either before the popup is opened (preferably) or after the popup is closed.

Screenshots/Video

https://user-images.githubusercontent.com/55155825/162859796-df7c5e94-4660-40b0-a8b3-4cd76aab245f.mp4

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)

Here is a snippet of test code to demonstrate the issue, place something like this in a per-frame tick function. If you drag and release the slider before the modal popup, then "Applied Count" will be incremented, and "Applied Value" will be updated to the slider value. If you hold the slider until the popup happens, then the value will not be applied.

        static float time = 0.0f;
        time += deltaTime;
        static float testValue = 0.0f;
        static float appliedValue = 0.0f;
        static int applyCounter = 0;
        static const char* modalPopupName = "Interruption";
        if (ImGui::Begin("TEST"))
        {
            ImGui::SliderFloat("Slider", &testValue, 0.0f, 1.0f);
            bool applyChanges = ImGui::IsItemDeactivatedAfterEdit();

            if (applyChanges)
            {
                applyCounter++;
                appliedValue = testValue;
            }

            ImGui::LabelText("Applied Count", "%d", applyCounter);
            ImGui::LabelText("Applied Value", "%f", appliedValue);

            if (time > 3.0f)
            {
                ImGui::OpenPopup(modalPopupName);

                if (ImGui::BeginPopupModal(modalPopupName))
                {
                    ImGui::Text("Interrupted!");
                    ImGui::EndPopup();
                }

                if (time > 4.0f)
                {
                    time = 0.0f;
                }
            }
        }
        ImGui::End();
ocornut commented 2 years ago

Thanks for reporting, I can confirm the issue. While not the same there's a little bit of overlap with #4714 (which I have a 90% fix for, but didn't finish it). I believe the solution for this (#5184) may lead t improving my solution for #4714.