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

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
target/ target/
*.spv *.spv
*.exrc

3
Cargo.lock generated
View File

@ -199,10 +199,11 @@ dependencies = [
] ]
[[package]] [[package]]
name = "wasm-bindings" name = "wasm-wrapper"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"graphite-editor",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test", "wasm-bindgen-test",
] ]

View File

@ -1,6 +1,7 @@
[workspace] [workspace]
members = [ members = [
"packages/*", "packages/*",
"web-frontend/wasm-wrapper",
] ]
[profile.release.package.wasm-bindings] [profile.release.package.wasm-bindings]

View File

@ -1,5 +1,5 @@
use crate::EditorError; use crate::EditorError;
type PanelId = usize; pub type PanelId = usize;
struct LayoutRoot { struct LayoutRoot {
hovered_panel: PanelId, hovered_panel: PanelId,

View File

@ -1,5 +1,5 @@
[package] [package]
name = "wasm-bindings" name = "wasm-wrapper"
version = "0.1.0" version = "0.1.0"
authors = ["Keavon Chambers <graphite@keavon.com>"] authors = ["Keavon Chambers <graphite@keavon.com>"]
edition = "2018" edition = "2018"
@ -12,6 +12,7 @@ default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2.72" wasm-bindgen = "0.2.72"
graphite-editor = { path = "../../packages/graphite-editor" }
# The `console_error_panic_hook` crate provides better debugging of panics by # The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires # logging them with `console.error`. This is great for development, but requires

View File

@ -1,4 +1,6 @@
mod utils; mod utils;
mod viewport;
mod window;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -12,3 +14,10 @@ pub fn init() {
utils::set_panic_hook(); utils::set_panic_hook();
alert("Hello, Graphite!"); alert("Hello, Graphite!");
} }
/// Send events
#[wasm_bindgen]
pub fn handle_event(event_name: String) {
// TODO: add payload
todo!()
}

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!()
}

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!()
}*/