diff options
Diffstat (limited to 'console/src/gui')
| -rw-r--r-- | console/src/gui/controller_app.rs | 38 | ||||
| -rw-r--r-- | console/src/gui/mod.rs | 1 |
2 files changed, 39 insertions, 0 deletions
diff --git a/console/src/gui/controller_app.rs b/console/src/gui/controller_app.rs new file mode 100644 index 0000000..d8325b1 --- /dev/null +++ b/console/src/gui/controller_app.rs @@ -0,0 +1,38 @@ +pub struct MyApp { + show_hello: bool, // 控制是否显示 "Hello World!" +} + +impl Default for MyApp { + fn default() -> Self { + Self { show_hello: false } + } +} + +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + // 添加一个按钮 + if ui.button("Click me!").clicked() { + self.show_hello = !self.show_hello; // 切换状态 + } + + // 如果按钮被点击过,显示 "Hello World!" + if self.show_hello { + ui.label("Hello World!"); + } + }); + } +} + +impl MyApp { + pub fn start () { + let options = eframe::NativeOptions::default(); + let _ = eframe::run_native( + "My egui App", + options, + Box::new(|_cc| { + Ok(Box::<MyApp>::default()) + }), + ); + } +}
\ No newline at end of file diff --git a/console/src/gui/mod.rs b/console/src/gui/mod.rs new file mode 100644 index 0000000..5e7124a --- /dev/null +++ b/console/src/gui/mod.rs @@ -0,0 +1 @@ +pub mod controller_app;
\ No newline at end of file |
