Implement key handling (#65)

This commit is contained in:
TrueDoctor
2021-04-07 11:02:56 +02:00
committed by Keavon Chambers
parent 599d478a5c
commit 0a112be97b
7 changed files with 112 additions and 13 deletions
+20 -2
View File
@@ -1,6 +1,6 @@
use crate::shims::Error;
use crate::wrappers::{translate_tool, Color};
use crate::wrappers::{translate_key, translate_tool, Color};
use crate::EDITOR_STATE;
use crate::{shims::Error, utils};
use editor_core::events;
use wasm_bindgen::prelude::*;
@@ -46,6 +46,24 @@ pub fn on_mouse_up(x: u32, y: u32, mouse_keys: u8) -> Result<(), JsValue> {
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_event(ev)).map_err(|err| Error::new(&err.to_string()).into())
}
/// A keyboard button depressed within screenspace the bounds of the viewport
#[wasm_bindgen]
pub fn on_key_down(name: String) -> Result<(), JsValue> {
let key = translate_key(&name);
log::trace!("key down {:?}, name: {}", key, name);
let ev = events::Event::KeyDown(key);
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_event(ev)).map_err(|err| Error::new(&err.to_string()).into())
}
/// A keyboard button released
#[wasm_bindgen]
pub fn on_key_up(name: String) -> Result<(), JsValue> {
let key = translate_key(&name);
log::trace!("key up {:?}, name: {}", key, name);
let ev = events::Event::KeyUp(key);
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_event(ev)).map_err(|err| Error::new(&err.to_string()).into())
}
/// Update primary color
#[wasm_bindgen]
pub fn update_primary_color(primary_color: Color) -> Result<(), JsValue> {