use astrelis_core::logging;
use astrelis_render::{Color, GraphicsContext, WindowContextDescriptor, WindowManager};
use astrelis_winit::{
FrameTime, WindowId,
app::{App, AppCtx, run_app},
event::EventBatch,
window::{WindowDescriptor, WinitPhysicalSize},
};
use std::collections::HashMap;
struct WindowManagerApp {
window_manager: WindowManager,
window_colors: HashMap<WindowId, Color>,
}
fn main() {
logging::init();
run_app(|ctx| {
let graphics_ctx =
GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
let mut window_manager = WindowManager::new(graphics_ctx);
let mut window_colors = HashMap::new();
let colors = [
Color::rgb(0.8, 0.2, 0.2), Color::rgb(0.2, 0.8, 0.2), Color::rgb(0.2, 0.2, 0.8), ];
for (i, color) in colors.iter().enumerate() {
let window_id = window_manager
.create_window_with_descriptor(
ctx,
WindowDescriptor {
title: format!("Window {} - WindowManager Demo", i + 1),
size: Some(WinitPhysicalSize::new(400.0, 300.0)),
..Default::default()
},
WindowContextDescriptor {
format: Some(wgpu::TextureFormat::Bgra8UnormSrgb),
..Default::default()
},
)
.expect("Failed to create window");
window_colors.insert(window_id, *color);
}
Box::new(WindowManagerApp {
window_manager,
window_colors,
})
});
}
impl App for WindowManagerApp {
fn update(&mut self, _ctx: &mut AppCtx, _time: &FrameTime) {
}
fn render(&mut self, _ctx: &mut AppCtx, window_id: WindowId, events: &mut EventBatch) {
let Some(&color) = self.window_colors.get(&window_id) else {
return;
};
self.window_manager
.render_window(window_id, events, |window, _events| {
let Some(frame) = window.begin_frame() else {
return; };
{
let _pass = frame
.render_pass()
.clear_color(color)
.label("window_manager_pass")
.build();
}
});
}
}