You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using ImPlot in my aplication and because often during scrolling plots are 'catching' mouse focus
(and scrolling ends, plot starts to zoom), I decided to add an option: use ctrl to zoom plot.
If it's disabled, then wheel on plot should zoom it, and wheel on window should scroll it.
If it's enabled, then wheel should scroll window no matter where cursor is, and wheel on plot should zoom it only if ctrl is pressed.
Aditionally, I handle ctrl+wheel case on window independently, and the scroll on window also could be custom-made, but it makes no difference. How am I supposed to handle these cases in proper fashion?
First, I disabled wheel handling in ImPlot:
ImPlot::GetInputMap().ZoomMod = 1 << 16; // btw. is there any value that will be safer?
(because of ImPlot's UpdateInput(ImPlotPlot& plot), section SCROLL INPUT: ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod)))
Then, I noticed that ImPlot::IsPlotHovered() is not always working (especially with custom drag from another widget),
and ImGuiHoveredFlags_AllowWhenBlockedByActiveItem could not be used with ImPlot::IsPlotHovered(),
so instead, in-between ImPlot begin-end I used:
if ((ImGui::GetIO().MouseWheel != 0.0f) && (need_ctrl == ImGui::GetIO().KeyCtrl) && !ImGui::GetIO().KeyShift)
In addition, I handle different kinds of zooms (and keys combinations) outside the ImPlot, and different kinds of scroll (default/smooth/etc).
I noticed that scroll behaves very odd. Whole variety of cases:
not working, then suddenly flushing the events when mouse leaves plot;
plot zooms, but window scrolls;
plot zooms only when mouse finish move after scroll in plot area;
only window scroll works.
After an investigation I realized that there is no 'consume the event / notify' mechanism and
I just(?) need to set ownership of the mousewheel, so after few experiments following combination worked:
if (!using_ctrl_for_plot_zoom)
{ ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, ImPlot::GetCurrentPlot()->ID); }
if (plot_zoomed_successfully)
{ ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, ImPlot::GetCurrentPlot()->ID); }
Still, no idea why the first condition is needed, and without it I get problems
mentioned above. Also, explicitly setting the window as a key owner didn't work.
First condition looks like this: if the ctrl-option is not set, plot gets the mousewheel always;
Very redundant.
I tried to follow/debug how ImGui handles mousewheel, but it's somehow problematic.
All I get is, that in NewFrame() readings are updated in UpdateMouseWheel,
and in the very same function, below remark // Mouse wheel scrolling: find target and apply
there is SetScrollY applied to the window.
It is unclear to me, how the flow finally looks like and how am I supposed to control it.
If the wheel readings are done at the beginning and instantly applied, then how am I supposed
to control it regarding the widgets?
Without altering the widgets and without the need to use anything from ImGui internal stuff.
No additional example code as it would need ImPlot and my questions are more like
about the proper way of handling stuff than reporting the issue (maybe there is no issue...).
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
The text was updated successfully, but these errors were encountered:
I'm using ImPlot in my aplication and because often during scrolling plots are 'catching' mouse focus
(and scrolling ends, plot starts to zoom)
XY Problem detected :) This could be improved in implot.
Since 26f14e0 we have a g.WheelingWindow field used for wheeling lock. Bhavior has been tweaked/improved since initial commit. I believe ImPlot should check that along is IsWindowHovered() when handling mouse wheel.
About the remaining of the post: you are asking too many things and partly asking about ImPlot codebase which is not mine. If you ask precise ImGui issues I will try to answer them. It would probably helped you if you displayed the state of various data on the screen while debugging.
ImPlot::GetInputMap().ZoomMod = 1 << 16; // btw. is there any value that will be safer?
Probably would need a way to disable zooming in ImPlot (e.g: ZoomRate == 0.0f), but only if that's the best way to achieve your result, and right now I am not sure.
Sorry for long pause, but I was dealing with so-called real life and my hobby had to wait.
Long story short: ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, ImPlot::GetCurrentPlot()->ID); wasn't always working as intended, especially when playing with mouse wheel (hand-made smooth scroll, etc);
The best behaviour I could get was that after ImGui noticed mouse scroll (and widget didn't) and moved the scrollbar / window content, event was triggered whenever the mouse cursor landed (by 'event was triggered' I mean: condition in ImPlot worked). So, when I had cursor hovering the ImPlot and used scroll, the window moved and plot was intact. But when I started from outside the plot and scrolled onto it, the plot noticed that there is mouse over (and is using the wheel).
The workaround was to completely disable scrolling window by mouse and do it manually (ImPlot is completely reworked anyway, but this problem also applies to other widgets).
However, when I read it now, it may sound like an XY problem, so all the more thanks for responding.
I'll be back with a more specific problem.
Version/Branch of Dear ImGui:
Version 1.90.1, Branch: master
Back-ends:
imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Windows 10 + MSVC 2022, VS 17.8.4
Full config/build information:
Details:
I'm using ImPlot in my aplication and because often during scrolling plots are 'catching' mouse focus
(and scrolling ends, plot starts to zoom), I decided to add an option: use ctrl to zoom plot.
Aditionally, I handle ctrl+wheel case on window independently, and the scroll on window also could be custom-made, but it makes no difference.
How am I supposed to handle these cases in proper fashion?
First, I disabled wheel handling in ImPlot:
ImPlot::GetInputMap().ZoomMod = 1 << 16; // btw. is there any value that will be safer?
(because of
ImPlot's UpdateInput(ImPlotPlot& plot)
, sectionSCROLL INPUT
:ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod))
)Then, I noticed that
ImPlot::IsPlotHovered()
is not always working (especially with custom drag from another widget),and
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem
could not be used withImPlot::IsPlotHovered()
,so instead, in-between ImPlot begin-end I used:
ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)
And finally I do the check:
if ((ImGui::GetIO().MouseWheel != 0.0f) && (need_ctrl == ImGui::GetIO().KeyCtrl) && !ImGui::GetIO().KeyShift)
In addition, I handle different kinds of zooms (and keys combinations) outside the ImPlot, and different kinds of scroll (default/smooth/etc).
I noticed that scroll behaves very odd. Whole variety of cases:
After an investigation I realized that there is no 'consume the event / notify' mechanism and
I just(?) need to set ownership of the mousewheel, so after few experiments following combination worked:
Still, no idea why the first condition is needed, and without it I get problems
mentioned above. Also, explicitly setting the window as a key owner didn't work.
First condition looks like this: if the ctrl-option is not set, plot gets the mousewheel always;
Very redundant.
I tried to follow/debug how ImGui handles mousewheel, but it's somehow problematic.
All I get is, that in
NewFrame()
readings are updated inUpdateMouseWheel
,and in the very same function, below remark
// Mouse wheel scrolling: find target and apply
there is SetScrollY applied to the window.
It is unclear to me, how the flow finally looks like and how am I supposed to control it.
If the wheel readings are done at the beginning and instantly applied, then how am I supposed
to control it regarding the widgets?
Without altering the widgets and without the need to use anything from ImGui internal stuff.
No additional example code as it would need ImPlot and my questions are more like
about the proper way of handling stuff than reporting the issue (maybe there is no issue...).
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response
The text was updated successfully, but these errors were encountered: