Add a responsive scaling that calculates the ui_scale.depending on the size of the main node
All checks were successful
Rust Checks / checks (push) Successful in 3m11s
Rust Checks / checks (pull_request) Successful in 1m56s

This commit is contained in:
Raphaël 2024-03-03 02:01:11 +01:00
parent 980bce2e08
commit 0775704b8e
2 changed files with 13 additions and 2 deletions

View file

@ -19,3 +19,13 @@ pub enum CurrentScene {
/// When we play this wonderful game. /// When we play this wonderful game.
Game, Game,
} }
/// Calculates the ui_scale.0 depending on the size of the main node
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

@ -3,7 +3,7 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_egui::EguiPlugin; use bevy_egui::EguiPlugin;
use crate::CurrentScene; use crate::{change_scaling, CurrentScene};
pub mod lobby; pub mod lobby;
pub mod menu; pub mod menu;
@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin {
app.add_plugins(EguiPlugin) app.add_plugins(EguiPlugin)
.add_state::<CurrentScene>() .add_state::<CurrentScene>()
.add_plugins(menu::MenuPlugin) .add_plugins(menu::MenuPlugin)
.add_plugins(lobby::LobbyPlugin); .add_plugins(lobby::LobbyPlugin)
.add_systems(Update, change_scaling);
} }
} }