#Is there any way to get the Window Scaling?
8 messages · Page 1 of 1 (latest)
You mean like the dpi scale? Should be on the Window component https://docs.rs/bevy/latest/bevy/window/struct.Window.html#method.scale_factor
The defining Component for window entities, storing information about how it should appear and behave.
Should you story it as a resource?
If you want to change it from the default use the below code when adding Bevy's DefaultPlugins (note it is auto detected, so usually it's already what you want)
use bevy::prelude::*;
fn main() {
let mut resolution = bevy::window::WindowResolution::new(1920,1080);
// Set this to be the dpi scale you want. 1.0 effectively disables display scaling making logical pixels 1 to 1 with your monitor's physical pixels.
.with_scale_factor_override(1.0);
let mut app = App::new();
app.add_plugins(DefaultPlugins.build().set(WindowPlugin{
primary_window: Some(Window{
resolution,
..default()
}),
..default()
})
app.run();
}
To get the value at runtime:
fn my_system(primary_window_query: Query<&Window, With<PrimaryWindow>){
let Ok(window) = primary_window_query.get_single() else {
// if for some reason we don't have a primary window, do nothing
return;
}
let scale_factor: f64 = window.scale_factor();
// do what you want with the scale factor
}
Is there a way to retrieve the dpi scaling value used but he os?
if you don't override it, the OS scaling value will be used
@sage cape you can retrieve it as described here