Fix return_after_run example (#6420)
# Objective - Fixes #6311 - Make it clearer what should be done in the example (close the Bevy app window) ## Solution - Remove the second windowed Bevy App [since winit does not support this](https://github.com/rust-windowing/winit/blob/v0.27.4/src/event_loop.rs#L82-L83) - Add title to the Bevy window asking the user to close it This is more of a quick fix to have a working example. It would be nicer if we had a small real usecase for this functionality. Another alternativ that I tried out: If we want to showcase a second Bevy app as it was before, we could still do this as long as one of them does not have a window. But I don't see how this is helpful in the context of the example, so I stuck with only one Bevy app and a simple print afterwards.
This commit is contained in:
		
							parent
							
								
									bb968f41bc
								
							
						
					
					
						commit
						558859691e
					
				@ -54,7 +54,7 @@ pub struct WindowPlugin {
 | 
				
			|||||||
    /// create 'headless' processes (processes without windows), which may
 | 
					    /// create 'headless' processes (processes without windows), which may
 | 
				
			||||||
    /// surprise your users. It is recommended to leave this setting as `true`.
 | 
					    /// surprise your users. It is recommended to leave this setting as `true`.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// If true, this plugin will add [`exit_on_all_closed`] to [`CoreStage::Update`].
 | 
					    /// If true, this plugin will add [`exit_on_all_closed`] to [`CoreStage::PostUpdate`].
 | 
				
			||||||
    pub exit_on_all_closed: bool,
 | 
					    pub exit_on_all_closed: bool,
 | 
				
			||||||
    /// Whether to close windows when they are requested to be closed (i.e.
 | 
					    /// Whether to close windows when they are requested to be closed (i.e.
 | 
				
			||||||
    /// when the close button is pressed).
 | 
					    /// when the close button is pressed).
 | 
				
			||||||
 | 
				
			|||||||
@ -3,33 +3,24 @@
 | 
				
			|||||||
use bevy::{prelude::*, winit::WinitSettings};
 | 
					use bevy::{prelude::*, winit::WinitSettings};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn main() {
 | 
					fn main() {
 | 
				
			||||||
    println!("Running first App.");
 | 
					    println!("Running Bevy App");
 | 
				
			||||||
    App::new()
 | 
					    App::new()
 | 
				
			||||||
        .insert_resource(WinitSettings {
 | 
					        .insert_resource(WinitSettings {
 | 
				
			||||||
            return_from_run: true,
 | 
					            return_from_run: true,
 | 
				
			||||||
            ..default()
 | 
					            ..default()
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .insert_resource(ClearColor(Color::rgb(0.2, 0.2, 0.8)))
 | 
					        .add_plugins(DefaultPlugins.set(WindowPlugin {
 | 
				
			||||||
        .add_plugins(DefaultPlugins)
 | 
					            window: WindowDescriptor {
 | 
				
			||||||
        .add_system(system1)
 | 
					                title: "Close the window to return to the main function".to_owned(),
 | 
				
			||||||
        .run();
 | 
					                ..default()
 | 
				
			||||||
    println!("Running another App.");
 | 
					            },
 | 
				
			||||||
    App::new()
 | 
					 | 
				
			||||||
        .insert_resource(WinitSettings {
 | 
					 | 
				
			||||||
            return_from_run: true,
 | 
					 | 
				
			||||||
            ..default()
 | 
					            ..default()
 | 
				
			||||||
        })
 | 
					        }))
 | 
				
			||||||
        .insert_resource(ClearColor(Color::rgb(0.2, 0.8, 0.2)))
 | 
					        .add_system(system)
 | 
				
			||||||
        .add_plugins(DefaultPlugins.build().disable::<bevy::log::LogPlugin>())
 | 
					 | 
				
			||||||
        .add_system(system2)
 | 
					 | 
				
			||||||
        .run();
 | 
					        .run();
 | 
				
			||||||
    println!("Done.");
 | 
					    println!("Bevy App has exited. We are back in our main function.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn system1() {
 | 
					fn system() {
 | 
				
			||||||
    info!("logging from first app");
 | 
					    info!("Logging from Bevy App");
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn system2() {
 | 
					 | 
				
			||||||
    info!("logging from second app");
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user