-
When targeting Web, is it possible to have a dynamically sized Canvas? I have been following this tutorial here, and I am unable to dynamically size the canvas (so resize when Browser Size changes, e.g.). What I was able to accomplish is to manually set width, height, and style of the Canvas using JS from the Browsers Console: But I was unable to accomplish the same using web-sys by also using a resize listener on the parent element. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I just noticed https://github.com/simbleau/nbody-wasm-sim supports dynamic resizing of canvases. I will try to extract how he accomplishes this, and will then come back here to update the Question. |
Beta Was this translation helpful? Give feedback.
-
Ok, figured out using https://github.com/simbleau/nbody-wasm-sim. These are the main steps:
That is basically it. These should be all changes to this tutorial here necessary to accomplish dynamically sized canvas on web! |
Beta Was this translation helpful? Give feedback.
Ok, figured out using https://github.com/simbleau/nbody-wasm-sim. These are the main steps:
let surface = instance.create_surface_from_canvas(canvas).unwrap();
(code)let window = WindowBuilder::new().with_canvas(Some(canvas)).....
(code)let (width, height) = (canvas.client_width(), canvas.client_h…