Skip to content

Commit 55d85bc

Browse files
author
Nathan Jeffords
committed
update Window's width & height methods to return f32
also removes `logical_width` & `logical_height` as they are not longer different
1 parent 3d386a7 commit 55d85bc

File tree

6 files changed

+15
-25
lines changed

6 files changed

+15
-25
lines changed

crates/bevy_render/src/camera/camera.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn camera_system<T: CameraProjection + Component>(
7878
for (entity, mut camera, mut camera_projection) in queries.q0_mut().iter_mut() {
7979
if let Some(window) = windows.get(camera.window) {
8080
if changed_window_ids.contains(&window.id()) || added_cameras.contains(&entity) {
81-
camera_projection.update(window.logical_width(), window.logical_height());
81+
camera_projection.update(window.width(), window.height());
8282
camera.projection_matrix = camera_projection.get_projection_matrix();
8383
camera.depth_calculation = camera_projection.depth_calculation();
8484
}

crates/bevy_ui/src/flex/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ impl FlexSurface {
116116
*node,
117117
stretch::style::Style {
118118
size: stretch::geometry::Size {
119-
width: stretch::style::Dimension::Points(window.logical_width()),
120-
height: stretch::style::Dimension::Points(window.logical_height()),
119+
width: stretch::style::Dimension::Points(window.width()),
120+
height: stretch::style::Dimension::Points(window.height()),
121121
},
122122
..Default::default()
123123
},

crates/bevy_window/src/window.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,12 @@ impl Window {
126126
}
127127

128128
#[inline]
129-
pub fn width(&self) -> u32 {
130-
self.logical_width() as u32
131-
}
132-
133-
#[inline]
134-
pub fn height(&self) -> u32 {
135-
self.logical_height() as u32
136-
}
137-
138-
#[inline]
139-
pub fn logical_width(&self) -> f32 {
129+
pub fn width(&self) -> f32 {
140130
(self.physical_width as f64 / self.scale_factor) as f32
141131
}
142132

143133
#[inline]
144-
pub fn logical_height(&self) -> f32 {
134+
pub fn height(&self) -> f32 {
145135
(self.physical_height as f64 / self.scale_factor) as f32
146136
}
147137

@@ -161,7 +151,7 @@ impl Window {
161151
.push(WindowCommand::SetMaximized { maximized });
162152
}
163153

164-
pub fn set_resolution(&mut self, width: u32, height: u32) {
154+
pub fn set_resolution(&mut self, width: f32, height: f32) {
165155
self.physical_width = (width as f64 * self.scale_factor) as u32;
166156
self.physical_height = (height as f64 * self.scale_factor) as u32;
167157
self.command_queue.push(WindowCommand::SetResolution {

crates/bevy_winit/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ pub fn winit_runner(mut app: App) {
210210
app.resources.get_mut::<Events<WindowResized>>().unwrap();
211211
resize_events.send(WindowResized {
212212
id: window_id,
213-
height: window.logical_height(),
214-
width: window.logical_width(),
213+
height: window.height(),
214+
width: window.width(),
215215
});
216216
}
217217
WindowEvent::CloseRequested => {
@@ -309,7 +309,7 @@ pub fn winit_runner(mut app: App) {
309309

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

examples/2d/contributors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ fn collision_system(
237237

238238
let win = wins.get_primary().unwrap();
239239

240-
let ceiling = win.logical_height() / 2.;
241-
let ground = -(win.logical_height() / 2.);
240+
let ceiling = win.height() / 2.;
241+
let ground = -(win.height() / 2.);
242242

243-
let wall_left = -(win.logical_width() / 2.);
244-
let wall_right = win.logical_width() / 2.;
243+
let wall_left = -(win.width() / 2.);
244+
let wall_right = win.width() / 2.;
245245

246246
for (mut v, mut t) in q.iter_mut() {
247247
let left = t.translation.x - SPRITE_SIZE / 2.0;

examples/ecs/parallel_query.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ fn bounce_system(
4848
mut sprites: Query<(&Transform, &mut Velocity)>,
4949
) {
5050
let window = windows.get_primary().expect("No primary window.");
51-
let width = window.logical_width();
52-
let height = window.logical_height();
51+
let width = window.width();
52+
let height = window.height();
5353
let left = width / -2.0;
5454
let right = width / 2.0;
5555
let bottom = height / -2.0;

0 commit comments

Comments
 (0)