Define the js wasm-editor interface (#31)

This commit is contained in:
TrueDoctor
2021-03-21 19:32:56 +01:00
committed by Keavon Chambers
parent 1b8c71d2b3
commit d254916430
10 changed files with 75 additions and 4 deletions
+23
View File
@@ -0,0 +1,23 @@
mod utils;
mod viewport;
mod window;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen(start)]
pub fn init() {
utils::set_panic_hook();
alert("Hello, Graphite!");
}
/// Send events
#[wasm_bindgen]
pub fn handle_event(event_name: String) {
// TODO: add payload
todo!()
}
+10
View File
@@ -0,0 +1,10 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
+18
View File
@@ -0,0 +1,18 @@
/// Modify the currently selected tool in the document state store
#[wasm_bindgen]
pub fn select_tool(tool: String) {
todo!()
}
/// Mouse movement with the bounds of the canvas
#[wasm_bindgen]
pub fn on_mouse_move(x: u32, y: u32) {
todo!()
}
use graphite_editor::Color;
/// Update working colors
#[wasm_bindgen]
pub fn update_colors(primary_color: Color, secondary_color: Color) {
todo!()
}
+40
View File
@@ -0,0 +1,40 @@
type DocumentId = u32;
/// Modify the active Document in the editor state store
#[wasm_bindgen]
pub fn set_active_document(document_id: DocumentId) {
todo!()
}
/// Query the name of a specific document
#[wasm_bindgen]
pub fn get_document_name(document_id: DocumentId) -> String {
todo!()
}
/// Query the id of the most recently interacted with document
#[wasm_bindgen]
pub fn get_active_document() -> DocumentId {
todo!()
}
use graphite_editor::layout::PanelId;
/// Notify the editor that the mouse hovers above a panel
#[wasm_bindgen]
pub fn panel_hover_enter(panel_id: PanelId) {
todo!()
}
/// Query a list of currently available operations
#[wasm_bindgen]
pub fn get_available_operations() -> Box<[String]> {
todo!()
}
/*
/// Load a new .gdd file into the editor
/// Returns a unique document identifier
#[wasm_bindgen]
pub fn load_document(raw_data: &[u8]) -> DocumentId {
todo!()
}*/