mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-27 07:03:15 -04:00
Draft web platform structure
This commit is contained in:
20
src/platform_impl/web/stdweb/canvas.rs
Normal file
20
src/platform_impl/web/stdweb/canvas.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
pub struct Canvas;
|
||||
|
||||
impl Canvas {
|
||||
pub fn new() -> Self {
|
||||
let element = document()
|
||||
.create_element("canvas")
|
||||
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?;
|
||||
|
||||
let canvas: CanvasElement = element
|
||||
.try_into()
|
||||
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))?;
|
||||
|
||||
document()
|
||||
.body()
|
||||
.ok_or_else(|| os_error!(OsError("Failed to find body node".to_owned())))?
|
||||
.append_child(&canvas);
|
||||
|
||||
Canvas(canvas)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user