-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Update InputFloat value with mouse wheel #4207
Comments
Note that this is a completely custom backend implementation. |
Hello, Not so long ago we formalized this with an imgui_internal.h function called 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;
}
}
} I would be interested in feedback and further example to figure out if this is a viable design to expose into the public API. |
Thanks! Sticking with const bool rv = ImGui::InputFloat( label, v, 0.0f, 0.0f, format, flags );
ImGui::SetItemUsingMouseWheel();
if( !ImGui::IsItemHovered() ) return rv;
float wheel = ImGui::GetIO().MouseWheel;
if( wheel )
{
if( ImGui::IsItemActive() )
{
ImGui::ClearActiveID();
}
else
{
*v += wheel * scrolStep;
}
}
// [...]
return rv; And it works just as expected -- prevents window from scrolling when the value is modified with mouse wheel. |
Good to hear! Closing this. |
So far, this is working well in my use cases. I ended up wrapping the widgets that I want to interact with the mouse wheel up in custom functions, and am using Working great so far. Would vote to have this exposed in the public API. 👍 |
I just upgraded my codebase to I see this in
But I'm not really finding any details on what the current mechanism is to support this functionality? |
Err, you literally pasted the answer to your question? |
I get that. Is this functionality stable, even if the naming keeps changing? |
Everything in imgui_internal.h is technically not guaranteed to be stable, but |
@ocornut sorry for bugging you for a century old and closed issue. Basically I am trying to do what this issue is talking about but in C#. :) |
It will be progressively be made public when the API has been used enough.
I think you should ask for your C# bindings to allow access to imgui_internal too.
|
Hi, |
Should probably check that the mouse moving window lock is disabled before claiming ownership. Will try to test this. |
Hi again, |
Version/Branch of Dear ImGui:
Version: 1.83
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: SDL2 + Vulkan
Compiler: MSVC 16.9
Operating System: Windows 10
My Issue/Question:
I am trying to allow to increase or decrease
InputFloat
field value by scrolling mouse wheel while the field is hovered by mouse cursor. I managed to do so (see below for my provided example). However, when the window has vertical scrollbar my solution works only when the window scroll is at its limits, e.g. when the window is scrolled to the top, value in the hovered field can only be increased with the mouse wheel -- scrolling the mouse wheel down causes the window to scroll down and the value remains unchanged (note that when the widget is "active" it is deactivated at the first mouse wheel action, otherwise the value is changed only temporarily -- for one frame).Could someone give me some pointers on how to proceed from here?
Screenshots/Video
Standalone, minimal, complete and verifiable example: (see #2261)
The text was updated successfully, but these errors were encountered: