feat(egui): egui app code init
parent
35b12c19f4
commit
056d304b73
|
@ -1 +1,3 @@
|
|||
/target
|
||||
/.vscode
|
||||
/dist
|
File diff suppressed because it is too large
Load Diff
24
Cargo.toml
24
Cargo.toml
|
@ -9,6 +9,12 @@ edition = "2021"
|
|||
lazy_static = "1.4.0"
|
||||
pest = "2.0"
|
||||
pest_derive = "2.0"
|
||||
# web
|
||||
egui = "0.20.0"
|
||||
eframe = { version = "0.20.0", default-features = false, features = [
|
||||
"default_fonts", # Embed the default egui fonts.
|
||||
"glow", # Use the glow rendering backend. Alternative: "wgpu".
|
||||
] }
|
||||
|
||||
[lib]
|
||||
name = "ducklang"
|
||||
|
@ -21,3 +27,21 @@ path = "src/parser/duck_parser.rs"
|
|||
[[bin]]
|
||||
name = "duck_interpreter"
|
||||
path = "src/interpreter/duck_interpreter.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "duck_web"
|
||||
path = "src/web/main.rs"
|
||||
|
||||
# native:
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
tracing-subscriber = "0.3"
|
||||
|
||||
# web:
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
console_error_panic_hook = "0.1.6"
|
||||
tracing-wasm = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 's'
|
||||
lto = true
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<link data-trunk rel="rust" data-wasm-opt="2" />
|
||||
|
||||
<style>
|
||||
html {
|
||||
/* Remove touch delay: */
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
overflow: hidden;
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
canvas {
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 0%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, 0%);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,68 @@
|
|||
// const CANVAS_WIDTH: f32 = 1280.0;
|
||||
// const CANVAS_HEIGHT: f32 = 720.0;
|
||||
|
||||
pub struct MyEguiApp {
|
||||
_code: String,
|
||||
}
|
||||
|
||||
impl MyEguiApp {
|
||||
pub fn new(_cc: &eframe::CreationContext<'_>) -> Self {
|
||||
Self {
|
||||
_code: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MyEguiApp {
|
||||
fn update(&mut self, _ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
// let toolbar = self.render_toolbar(ctx);
|
||||
// #[cfg(not(target_arch = "wasm32"))]
|
||||
// frame.set_window_size(egui::vec2(CANVAS_WIDTH, CANVAS_HEIGHT + toolbar.height()));
|
||||
// ctx.request_repaint();
|
||||
|
||||
// TODO
|
||||
// toolbar:
|
||||
// - reset code and env
|
||||
// - reset env
|
||||
// - run code
|
||||
// - ...
|
||||
// central panel:
|
||||
// - code editor
|
||||
// side panel:
|
||||
// - env
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn main() {
|
||||
// Make sure panics are logged using `console.error`.
|
||||
console_error_panic_hook::set_once();
|
||||
tracing_wasm::set_as_global_default();
|
||||
|
||||
let web_options = eframe::WebOptions::default();
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async {
|
||||
eframe::start_web(
|
||||
// this is the id of the `<canvas>` element we have
|
||||
// in our `index.html`
|
||||
"canvas",
|
||||
web_options,
|
||||
Box::new(|cc| Box::new(MyEguiApp::new(cc))),
|
||||
)
|
||||
.await
|
||||
.expect("failed to start eframe");
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn main() {
|
||||
let options = eframe::NativeOptions {
|
||||
resizable: false,
|
||||
..Default::default()
|
||||
};
|
||||
eframe::run_native(
|
||||
"Game of Life",
|
||||
options,
|
||||
Box::new(|cc| Box::new(MyEguiApp::new(cc))),
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue