Add a responsive scaling for ui #73

Merged
raphael merged 11 commits from change-scaling into main 2024-03-09 17:24:22 +00:00
2 changed files with 13 additions and 11 deletions
Showing only changes of commit f0af5f4cfd - Show all commits

View file

@ -19,14 +19,3 @@ pub enum CurrentScene {
/// When we play this wonderful game.
Game,
}
/// Calculates the ui_scale.0 depending on the size of the main node
/// in order to make the screen responsive
pub fn change_scaling(mut ui_scale: ResMut<UiScale>, window: Query<&Window>) {
let window = window.single();
let (a, b) = (
window.resolution.width() / 1280.,
window.resolution.height() / 720.,
);
ui_scale.0 = if a < b { a } else { b } as f64
}

View file

@ -0,0 +1,13 @@
const DEFAULT_WIDTH = 1280.
const DEFAULT_HEIGHT = 720.
/// Calculates the ui_scale.0 depending on the size of the main node
/// in order to make the screen responsive
pub fn change_scaling(mut ui_scale: ResMut<UiScale>, window: Query<&Window>) {
let window = window.single();
let (a, b) = (
window.resolution.width() / DEFAULT_WIDTH,

You should put these constants in bevy's resources instead.
this can be changed in future settings.

You should put these constants in bevy's resources instead. this can be changed in future settings.
window.resolution.height() / DEFAULT_HEIGHT,
);
ui_scale.0 = if a < b { a } else { b } as f64
}