Browse Source

Break into two crates

pull/1/head
Emil Ernerfeldt 6 years ago
parent
commit
bfa20be28e
  1. 1
      .gitignore
  2. 21
      Cargo.toml
  3. 12
      docs/emgui.js
  4. BIN
      docs/emgui_bg.wasm
  5. 12
      emgui/Cargo.toml
  6. 0
      emgui/src/emgui.rs
  7. 0
      emgui/src/layout.rs
  8. 16
      emgui/src/lib.rs
  9. 0
      emgui/src/math.rs
  10. 0
      emgui/src/style.rs
  11. 0
      emgui/src/types.rs
  12. 17
      emgui_wasm/Cargo.toml
  13. 6
      emgui_wasm/src/app.rs
  14. 31
      emgui_wasm/src/lib.rs

1
.gitignore

@ -1,2 +1,3 @@
*.sublime*
/docs/*.d.ts
/target

21
Cargo.toml

@ -1,19 +1,8 @@
[package]
name = "emgui"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
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]

12
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);

BIN
docs/emgui_bg.wasm

Binary file not shown.

12
emgui/Cargo.toml

@ -0,0 +1,12 @@
[package]
name = "emgui"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
edition = "2018"
[lib]
[dependencies]
# palette = "0.4"
serde = "1"
serde_derive = "1"

0
src/emgui.rs → emgui/src/emgui.rs

0
src/layout.rs → emgui/src/layout.rs

16
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,
};

0
src/math.rs → emgui/src/math.rs

0
src/style.rs → emgui/src/style.rs

0
src/types.rs → emgui/src/types.rs

17
emgui_wasm/Cargo.toml

@ -0,0 +1,17 @@
[package]
name = "emgui_wasm"
version = "0.1.0"
authors = ["Emil Ernerfeldt <emilernerfeldt@gmail.com>"]
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
src/app.rs → 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();

31
src/lib.rs → 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 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 {
@ -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();
Loading…
Cancel
Save