pixels icon indicating copy to clipboard operation
pixels copied to clipboard

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

Open markusmoenig opened this issue 1 year ago • 2 comments

Hi,

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

  • Is it possible to open the window so that it covers all available browser space (and resize with it) ?
  • By default, after running the example it does not have keyboard focus, before being able to receive keyboard input one has to click on the window canvas. Is it possible to make the window canvas focus during startup ?

Thanks as always!

markusmoenig avatar May 02 '23 02:05 markusmoenig

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.

parasyte avatar May 02 '23 02:05 parasyte

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.

markusmoenig avatar May 02 '23 02:05 markusmoenig