pixels icon indicating copy to clipboard operation
pixels copied to clipboard

Feature request: Getting window position from pixel position

Open TrolledWoods opened this issue 2 years ago • 1 comments

I'm sure this usecase is very esoteric, but I'm using egui with pixels and I wanted to put egui objects on the same screen location as objects I'm drawing on the pixel buffer, but to do that I need some way of going from pixel positions to window positions, and surprisingly there doesn't seem to be a way right now, even though there is a way to go from window position to pixel position via window_pos_to_pixel. Even without a crazy usecase like that, there are probably other scenarios where this would be something you want.

TrolledWoods avatar Jun 20 '23 12:06 TrolledWoods

Sounds like a reasonable request. The coordinate transformation depends on the scaling matrix, which is an internal implementation detail. (Technically the matrix can be derived from the clipping rectangle, but that's not recommended or intentional.)

For anyone who wishes to implement this feature right away, the window_pos_to_pixel method is the right starting point. The pos vector just needs to be computed slightly differently, and everything else can be the same. In fact, it might be a good idea to reuse most of the code for both cases (if it doesn't require too much accidental complexity).

https://github.com/parasyte/pixels/blob/39e84aacbe117347e7b8e7201c48184344aed9cc/src/lib.rs#L573-L606

parasyte avatar Jun 20 '23 20:06 parasyte