web_sys::HtmlCanvasElement::set_height function

Example

Set the height of the canvas.


    pub fn htmlcanvaselement_set_width_height()
    {
        let document = web_sys::window().unwrap().document().unwrap();
        let canvas = document.get_element_by_id("canvas").unwrap();
        let canvas: web_sys::HtmlCanvasElement = canvas
            .dyn_into::<web_sys::HtmlCanvasElement>()
            .map_err(|_| ())
            .unwrap();
    
        canvas.set_width(500);
        canvas.set_height(500);
        
        let context = canvas
            .get_context("2d")
            .unwrap()
            .unwrap()
            .dyn_into::<web_sys::CanvasRenderingContext2d>()
            .unwrap();
    
        context.begin_path();
    
        context
            .rect(75.0, 75.0, 50.0, 50.0);
    
        context.fill();
    
    }    

Function


	pub fn set_height(&self, height: u32)

features/dependencies

Source Code