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

slider - make mouse wheel control sliders #3281

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

Conversation

phweyland
Copy link

vkdt is a project which uses imgui. This a darktable similar project whose the first aim is to be faster. But you probably know.
Trying to help at this I think it would be a great addition to allow the mouse wheel to control the silders.
Adapting the ImGuiInputSource_Nav case to mouse wheel increments gave me interesting results.

However I've seen a first side effect when the window is scrollable. This property not being limited to scrollbar region the window contents moves before the hovered slider. What would be the correct way to fix that, if it could exist ?
If this is something you would agree with, the same principle could be applied for other widgets as well.

Thanks for reading. Your comments, whatever they can be, are welcome.
Philippe

@ocornut
Copy link
Owner

ocornut commented Jun 8, 2021

Hello @phweyland,
Sorry for late answer.
Last december we formalized a solution for this problem with an imgui_internal.h function called SetItemUsingMouseWheel() (see #2891)

ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::SetItemUsingMouseWheel();
if (ImGui::IsItemHovered())
{
    float wheel = ImGui::GetIO().MouseWheel;
    if (wheel)
    {
        if (ImGui::IsItemActive())
        {
            ImGui::ClearActiveID();
        }
        else
        {
            f += wheel;
        }
    }
}

Note that SetItemUsingMouseWheel() does two very simple things, and an internal widget could perfectly do either of those thing separately, and by poking into internal api if needed.

The more difficult question is to come up with a design to make this sort of features available by default in stock sliders. As you can see in the example above, it is currently already possible to do it from "outside" but I agree it would be nice if we add a way to add that support into sliders/drags (now that they have flags it may be possible).

Whether it comes as a flag on a per-instance basis or a is more global type of flags would make an important difference and is not an easy question to answer. Among other things we have to design around the idea that dear imgui code can be shared among apps and reused outside of its initial context and that has an effect on design.

@ocornut ocornut force-pushed the master branch 2 times, most recently from 0c1e5bd to bb6a60b Compare August 27, 2021 19:10
@ocornut ocornut force-pushed the master branch 2 times, most recently from 8b83e0a to d735066 Compare December 13, 2021 11:31
@ocornut ocornut force-pushed the master branch 2 times, most recently from b3b85d8 to 0755767 Compare January 17, 2022 14:21
@ocornut ocornut force-pushed the master branch 3 times, most recently from c817acb to 8d39063 Compare February 15, 2022 16:25
@phweyland phweyland force-pushed the slider-mousewheel branch from ea8c585 to 35802d1 Compare June 4, 2022 13:04
@phweyland
Copy link
Author

Hello @ocornut ... sorry for the late answer as well. :)
Not sure I've understood all the details of your above example (ClearActiveId()...), but here is an update of the PR. The original issue has gone with the use of SetItemUsingMouseWheel().
I've added a new flag to make the slider scrollable.
I would have liked to allow moving values outside the slider's limits but there is conflict with some routines (ScaleRatioFromValueT()) so I've kept the current behavior.
Any comment is welcome.

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.

2 participants