-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add keyboard control for zoom #44
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #44 +/- ##
==========================================
- Coverage 77.90% 77.62% -0.29%
==========================================
Files 13 13
Lines 1856 1868 +12
==========================================
+ Hits 1446 1450 +4
- Misses 410 418 +8 ☔ View full report in Codecov by Sentry. |
hell yes :) there is a slight typing issue here, which requires some explanation. the So, we either need to add a |
This adds a zoom function to the PCanvas and implements for the two current backends. For vispy, the zoom happens under the cursor, like how the mouse wheel behaves. But for pygfx, I did not yet figure out how to do that. Do we need to translate the focused point to the origin, then change zoom, then translate it back?
thanks for the update @ctrueden. Couple remaining issues. (Depending on your degree of interest, I'm happy to fix them from here):
|
@tlambert03 Thanks. Sorry about the pygfx wrong-direction zoom; I didn't notice that when I tested briefly. I did know about the mouse position limitation though—I wrote about it in the commit message. In my view, the +/- keys should behave the same as the mouse wheel scroll (in both 2D and 3D), so of course the first place I looked for implementing +/- was how the mouse wheel code works. But I, embarrassingly, could not figure out how/where the mouse wheel code is... reading the source, all I could see was stuff about a selection, which did not seem relevant. I concluded that maybe the mouse wheel behavior is handled upstream in the backends themselves, rather than in ndv? But I didn't yet dive into a debugger to confirm that. If you know how it works already, I think it makes sense for you to do your thing and wrap up this work. But if you would also need to dig, I can try to make time to do it myself some time soon. Just let me know your preference! |
indeed! all of the mouse interactions are currently just passed to the backends. This was done for now so as to avoid duplicating all of the mouse/controller logic that has already been implemented in these backends. It does of course mean that cases like this can be a little hard to figure out exactly what is handling mouse interactions. For now, until we fully abstract away all mouse interactions and key interactions, this is the state of things. We can certainly intercept mouse/key interaction and do something else, but by default, we just pass them through to the backends (which, thankfully, do mostly the same thing with them) I'm also more than happy to dig into this (i appreciate what you've already done :)). not sure when I'll get to it with busy upcoming weeks, but whoever gets there first can update the other. thanks @ctrueden 🙏 |
This patch adds keyboard shortcuts for zooming the canvas in and out using +/= and -/_ respectively. It also tweaks the hover logic to save the last computed data point, so that the canvas can be zoomed more precisely at that coordinate.