synvael/crates/client/src/main.rs
Serkyo 9e56bccb05 feat(client): implement main event loop and tracing initialization
Added winit event loop with ControlFlow::Poll for continuous rendering, and initialized tracing-subscriber for standardized logging. Also integrated anyhow for robust error handling in the client binary.
2026-04-30 01:02:42 +02:00

58 lines
1.9 KiB
Rust

use anyhow::{Context, Result};
use tracing::info;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
use winit::window::{Window, WindowId};
#[derive(Default)]
struct App {
window: Option<Window>,
}
impl ApplicationHandler for App {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let attributes = Window::default_attributes()
.with_title("Project Catalyst");
self.window = Some(event_loop.create_window(attributes).unwrap());
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
event_loop.exit();
},
WindowEvent::RedrawRequested => {
// Redraw the application.
//
// It's preferable for applications that do not render continuously to render in
// this event rather than in AboutToWait, since rendering in here allows
// the program to gracefully handle redraws requested by the OS.
// Draw.
// Queue a RedrawRequested event.
//
// You only need to call this if you've determined that you need to redraw in
// applications which do not always need to. Applications that redraw continuously
// can render here instead.
self.window.as_ref().unwrap().request_redraw();
}
_ => (),
}
}
}
fn main() -> Result<()> {
tracing_subscriber::fmt().init();
info!("Starting Project Catalyst client");
let event_loop = EventLoop::new().context("Failed to create event loop")?;
event_loop.set_control_flow(ControlFlow::Poll);
let mut app = App::default();
event_loop.run_app(&mut app).context("Failed to run event loop")?;
Ok(())
}