egui/src/lib.rs

64 lines
1.3 KiB
Rust
Raw Normal View History

2018-12-26 16:01:46 +00:00
#![deny(warnings)]
2018-12-23 19:06:40 +00:00
extern crate lazy_static;
extern crate serde;
extern crate serde_json;
extern crate wasm_bindgen;
extern crate web_sys;
2018-12-23 19:06:40 +00:00
2018-12-26 16:01:46 +00:00
#[macro_use] // TODO: get rid of this
extern crate serde_derive;
2018-12-23 19:06:40 +00:00
use std::sync::Mutex;
use wasm_bindgen::prelude::*;
2018-12-26 22:08:50 +00:00
use crate::types::*;
2018-12-26 09:46:23 +00:00
pub mod app;
2018-12-26 22:08:50 +00:00
pub mod emgui;
pub mod layout;
2018-12-26 16:01:46 +00:00
pub mod math;
2018-12-26 13:38:46 +00:00
pub mod style;
2018-12-26 09:46:23 +00:00
pub mod types;
2018-12-23 23:15:18 +00:00
/*
// 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]
2018-12-26 09:46:23 +00:00
pub fn show_gui(raw_input_json: &str) -> String {
// TODO: faster interface than JSON
let raw_input: RawInput = serde_json::from_str(raw_input_json).unwrap();
2018-12-23 19:06:40 +00:00
lazy_static::lazy_static! {
2018-12-26 21:17:33 +00:00
static ref APP: Mutex<app::App> = Default::default();
2018-12-26 22:08:50 +00:00
static ref EMGUI: Mutex<crate::emgui::Emgui> = Default::default();
2018-12-23 19:06:40 +00:00
}
2018-12-26 22:08:50 +00:00
let mut emgui = EMGUI.lock().unwrap();
emgui.new_frame(raw_input);
2018-12-26 14:28:38 +00:00
2018-12-26 22:08:50 +00:00
use crate::app::GuiSettings;
APP.lock().unwrap().show_gui(&mut emgui.layout);
2018-12-26 14:28:38 +00:00
2018-12-27 17:19:06 +00:00
let mut style = emgui.style.clone();
2018-12-27 18:08:43 +00:00
emgui.layout.foldable("Style", |gui| {
style.show_gui(gui);
});
2018-12-27 17:19:06 +00:00
emgui.style = style;
2018-12-26 22:08:50 +00:00
let commands = emgui.paint();
serde_json::to_string(&commands).unwrap()
}