Skip to main content

simple_app/
simple-app.rs

1use neuton::*;
2use std::path::PathBuf;
3
4struct MyApp {
5    color: u8,
6}
7
8impl MyApp {
9    fn new() -> Self {
10        Self { color: 0 }
11    }
12}
13
14impl AppBehavior for MyApp {
15    fn on_update(&mut self, _dt: f64) {
16        self.color = self.color.wrapping_add(1);
17    }
18
19    fn on_event(&mut self, event: &Event) {
20        if let Event::KeyDown { .. } = event {
21            log!(trace, "Key pressed, current color value: {}", self.color);
22        } else if let Event::MouseButtonDown { .. } = event {
23            log!(
24                trace,
25                "Mouse button pressed, current color value: {}",
26                self.color
27            );
28        }
29    }
30
31    fn on_render(&mut self, canvas: &mut Canvas<Window>) {
32        canvas.set_draw_color(Color::RGB(self.color / 2, self.color / 2, self.color));
33    }
34}
35
36fn main() -> NeutonResult<()> {
37    let config = AppConfig {
38        app_name: "Example App".to_string(),
39        window_width: 3560,
40        window_height: 1440,
41        fullscreen: false,
42        vsync: true,
43        max_fps: Some(60),
44        log_directory: Some(PathBuf::from("/tmp")),
45    };
46
47    init_logger(config.log_directory.as_deref())?;
48
49    Application::new(config, MyApp::new())?.run()
50}