Skip to content

Commit ad4f19a

Browse files
committed
add fullscreen button to desktop
1 parent 54ed0c5 commit ad4f19a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/lib.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#[cfg(target_arch = "wasm32")]
22
use wasm_bindgen::prelude::*;
33

4+
#[cfg(not(target_arch = "wasm32"))]
5+
use winit::window::Fullscreen;
6+
47
use egui::Color32;
58
use egui_wgpu_backend::{RenderPass, ScreenDescriptor};
69
use instant::{Duration, Instant};
@@ -534,6 +537,8 @@ impl State {
534537
self.prev_frame_time.as_micros() as f64 / 1000.0,
535538
1.0 / self.prev_frame_time.as_secs_f64()
536539
));
540+
#[cfg(not(target_arch = "wasm32"))]
541+
ui.label("Fullscreen: [F11]");
537542
ui.separator();
538543

539544
let settings_clone = self.settings.clone();
@@ -692,10 +697,11 @@ impl State {
692697
let screen_descriptor = ScreenDescriptor {
693698
physical_width: self.config.width,
694699
physical_height: self.config.height,
695-
#[cfg(target_arch = "wasm32")]
696-
scale_factor: window.scale_factor() as f32,
697-
#[cfg(not(target_arch = "wasm32"))]
698-
scale_factor: 1.0,
700+
scale_factor: if cfg!(target_arch = "wasm32") {
701+
window.scale_factor() as f32
702+
} else {
703+
1.0
704+
},
699705
};
700706

701707
let tdelta = full_output.textures_delta;
@@ -801,6 +807,26 @@ pub async fn run() {
801807
},
802808
..
803809
} => *control_flow = ControlFlow::Exit,
810+
#[cfg(not(target_arch = "wasm32"))]
811+
WindowEvent::KeyboardInput {
812+
input:
813+
KeyboardInput {
814+
state: ElementState::Pressed,
815+
virtual_keycode: Some(VirtualKeyCode::F11),
816+
..
817+
},
818+
..
819+
} => {
820+
if window.fullscreen().is_some() {
821+
window.set_fullscreen(None);
822+
} else {
823+
window.current_monitor().map(|monitor| {
824+
monitor.video_modes().next().map(|mode| {
825+
window.set_fullscreen(Some(Fullscreen::Exclusive(mode)));
826+
})
827+
});
828+
}
829+
}
804830
WindowEvent::Resized(physical_size) => state.resize(*physical_size),
805831
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
806832
state.resize(**new_inner_size)

0 commit comments

Comments
 (0)