From a8a9e15a4a86ff2159e42deb2374cb7d4ed874c8 Mon Sep 17 00:00:00 2001 From: ProTheory8 <59506423+protheory8@users.noreply.github.com> Date: Mon, 22 Mar 2021 21:42:14 +0500 Subject: [PATCH] Make it compile (#37) * Fix indentation * Set the correct name of the crate in root Cargo.toml * Fix all compile errors --- Cargo.toml | 5 ++--- packages/graphite-editor/Cargo.toml | 1 - packages/graphite-editor/src/error.rs | 2 +- packages/graphite-editor/src/lib.rs | 3 ++- packages/graphite-editor/src/scheduler/mod.rs | 1 + packages/graphite-editor/src/workspace/mod.rs | 2 +- web-frontend/wasm-wrapper/src/lib.rs | 13 ++++--------- web-frontend/wasm-wrapper/src/viewport.rs | 4 +++- web-frontend/wasm-wrapper/src/window.rs | 9 ++++++--- web-frontend/wasm-wrapper/src/wrappers.rs | 13 +++++++++++++ 10 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 web-frontend/wasm-wrapper/src/wrappers.rs diff --git a/Cargo.toml b/Cargo.toml index 6c8d33d7ac..1f05e01e65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,8 @@ [workspace] members = [ "packages/*", - "web-frontend/wasm-wrapper", + "web-frontend/wasm-wrapper", ] -[profile.release.package.wasm-bindings] -# Tell `rustc` to optimize for small code size. +[profile.release.package.wasm-wrapper] opt-level = "s" diff --git a/packages/graphite-editor/Cargo.toml b/packages/graphite-editor/Cargo.toml index 2872eeab60..1b575debc3 100644 --- a/packages/graphite-editor/Cargo.toml +++ b/packages/graphite-editor/Cargo.toml @@ -4,6 +4,5 @@ version = "0.1.0" authors = ["Keavon Chambers "] edition = "2018" - [dependencies] log = "0.4" diff --git a/packages/graphite-editor/src/error.rs b/packages/graphite-editor/src/error.rs index f5b2a8c9c0..00b19e976e 100644 --- a/packages/graphite-editor/src/error.rs +++ b/packages/graphite-editor/src/error.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::fmt::{self, Display}; /// The error type used by the graphite editor. -#[derive(Debug)] +#[derive(Clone, Debug)] pub enum EditorError { InvalidOperation(String), Misc(String), diff --git a/packages/graphite-editor/src/lib.rs b/packages/graphite-editor/src/lib.rs index 1649c48e5f..3baa4fffb3 100644 --- a/packages/graphite-editor/src/lib.rs +++ b/packages/graphite-editor/src/lib.rs @@ -11,9 +11,10 @@ pub use error::EditorError; pub use color::Color; use tools::ToolState; +use workspace::Workspace; // TODO: serialize with serde to save the current editor state struct Editor { tools: ToolState, - workspace: workspace::Workspace, + workspace: Workspace, } diff --git a/packages/graphite-editor/src/scheduler/mod.rs b/packages/graphite-editor/src/scheduler/mod.rs index e69de29bb2..8b13789179 100644 --- a/packages/graphite-editor/src/scheduler/mod.rs +++ b/packages/graphite-editor/src/scheduler/mod.rs @@ -0,0 +1 @@ + diff --git a/packages/graphite-editor/src/workspace/mod.rs b/packages/graphite-editor/src/workspace/mod.rs index 1cc4f5af44..37e265627c 100644 --- a/packages/graphite-editor/src/workspace/mod.rs +++ b/packages/graphite-editor/src/workspace/mod.rs @@ -1,7 +1,7 @@ use crate::EditorError; pub type PanelId = usize; -struct Workspace { +pub struct Workspace { hovered_panel: PanelId, root: PanelGroup, } diff --git a/web-frontend/wasm-wrapper/src/lib.rs b/web-frontend/wasm-wrapper/src/lib.rs index f3ac30b257..9f14398010 100644 --- a/web-frontend/wasm-wrapper/src/lib.rs +++ b/web-frontend/wasm-wrapper/src/lib.rs @@ -1,18 +1,13 @@ -mod utils; -mod viewport; -mod window; +pub mod utils; +pub mod viewport; +pub mod window; +pub mod wrappers; 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 diff --git a/web-frontend/wasm-wrapper/src/viewport.rs b/web-frontend/wasm-wrapper/src/viewport.rs index 411e1a2c50..ebfa59f88f 100644 --- a/web-frontend/wasm-wrapper/src/viewport.rs +++ b/web-frontend/wasm-wrapper/src/viewport.rs @@ -1,3 +1,6 @@ +use crate::wrappers::Color; +use wasm_bindgen::prelude::*; + /// Modify the currently selected tool in the document state store #[wasm_bindgen] pub fn select_tool(tool: String) { @@ -10,7 +13,6 @@ 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) { diff --git a/web-frontend/wasm-wrapper/src/window.rs b/web-frontend/wasm-wrapper/src/window.rs index 1c57480c6b..80d11ad5dd 100644 --- a/web-frontend/wasm-wrapper/src/window.rs +++ b/web-frontend/wasm-wrapper/src/window.rs @@ -1,3 +1,5 @@ +use wasm_bindgen::prelude::*; + type DocumentId = u32; /// Modify the active Document in the editor state store @@ -18,7 +20,7 @@ pub fn get_active_document() -> DocumentId { todo!() } -use graphite_editor::layout::PanelId; +use graphite_editor::workspace::PanelId; /// Notify the editor that the mouse hovers above a panel #[wasm_bindgen] pub fn panel_hover_enter(panel_id: PanelId) { @@ -27,8 +29,9 @@ pub fn panel_hover_enter(panel_id: PanelId) { /// Query a list of currently available operations #[wasm_bindgen] -pub fn get_available_operations() -> Box<[String]> { - todo!() +pub fn get_available_operations() -> Vec { + todo!(); + // vec!["example1", "example2"].into_iter().map(JsValue::from).collect() } /* diff --git a/web-frontend/wasm-wrapper/src/wrappers.rs b/web-frontend/wasm-wrapper/src/wrappers.rs new file mode 100644 index 0000000000..0d54a7b4a0 --- /dev/null +++ b/web-frontend/wasm-wrapper/src/wrappers.rs @@ -0,0 +1,13 @@ +use graphite_editor::Color as InnerColor; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct Color(InnerColor); + +#[wasm_bindgen] +impl Color { + #[wasm_bindgen(constructor)] + pub fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Self { + Self(InnerColor::from_rgbaf32(red, green, blue, alpha).unwrap_throw()) + } +}