parasyte / pixels

A tiny hardware-accelerated pixel frame buffer. 🦀
https://docs.rs/pixels
MIT License
1.82k stars 123 forks source link

Web Example: Possible to occupy all available space ? Key Input #358

Open markusmoenig opened 1 year ago

markusmoenig commented 1 year ago

Hi,

not a web expert here..., two questions on the web example:

Thanks as always!

parasyte commented 1 year ago

The web example does cover all available space in the Browser window, with the same image scaling rules as with native windows. E.g. it will only scale to even integer ratios, leaving a black border as in the screenshot:

minimal-web screenshot

Resize is already handled: https://github.com/parasyte/pixels/blob/cbda7df53b54be03b9b40bacbf46bc6b2dbaa13a/examples/minimal-web/src/main.rs#L88-L97 and https://github.com/parasyte/pixels/blob/cbda7df53b54be03b9b40bacbf46bc6b2dbaa13a/examples/minimal-web/src/main.rs#L130-L137

For keyboard focus, I think it can be done with some extra web-sys stuff. With access to the canvas element that winit manages, you would call the focus() method on it. Probably need to verify that winit adds an event listener to the canvas (I'm not really sure if it does, maybe it adds a global event listener to the window). If it's a global event listener, then calling focus() on the window should be enough.

markusmoenig commented 1 year ago

Ah, you are right, I forgot that you scale up to even aspect ratios and mistook the black border for unused space. Perfect!

Thanks for the info re web-sys, will look into it.