Commit 7dc6ebb5 authored by Florian Blasius's avatar Florian Blasius 🤘

web: almost finished

parent 6fe2f682
Pipeline #9145 passed with stage
in 1 minute and 12 seconds
......@@ -121,7 +121,7 @@ impl Window {
w: u32,
h: u32,
title: &str,
flags: &[WindowFlag],
_flags: &[WindowFlag],
) -> Option<Self> {
// todo resizable.
......@@ -245,7 +245,13 @@ impl Window {
}
/// Set mouse grabbing
pub fn set_mouse_grab(&mut self, grab: bool) {}
pub fn set_mouse_grab(&mut self, grab: bool) {
if grab {
self.canvas.set_capture();
} else {
self.canvas.release_capture();
}
}
/// Set mouse relative mode
pub fn set_mouse_relative(&mut self, relative: bool) {
......@@ -490,9 +496,7 @@ pub fn context_2d(canvas: &HtmlCanvasElement) -> Result<web_sys::CanvasRendering
/// Outputs a message to the web console.
pub fn log(msg: impl Into<JsValue>) {
unsafe {
web_sys::console::log_1(&msg.into());
}
web_sys::console::log_1(&msg.into());
}
fn request_animation_frame(f: &Closure<dyn FnMut()>) {
......@@ -755,4 +759,23 @@ fn connect_event_handlers(
.unwrap();
closure.forget();
}
// resize
{
let events = events.clone();
let canvas_clone = canvas.clone();
let closure = Closure::wrap(Box::new(move |_: web_sys::UiEvent| {
events.borrow_mut().push(
ResizeEvent {
width: canvas_clone.width(),
height: canvas_clone.height(),
}
.to_event(),
);
}) as Box<dyn FnMut(_)>);
canvas
.add_event_listener_with_callback("resize", closure.as_ref().unchecked_ref())
.unwrap();
closure.forget();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment