Skip to content

Commit

Permalink
restore the return type of window's width and height function
Browse files Browse the repository at this point in the history
* add back `logical_width` & `logical_height` so that code that wants full
  precision still has access, updated several places in engine that wanted
  `f32` to use these.
  • Loading branch information
Nathan Jeffords committed Dec 7, 2020
1 parent 2e44163 commit 7f2d68d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn camera_system<T: CameraProjection + Component>(
for (entity, mut camera, mut camera_projection) in queries.q0_mut().iter_mut() {
if let Some(window) = windows.get(camera.window) {
if changed_window_ids.contains(&window.id()) || added_cameras.contains(&entity) {
camera_projection.update(window.width(), window.height());
camera_projection.update(window.logical_width(), window.logical_height());
camera.projection_matrix = camera_projection.get_projection_matrix();
camera.depth_calculation = camera_projection.depth_calculation();
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/flex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ impl FlexSurface {
*node,
stretch::style::Style {
size: stretch::geometry::Size {
width: stretch::style::Dimension::Points(window.width()),
height: stretch::style::Dimension::Points(window.height()),
width: stretch::style::Dimension::Points(window.logical_width()),
height: stretch::style::Dimension::Points(window.logical_height()),
},
..Default::default()
},
Expand Down
14 changes: 12 additions & 2 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,22 @@ impl Window {
}

#[inline]
pub fn width(&self) -> f32 {
pub fn width(&self) -> u32 {
self.logical_width() as u32
}

#[inline]
pub fn height(&self) -> u32 {
self.logical_height() as u32
}

#[inline]
pub fn logical_width(&self) -> f32 {
(self.physical_width as f64 / self.scale_factor) as f32
}

#[inline]
pub fn height(&self) -> f32 {
pub fn logical_height(&self) -> f32 {
(self.physical_height as f64 / self.scale_factor) as f32
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ pub fn winit_runner(mut app: App) {
app.resources.get_mut::<Events<WindowResized>>().unwrap();
resize_events.send(WindowResized {
id: window_id,
height: window.height(),
width: window.width(),
height: window.logical_height(),
width: window.logical_width(),
});
}
WindowEvent::CloseRequested => {
Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn winit_runner(mut app: App) {

// FIXME?: On Android window start is top while on PC/Linux/OSX on bottom
if cfg!(target_os = "android") {
let window_height = windows.get_primary().unwrap().height();
let window_height = windows.get_primary().unwrap().logical_height();
location.y = window_height - location.y;
}
touch_input_events.send(converters::convert_touch_input(touch, location));
Expand Down

0 comments on commit 7f2d68d

Please sign in to comment.