Skip to content

Commit

Permalink
make scale factor available from bevy_window
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Nov 29, 2020
1 parent 1fa488b commit 52373f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct Window {
#[cfg(target_arch = "wasm32")]
pub canvas: Option<String>,
command_queue: Vec<WindowCommand>,
scale_factor: f64,
}

#[derive(Debug)]
Expand Down Expand Up @@ -110,6 +111,7 @@ impl Window {
#[cfg(target_arch = "wasm32")]
canvas: window_descriptor.canvas.clone(),
command_queue: Vec::new(),
scale_factor: 1.0,
}
}

Expand Down Expand Up @@ -141,6 +143,16 @@ impl Window {
self.height = height;
}

#[doc(hidden)]
pub fn update_scale_factor_from_backend(&mut self, scale_factor: f64) {
self.scale_factor = scale_factor;
}

#[inline]
pub fn scale_factor(&self) -> f64 {
self.scale_factor
}

#[inline]
pub fn title(&self) -> &str {
&self.title
Expand Down
5 changes: 3 additions & 2 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ pub fn winit_runner(mut app: App) {
let window = windows.get_mut(window_id).unwrap();
let size = new_inner_size.to_logical(scale_factor);
window.update_resolution_from_backend(size.width, size.height);
window.update_scale_factor_from_backend(scale_factor);
}
_ => {}
},
Expand Down Expand Up @@ -344,8 +345,8 @@ fn handle_create_window_events(
let create_window_events = resources.get::<Events<CreateWindow>>().unwrap();
let mut window_created_events = resources.get_mut::<Events<WindowCreated>>().unwrap();
for create_window_event in create_window_event_reader.iter(&create_window_events) {
let window = Window::new(create_window_event.id, &create_window_event.descriptor);
winit_windows.create_window(event_loop, &window);
let mut window = Window::new(create_window_event.id, &create_window_event.descriptor);
winit_windows.create_window(event_loop, &mut window);
let window_id = window.id();
windows.add(window);
window_created_events.send(WindowCreated { id: window_id });
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl WinitWindows {
pub fn create_window(
&mut self,
event_loop: &winit::event_loop::EventLoopWindowTarget<()>,
window: &Window,
window: &mut Window,
) {
#[cfg(target_os = "windows")]
let mut winit_window_builder = {
Expand Down Expand Up @@ -100,6 +100,8 @@ impl WinitWindows {
}
}

window.update_scale_factor_from_backend(winit_window.scale_factor());

self.windows.insert(winit_window.id(), winit_window);
}

Expand Down

0 comments on commit 52373f9

Please sign in to comment.