Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power save mode. Allow user call RequestRedraw to redraw a new frame. #5140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ForrestFeng
Copy link

This is a new try inspired by the pull request of #5116.

This new approach allows the user to choose which mode to use by specifying the timeout.

To tryout, please set the timeout value to -1 and open the Tools->Matics/Debugger to see how many frames are drawed when you interact with the demo.

image

Sample of code in the file of main.cpp to enable/disable power save. The default timeout value is 0 which keeps current ImGui no blocking behavior. Users can change it as needed.

   while (!glfwWindowShouldClose(window))
   {
        // wait and poll event
        // timeout:
        //  0 process event immediatly, not blocking
        // -1 wait for ever untill an event comes
        // positive number wait untill timedout or event comes
        // call ImGui::RequestRedraw to awake waiting of this function. Return 0 to signel a quict event.
        int timeout = 0;
        ImGui::WaitAndPollEvents(timeout);

       ...
    }

This PR also allows users to request a redraw on demand. For example, the Widgets/Plotting/ProgressBar animation calls this ImGui::RequestRedraw(ImGuiRedrawFlags_Everything) to animate the progress bar change.

        // Animate a simple progress bar
        IMGUI_DEMO_MARKER("Widgets/Plotting/ProgressBar");
        static float progress = 0.0f, progress_dir = 1.0f;
        if (animate)
        {
            progress += progress_dir * 0.4f * ImGui::GetIO().DeltaTime;
            if (progress >= +1.1f) { progress = +1.1f; progress_dir *= -1.0f; }
            if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; }
            // in power save mode when animate is enabled and, request redraw a new frame to show animation
            ImGui::RequestRedraw(ImGuiRedrawFlags_Everything);
        }

image

ImGuiRedrawFlags is an enum currently only implemented the redraw for everything. We can implement redraw for specific window or region of a window in the future.

Currently, only tested on Windows works well for all backends. Any feedback or suggestions on Linux and Mac are welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants