実際のところ
tomlファイル
[package] name = "guiproject" version = "0.1.0" edition = "2021" [dependencies] eframe = "0.24.0"
スクリプト
use eframe::egui; fn main() -> Result<(), eframe::Error> { let options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default() .with_inner_size([200.0, 200.0]) .with_resizable(false), ..Default::default() }; eframe::run_native( "Counter", options, Box::new(|_cc| Box::new(CounterApp::default())), ) } struct CounterApp { count: i32, } impl Default for CounterApp { fn default() -> Self { Self { count: 0, } } } impl eframe::App for CounterApp { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { ui.add_space(50.0); ui.label(self.count.to_string()); ui.add_space(20.0); if ui.button("+1").clicked() { self.count += 1; } }); } }
実行結果
ボタンを押すとテキスト部が加算されます