Created a more scalable file structure with modular elements
This commit is contained in:
parent
07c1cb9ad5
commit
37360a24d6
15
src/app/mod.rs
Normal file
15
src/app/mod.rs
Normal file
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
9
src/app/ui/mod.rs
Normal file
9
src/app/ui/mod.rs
Normal file
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
28
src/main.rs
28
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);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user