Translating between column/line and pixel coordinates

I’m experimenting with integrating NeoVim with some third-party programs for the display of media (e.g. images). At present, I am trying to create temporary external windows using MPV to display images.

MPV allows me to create the window wherever I want in pixel coordinates. But to create windows properly relative to NeoVim content, I need to be able to translate line/column coordinates into pixels. What is the best way to do this?

Additional info:

Note that I’m using NeoVim inside the macOS gui VimR. I can get both the macOS window width/height in pixels and the NeoVim width/height in lines/columns. I was hoping that simply taking the ratio of these numbers would give me a constant “cell” width/height in pixels that I could use. But I find that this ratio is slightly different depending on how large the window is. Presumably that is because, despite the underlying cell-structure of the NeoVim content, the GUI window can be smoothly resized-- so a few pixels of “padding” are being introduced somewhere, but I can’t tell where. I am hoping there is a way to perform the conversion without this slight error.

1 Like