diff --git a/rust-learning/Cargo.toml b/rust-learning/Cargo.toml new file mode 100644 index 0000000..b77fc13 --- /dev/null +++ b/rust-learning/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "rust-learning" +version = "0.1.0" +edition = "2021" + +[dependencies] +eframe = "0.30.0" diff --git a/rust-learning/src/main.rs b/rust-learning/src/main.rs new file mode 100644 index 0000000..cc8931e --- /dev/null +++ b/rust-learning/src/main.rs @@ -0,0 +1,54 @@ +use eframe::egui; + +fn main() -> eframe::Result { + let options = eframe::NativeOptions { + viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]), + ..Default::default() + }; + + eframe::run_native( + "rust-learning", + options, + Box::new(|cc| Ok(Box::new(MyApp::new(cc)))), + ) +} + +struct MyApp { + counter: i32, +} + +impl MyApp { + fn new(_cc: &eframe::CreationContext<'_>) -> Self { + Self { counter: 0 } + } +} + +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + ui.heading("Hello eframe!"); + ui.label("This is a simple eframe app."); + + ui.horizontal(|ui| { + let counter_color = match self.counter { + 0 => egui::Color32::WHITE, + _ if self.counter > 0 => egui::Color32::GREEN, + _ => egui::Color32::RED, + }; + + ui.label("Counter:"); + ui.label(egui::RichText::new(format!("{}", self.counter)).color(counter_color)); + }); + + ui.horizontal(|ui| { + if ui.button("Increment").clicked() { + self.counter += 1; + } + + if ui.button("Decrement").clicked() { + self.counter -= 1; + } + }); + }); + } +}