tim-harding / neophyte

A WebGPU rendered Neovim GUI
MIT License
144 stars 3 forks source link

[question] Pixel-precise scrolling #14

Closed ales-tsurko closed 9 months ago

ales-tsurko commented 9 months ago

Hi! I was about to start building my own wgpu-based frontend for neovim, when I found this repo. Cool! My motivation was lack of smooth scrolling (I mean something like emacs GUI pixel-precise scroll) and better keyboard bindings handling. And I see you already implemented smooth scrolling. But it looks like kind of interpolation for vim's line based scrolling. Given that you have experience with it, I'd like to ask your opinion on implementing pixel-precise scrolling. My idea was using scroll delta to shift text lines to additional pixels, so you could scroll by pixels using delta and when it's more than a line height, it would send a scroll event to the neovim. Do you think, would it be possible in a practical way? And if so, could you point me to related code parts in your repo, so I could try it out on my fork? If you're interested, and I'd had any luck with it, I could contribute this feature back in the repo:) Otherwise, I'd just use it as a fork. Thanks!

tim-harding commented 9 months ago

If you mean sub-line scrolling with the mouse, I think you'd need to request a larger vertical size for the grid and just render the lines in view. The trouble is that Neovim isn't really on the same page about what's being displayed so you might have some difficulties with the cursor going off the bottom because Neovim thinks more lines are visible. I think there are some issues related to making this easier but I don't have links offhand.

The code for scrolling animation is in this file: https://github.com/tim-harding/neophyte/blob/main/src/rendering/scrolling_grids/mod.rs

This code is probably a bit confusing, but whenever a scroll event happens, the grid is added to this collection with an offset. The text shaper iterates over the lines in the collection, which come with vertical offsets. I then just animate the quads toward their final position and remove the old grids when the scroll finishes.

ales-tsurko commented 9 months ago

Thanks!

tim-harding commented 9 months ago

By the way, I'm thinking that my next initiative for Neophyte will be to break it up into crates for parsing UI events, managing UI state synchronization, rendering, and the app itself, which could make experimentation with new GUI ideas easier if you want to blaze your own trail. No promises on when that will be done, but it's planned.

ales-tsurko commented 9 months ago

Sounds cool!