 1477765f62
			
		
	
	
		1477765f62
		
	
	
	
	
		
			
			# Objective Enable the user to specify any presentation modes (including `Mailbox`). Fixes #3807 ## Solution I've added a new `PresentMode` enum in `bevy_window` that mirrors the `wgpu` enum 1:1. Alternatively, I could add a new dependency on `wgpu-types` if that would be preferred.
		
			
				
	
	
		
			64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use bevy::{prelude::*, window::PresentMode};
 | |
| 
 | |
| /// This example illustrates how to customize the default window settings
 | |
| fn main() {
 | |
|     App::new()
 | |
|         .insert_resource(WindowDescriptor {
 | |
|             title: "I am a window!".to_string(),
 | |
|             width: 500.,
 | |
|             height: 300.,
 | |
|             present_mode: PresentMode::Fifo,
 | |
|             ..Default::default()
 | |
|         })
 | |
|         .add_plugins(DefaultPlugins)
 | |
|         .add_system(change_title)
 | |
|         .add_system(toggle_cursor)
 | |
|         .add_system(cycle_cursor_icon)
 | |
|         .run();
 | |
| }
 | |
| 
 | |
| /// This system will then change the title during execution
 | |
| fn change_title(time: Res<Time>, mut windows: ResMut<Windows>) {
 | |
|     let window = windows.get_primary_mut().unwrap();
 | |
|     window.set_title(format!(
 | |
|         "Seconds since startup: {}",
 | |
|         time.seconds_since_startup().round()
 | |
|     ));
 | |
| }
 | |
| 
 | |
| /// This system toggles the cursor's visibility when the space bar is pressed
 | |
| fn toggle_cursor(input: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
 | |
|     let window = windows.get_primary_mut().unwrap();
 | |
|     if input.just_pressed(KeyCode::Space) {
 | |
|         window.set_cursor_lock_mode(!window.cursor_locked());
 | |
|         window.set_cursor_visibility(!window.cursor_visible());
 | |
|     }
 | |
| }
 | |
| 
 | |
| /// This system cycles the cursor's icon through a small set of icons when clicking
 | |
| fn cycle_cursor_icon(
 | |
|     input: Res<Input<MouseButton>>,
 | |
|     mut windows: ResMut<Windows>,
 | |
|     mut index: Local<usize>,
 | |
| ) {
 | |
|     const ICONS: &[CursorIcon] = &[
 | |
|         CursorIcon::Default,
 | |
|         CursorIcon::Hand,
 | |
|         CursorIcon::Wait,
 | |
|         CursorIcon::Text,
 | |
|         CursorIcon::Copy,
 | |
|     ];
 | |
|     let window = windows.get_primary_mut().unwrap();
 | |
|     if input.just_pressed(MouseButton::Left) {
 | |
|         *index = (*index + 1) % ICONS.len();
 | |
|         window.set_cursor_icon(ICONS[*index]);
 | |
|     } else if input.just_pressed(MouseButton::Right) {
 | |
|         *index = if *index == 0 {
 | |
|             ICONS.len() - 1
 | |
|         } else {
 | |
|             *index - 1
 | |
|         };
 | |
|         window.set_cursor_icon(ICONS[*index]);
 | |
|     }
 | |
| }
 |