parent
57981b533d
commit
10419ff441
72 changed files with 377 additions and 312 deletions
|
|
@ -44,11 +44,11 @@ impl Canvas {
|
|||
Some(canvas) => canvas,
|
||||
None => {
|
||||
let window = web_sys::window()
|
||||
.ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
|
||||
.ok_or_else(|| os_error!(OsError("Failed to obtain window".to_owned())))?;
|
||||
|
||||
let document = window
|
||||
.document()
|
||||
.ok_or(os_error!(OsError("Failed to obtain document".to_owned())))?;
|
||||
.ok_or_else(|| os_error!(OsError("Failed to obtain document".to_owned())))?;
|
||||
|
||||
document
|
||||
.create_element("canvas")
|
||||
|
|
@ -94,10 +94,10 @@ impl Canvas {
|
|||
self.raw().request_pointer_lock();
|
||||
} else {
|
||||
let window = web_sys::window()
|
||||
.ok_or(os_error!(OsError("Failed to obtain window".to_owned())))?;
|
||||
.ok_or_else(|| os_error!(OsError("Failed to obtain window".to_owned())))?;
|
||||
let document = window
|
||||
.document()
|
||||
.ok_or(os_error!(OsError("Failed to obtain document".to_owned())))?;
|
||||
.ok_or_else(|| os_error!(OsError("Failed to obtain document".to_owned())))?;
|
||||
document.exit_pointer_lock();
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -107,7 +107,7 @@ impl Canvas {
|
|||
self.common
|
||||
.raw
|
||||
.set_attribute(attribute, value)
|
||||
.expect(&format!("Set attribute: {}", attribute));
|
||||
.unwrap_or_else(|err| panic!("error: {:?}\nSet attribute: {}", err, attribute))
|
||||
}
|
||||
|
||||
pub fn position(&self) -> LogicalPosition<f64> {
|
||||
|
|
@ -339,9 +339,7 @@ impl Common {
|
|||
handler(event);
|
||||
}) as Box<dyn FnMut(E)>);
|
||||
|
||||
let listener = EventListenerHandle::new(&self.raw, event_name, closure);
|
||||
|
||||
listener
|
||||
EventListenerHandle::new(&self.raw, event_name, closure)
|
||||
}
|
||||
|
||||
// The difference between add_event and add_user_event is that the latter has a special meaning
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ use std::rc::Rc;
|
|||
|
||||
use web_sys::{EventTarget, MouseEvent};
|
||||
|
||||
type MouseLeaveHandler = Rc<RefCell<Option<Box<dyn FnMut(i32)>>>>;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(super) struct MouseHandler {
|
||||
on_mouse_leave: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
|
||||
|
|
@ -15,7 +17,7 @@ pub(super) struct MouseHandler {
|
|||
on_mouse_move: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
|
||||
on_mouse_press: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
|
||||
on_mouse_release: Option<EventListenerHandle<dyn FnMut(MouseEvent)>>,
|
||||
on_mouse_leave_handler: Rc<RefCell<Option<Box<dyn FnMut(i32)>>>>,
|
||||
on_mouse_leave_handler: MouseLeaveHandler,
|
||||
mouse_capture_state: Rc<RefCell<MouseCaptureState>>,
|
||||
}
|
||||
|
||||
|
|
@ -175,8 +177,8 @@ impl MouseHandler {
|
|||
.map_or(false, |target| target == EventTarget::from(canvas.clone()));
|
||||
match &*mouse_capture_state {
|
||||
// Don't handle hover events outside of canvas.
|
||||
MouseCaptureState::NotCaptured if !is_over_canvas => return,
|
||||
MouseCaptureState::OtherElement if !is_over_canvas => return,
|
||||
MouseCaptureState::NotCaptured | MouseCaptureState::OtherElement
|
||||
if !is_over_canvas => {}
|
||||
// If hovering over the canvas, just send the cursor move event.
|
||||
MouseCaptureState::NotCaptured
|
||||
| MouseCaptureState::OtherElement
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ impl MediaQueryListHandle {
|
|||
.ok()
|
||||
.flatten()
|
||||
.and_then(|mql| {
|
||||
mql.add_listener_with_opt_callback(Some(&listener.as_ref().unchecked_ref()))
|
||||
mql.add_listener_with_opt_callback(Some(listener.as_ref().unchecked_ref()))
|
||||
.map(|_| mql)
|
||||
.ok()
|
||||
});
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ pub fn set_canvas_style_property(raw: &HtmlCanvasElement, property: &str, value:
|
|||
let style = raw.style();
|
||||
style
|
||||
.set_property(property, value)
|
||||
.expect(&format!("Failed to set {}", property));
|
||||
.unwrap_or_else(|err| panic!("error: {:?}\nFailed to set {}", err, property))
|
||||
}
|
||||
|
||||
pub fn is_fullscreen(canvas: &HtmlCanvasElement) -> bool {
|
||||
|
|
|
|||
|
|
@ -65,13 +65,13 @@ impl ScaleChangeDetectorInternal {
|
|||
);
|
||||
let mql = MediaQueryListHandle::new(&media_query, closure);
|
||||
if let Some(mql) = &mql {
|
||||
assert_eq!(mql.mql().matches(), true);
|
||||
assert!(mql.mql().matches());
|
||||
}
|
||||
mql
|
||||
}
|
||||
|
||||
fn handler(&mut self, event: MediaQueryListEvent) {
|
||||
assert_eq!(event.matches(), false);
|
||||
assert!(!event.matches());
|
||||
let mql = self
|
||||
.mql
|
||||
.take()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl Timeout {
|
|||
|
||||
let handle = window
|
||||
.set_timeout_with_callback_and_timeout_and_arguments_0(
|
||||
&closure.as_ref().unchecked_ref(),
|
||||
closure.as_ref().unchecked_ref(),
|
||||
duration.as_millis() as i32,
|
||||
)
|
||||
.expect("Failed to set timeout");
|
||||
|
|
@ -64,7 +64,7 @@ impl AnimationFrameRequest {
|
|||
}) as Box<dyn FnMut()>);
|
||||
|
||||
let handle = window
|
||||
.request_animation_frame(&closure.as_ref().unchecked_ref())
|
||||
.request_animation_frame(closure.as_ref().unchecked_ref())
|
||||
.expect("Failed to request animation frame");
|
||||
|
||||
AnimationFrameRequest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue