Figured out how to resize canvas properly, will still have to handle on window resize
This commit is contained in:
parent
747e9f9595
commit
0fafffb40f
@ -9,12 +9,20 @@ use crate::space_colonization::SpaceColonization;
|
||||
#[component]
|
||||
pub fn Background(cx: Scope, class: &'static str) -> impl IntoView {
|
||||
let canvas = create_node_ref::<Canvas>(cx);
|
||||
let mut size = (300, 300);
|
||||
|
||||
canvas.on_load(cx, move |_| {
|
||||
let canvas = canvas.get().expect("canvas is mounted");
|
||||
let canvas_parent = canvas.parent_element().unwrap();
|
||||
canvas.set_width(u32::try_from(canvas_parent.client_width()).unwrap());
|
||||
canvas.set_height(u32::try_from(canvas_parent.client_height()).unwrap());
|
||||
log!(
|
||||
"canvas parent size = {} {}",
|
||||
canvas_parent.client_width(),
|
||||
canvas_parent.client_height()
|
||||
);
|
||||
log!("in canvas");
|
||||
let context = canvas
|
||||
.get()
|
||||
.expect("canvas is mounted")
|
||||
.get_context("2d")
|
||||
.ok()
|
||||
.flatten()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user