You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ApplicationHandler API presents a problem for any application where a window is required before much can be done as you can't create a window until the first event, by which time you will have already created the struct to represent your application. This means you now have to use Option<T> to handle the possibility of no window at some point. The most sane way I have found to do this is to create my own separate application struct, which is stored as an Option<T> in the ApplicationHandler implementation and simply pass through all the events. This is somewhat messy, and not ideal.
As a solution, I would suggest changing how an event loop is started, the best way I can think of acomplishing this would be to introduce a new ApplicationHandler::init method, a rough overview of the idea is as follows:
structApplication{window:Window}implApplicationHandler<()>forApplication{typePassedData = String;// The addition of PassedData is to make it convenient to pass anything created before the event loop, any API wouldn't necessarily need this, but it would be a useful thing to have.fninit(event_loop:&ActiveEventLoop,passed_data:PassedData) -> Self{println!("{passed_data}");Self{window: event_loop.create_window(Window::default_attributes()).unwrap(),}}// *All other functions would be same as they are currently*}fnmain(){EventLoop::new().unwrap().run_app::<Application>(String::from("Hello World!")).unwrap();}
Relevant platforms
No response
The text was updated successfully, but these errors were encountered:
Description
The
ApplicationHandler
API presents a problem for any application where a window is required before much can be done as you can't create a window until the first event, by which time you will have already created the struct to represent your application. This means you now have to useOption<T>
to handle the possibility of no window at some point. The most sane way I have found to do this is to create my own separate application struct, which is stored as anOption<T>
in theApplicationHandler
implementation and simply pass through all the events. This is somewhat messy, and not ideal.As a solution, I would suggest changing how an event loop is started, the best way I can think of acomplishing this would be to introduce a new
ApplicationHandler::init
method, a rough overview of the idea is as follows:Relevant platforms
No response
The text was updated successfully, but these errors were encountered: