1use eframe::egui;
6use wander::{run, NoHostType};
7use wander::preludes::common;
8
9pub fn start_app() -> Result<(), eframe::Error> {
10 let options = eframe::NativeOptions {
11 initial_window_size: Some(egui::vec2(320.0, 240.0)),
12 ..Default::default()
13 };
14 eframe::run_native(
15 "WanderPad",
16 options,
17 Box::new(|cc| {
18 Box::<WanderPad>::default()
20 }),
21 )
22}
23
24struct WanderPad {
25 script: String,
26 result: String,
27}
28
29impl Default for WanderPad {
30 fn default() -> Self {
31 Self {
32 script: "".to_owned(),
33 result: "".to_owned(),
34 }
35 }
36}
37
38impl eframe::App for WanderPad {
39 fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
40 egui::CentralPanel::default().show(ctx, |ui| {
41 if ui.button("Run").clicked() {
42 let script = self.script.clone();
43 self.result = match run(&script, &mut common::<NoHostType>()) {
44 Ok(value) => value.to_string(),
45 Err(err) => err.0,
46 }
47 }
48 ui.text_edit_multiline(&mut self.script);
49 ui.label(&self.result);
50 });
51 }
52}