~luyu/comp5411-rendering-project

a8449927e2f43669ff523f6af55d335b6e0ba12c — Luyu Cheng 2 months ago 9c4b3f8
fix: move with only left button
1 files changed, 6 insertions(+), 2 deletions(-)

M src/lib.rs
M src/lib.rs => src/lib.rs +6 -2
@@ 86,7 86,9 @@ pub fn start() -> Result<(), JsValue> {
    {
        let pressed = pressed.clone();
        let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
            pressed.set(true);
            if event.button() == 0 {
                pressed.set(true);
            }
        }) as Box<dyn FnMut(_)>);
        canvas.add_event_listener_with_callback("mousedown", closure.as_ref().unchecked_ref())?;
        closure.forget();


@@ 94,7 96,9 @@ pub fn start() -> Result<(), JsValue> {
    {
        let pressed = pressed.clone();
        let closure = Closure::wrap(Box::new(move |event: web_sys::MouseEvent| {
            pressed.set(false);
            if event.button() == 0 {
                pressed.set(false);
            }
        }) as Box<dyn FnMut(_)>);
        canvas.add_event_listener_with_callback("mouseup", closure.as_ref().unchecked_ref())?;
        canvas.add_event_listener_with_callback("mouseleave", closure.as_ref().unchecked_ref())?;