Skip to content

Commit

Permalink
Break into two crates
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 30, 2018
1 parent 25d049a commit bfa20be
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.sublime*
/docs/*.d.ts
/target
21 changes: 5 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
[package]
name = "emgui"
version = "0.1.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
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]
Expand Down
12 changes: 8 additions & 4 deletions docs/emgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -91,7 +95,7 @@
}
return instantiation.then(({instance}) => {
wasm = init.wasm = instance.exports;
return;

});
};
self.wasm_bindgen = Object.assign(init, __exports);
Expand Down
Binary file modified docs/emgui_bg.wasm
Binary file not shown.
12 changes: 12 additions & 0 deletions emgui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "emgui"
version = "0.1.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
edition = "2018"

[lib]

[dependencies]
# palette = "0.4"
serde = "1"
serde_derive = "1"
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions emgui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions emgui_wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "emgui_wasm"
version = "0.1.0"
authors = ["Emil Ernerfeldt <[email protected]>"]
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" }
6 changes: 3 additions & 3 deletions src/app.rs → emgui_wasm/src/app.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
31 changes: 5 additions & 26 deletions src/lib.rs → emgui_wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 wasm_bindgen::prelude::*;
use emgui::{Emgui, RawInput};

use crate::types::*;
use wasm_bindgen::prelude::*;

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<T: Trait>(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 {
Expand All @@ -43,7 +22,7 @@ pub fn show_gui(raw_input_json: &str) -> String {

lazy_static::lazy_static! {
static ref APP: Mutex<app::App> = Default::default();
static ref EMGUI: Mutex<crate::emgui::Emgui> = Default::default();
static ref EMGUI: Mutex<Emgui> = Default::default();
}

let mut emgui = EMGUI.lock().unwrap();
Expand Down

0 comments on commit bfa20be

Please sign in to comment.