Hi,
I'm trying to write simple winit
app. Here is a part of the code. window_manager
contains a vector of virtual windows that are drawn in a winit
window as rectangles.
struct MyApp<'a> {
window: Option<Arc<Window>>,
window_mananger: window_manager::WindowManager<'a>,
}
const WIDTH: i32 = 1280;
const HEIGHT: i32 = 720;
impl<'a> ApplicationHandler for MyApp<'a> {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
let window_attributes = Window::default_attributes().with_inner_size(PhysicalSize::new(WIDTH, HEIGHT));
let window = event_loop.create_window(window_attributes).unwrap();
self.window_mananger.create_window(640, 360, (-25, -25));
self.window_mananger.create_window(640, 360, (665, -25));
self.window_mananger.create_window(640, 360, (-25, 385));
self.window_mananger.create_window(640, 360, (665, 385));
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => {
println!("The close button was pressed; stopping");
event_loop.exit();
},
...
WindowEvent::CursorMoved { position, .. } => {
let window = self.window_mananger.find_window(position.x, position.y as i32);
}
_ => (),
}
}
}
The compiler tells:
lifetime may not live long enough
argument requires that `'1` must outlive `'a`
for the line:
let window = self.window_mananger.find_window(position.x, position.y as i32);
I think I understand what it means. I have to specify a lifetime for &mut self
in window_event
method. But if I set the lifetime for this parameter, the compiler says:
method not compatible with trait
expected signature `fn(&mut MyApp<'_>, &ActiveEventLoop, WindowId, winit::event::WindowEvent)`
found signature `fn(&'a mut MyApp<'_>, &ActiveEventLoop, WindowId, winit::event::WindowEvent)
Is the problem with my abstractions or or is this a limitation of winit
? Is there any workaround for this?