From 37360a24d6b9e7897d6e500da91a142ce482ed30 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sat, 3 Jun 2023 16:43:19 +0100 Subject: [PATCH] Created a more scalable file structure with modular elements --- src/app/mod.rs | 15 +++++++++++++++ src/app/ui/mod.rs | 9 +++++++++ src/main.rs | 28 +++++++--------------------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 src/app/mod.rs create mode 100644 src/app/ui/mod.rs diff --git a/src/app/mod.rs b/src/app/mod.rs new file mode 100644 index 0000000..8743037 --- /dev/null +++ b/src/app/mod.rs @@ -0,0 +1,15 @@ +mod ui; + +/// Stuct to store the state of the running application +pub struct App { + name: String +} + +impl Default for App { + /// Creates the default startup state for the app; + fn default() -> Self { + Self { + name: "Hello, World!".to_owned() + } + } +} \ No newline at end of file diff --git a/src/app/ui/mod.rs b/src/app/ui/mod.rs new file mode 100644 index 0000000..b76e0f5 --- /dev/null +++ b/src/app/ui/mod.rs @@ -0,0 +1,9 @@ +use crate::app::App; + +impl eframe::App for App { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::CentralPanel::default().show(ctx, |ui| { + ui.heading(&self.name); + }); + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 850e421..29866d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,38 +2,24 @@ use eframe::egui; +mod app; +use app::App; + fn main() -> Result<(), eframe::Error> { // Log to stdout (if you run with `RUST_LOG=debug`). tracing_subscriber::fmt::init(); + // Setup the options for the default window let options = eframe::NativeOptions { initial_window_size: Some(egui::vec2(150.0, 50.0)), resizable: false, ..Default::default() }; + + //Start rendering and run the application eframe::run_native( "egui-template", options, - Box::new(|_cc| Box::new(MyApp::default())), + Box::new(|_cc| Box::new(App::default())), ) -} - -struct MyApp { - name: String -} - -impl Default for MyApp { - fn default() -> Self { - Self { - name: "Hello, World!".to_owned() - } - } -} - -impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - egui::CentralPanel::default().show(ctx, |ui| { - ui.heading(&self.name); - }); - } } \ No newline at end of file