diff --git a/.gitignore b/.gitignore index 1d09522c..48aed118 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.sublime* +/docs/*.d.ts /target diff --git a/Cargo.toml b/Cargo.toml index fb7cdcc1..6879c8ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,19 +1,8 @@ -[package] -name = "emgui" -version = "0.1.0" -authors = ["Emil Ernerfeldt "] -edition = "2018" - -[lib] -crate-type = ["cdylib", "rlib"] - -[dependencies] -lazy_static = "1" -serde = "1" -serde_derive = "1" -serde_json = "1" -wasm-bindgen = "0.2" -web-sys = { version = "0.3.5", features = ['console', 'Performance', 'Window'] } +[workspace] +members = [ + "emgui", + "emgui_wasm", +] # Optimize for small code size: [profile.dev] diff --git a/docs/emgui.js b/docs/emgui.js index 07a839c5..7ae8bf76 100644 --- a/docs/emgui.js +++ b/docs/emgui.js @@ -13,12 +13,15 @@ return cachegetUint8Memory; } + let WASM_VECTOR_LEN = 0; + function passStringToWasm(arg) { const buf = cachedTextEncoder.encode(arg); const ptr = wasm.__wbindgen_malloc(buf.length); getUint8Memory().set(buf, ptr); - return [ptr, buf.length]; + WASM_VECTOR_LEN = buf.length; + return ptr; } let cachedTextDecoder = new TextDecoder('utf-8'); @@ -47,7 +50,8 @@ * @returns {string} */ __exports.show_gui = function(arg0) { - const [ptr0, len0] = passStringToWasm(arg0); + const ptr0 = passStringToWasm(arg0); + const len0 = WASM_VECTOR_LEN; const retptr = globalArgumentPtr(); try { wasm.show_gui(retptr, ptr0, len0); @@ -77,7 +81,7 @@ if (path_or_module instanceof WebAssembly.Module) { instantiation = WebAssembly.instantiate(path_or_module, imports) .then(instance => { - return { instance, module: module_or_path } + return { instance, module: path_or_module } }); } else { const data = fetch(path_or_module); @@ -91,7 +95,7 @@ } return instantiation.then(({instance}) => { wasm = init.wasm = instance.exports; - return; + }); }; self.wasm_bindgen = Object.assign(init, __exports); diff --git a/docs/emgui_bg.wasm b/docs/emgui_bg.wasm index 15110b68..62a3c82b 100644 Binary files a/docs/emgui_bg.wasm and b/docs/emgui_bg.wasm differ diff --git a/emgui/Cargo.toml b/emgui/Cargo.toml new file mode 100644 index 00000000..6be652f4 --- /dev/null +++ b/emgui/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "emgui" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +edition = "2018" + +[lib] + +[dependencies] +# palette = "0.4" +serde = "1" +serde_derive = "1" diff --git a/src/emgui.rs b/emgui/src/emgui.rs similarity index 100% rename from src/emgui.rs rename to emgui/src/emgui.rs diff --git a/src/layout.rs b/emgui/src/layout.rs similarity index 100% rename from src/layout.rs rename to emgui/src/layout.rs diff --git a/emgui/src/lib.rs b/emgui/src/lib.rs new file mode 100644 index 00000000..a8996947 --- /dev/null +++ b/emgui/src/lib.rs @@ -0,0 +1,16 @@ +#![deny(warnings)] + +extern crate serde; + +#[macro_use] // TODO: get rid of this +extern crate serde_derive; + +mod emgui; +mod layout; +pub mod math; +mod style; +pub mod types; + +pub use crate::{ + emgui::Emgui, layout::Layout, layout::LayoutOptions, style::Style, types::RawInput, +}; diff --git a/src/math.rs b/emgui/src/math.rs similarity index 100% rename from src/math.rs rename to emgui/src/math.rs diff --git a/src/style.rs b/emgui/src/style.rs similarity index 100% rename from src/style.rs rename to emgui/src/style.rs diff --git a/src/types.rs b/emgui/src/types.rs similarity index 100% rename from src/types.rs rename to emgui/src/types.rs diff --git a/emgui_wasm/Cargo.toml b/emgui_wasm/Cargo.toml new file mode 100644 index 00000000..5aeed7d5 --- /dev/null +++ b/emgui_wasm/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "emgui_wasm" +version = "0.1.0" +authors = ["Emil Ernerfeldt "] +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +lazy_static = "1" +serde = "1" +serde_json = "1" +wasm-bindgen = "0.2" +# web-sys = { version = "0.3.5", features = ['console', 'Performance', 'Window'] } + +emgui = { path = "../emgui" } diff --git a/src/app.rs b/emgui_wasm/src/app.rs similarity index 96% rename from src/app.rs rename to emgui_wasm/src/app.rs index c8d37157..f138ce78 100644 --- a/src/app.rs +++ b/emgui_wasm/src/app.rs @@ -1,4 +1,4 @@ -use crate::{layout::Layout, math::*, types::*}; +use emgui::{math::*, types::*, Layout}; pub trait GuiSettings { fn show_gui(&mut self, gui: &mut Layout); @@ -91,7 +91,7 @@ impl GuiSettings for App { } } -impl GuiSettings for crate::layout::LayoutOptions { +impl GuiSettings for emgui::LayoutOptions { fn show_gui(&mut self, gui: &mut Layout) { if gui.button("Reset LayoutOptions").clicked { *self = Default::default(); @@ -110,7 +110,7 @@ impl GuiSettings for crate::layout::LayoutOptions { } } -impl GuiSettings for crate::style::Style { +impl GuiSettings for emgui::Style { fn show_gui(&mut self, gui: &mut Layout) { if gui.button("Reset Style").clicked { *self = Default::default(); diff --git a/src/lib.rs b/emgui_wasm/src/lib.rs similarity index 63% rename from src/lib.rs rename to emgui_wasm/src/lib.rs index 57de2a3c..cfddc6f1 100644 --- a/src/lib.rs +++ b/emgui_wasm/src/lib.rs @@ -1,40 +1,19 @@ #![deny(warnings)] extern crate lazy_static; -extern crate serde; extern crate serde_json; extern crate wasm_bindgen; -extern crate web_sys; +// extern crate web_sys; -#[macro_use] // TODO: get rid of this -extern crate serde_derive; +extern crate emgui; use std::sync::Mutex; +use emgui::{Emgui, RawInput}; + use wasm_bindgen::prelude::*; -use crate::types::*; - pub mod app; -pub mod emgui; -pub mod layout; -pub mod math; -pub mod style; -pub mod types; - -/* -// Fast compilation, slow code: -fn foo(x: &dyn Trait); - - -// Fast code, slow compilation: -fn foo(x: &dyn T); - - -// Compiles quickly in debug, fast in release: -#[dynimp(Trait)] -fn foo(x: &Trait); -*/ #[wasm_bindgen] pub fn show_gui(raw_input_json: &str) -> String { @@ -43,7 +22,7 @@ pub fn show_gui(raw_input_json: &str) -> String { lazy_static::lazy_static! { static ref APP: Mutex = Default::default(); - static ref EMGUI: Mutex = Default::default(); + static ref EMGUI: Mutex = Default::default(); } let mut emgui = EMGUI.lock().unwrap();