generated from tipragot/rust
Add a responsive scaling for ui #73
|
@ -19,3 +19,13 @@ pub enum CurrentScene {
|
|||
/// When we play this wonderful game.
|
||||
Game,
|
||||
}
|
||||
|
||||
/// Calculates the ui_scale.0 depending on the size of the main node
|
||||
CoCo_Sol marked this conversation as resolved
Outdated
|
||||
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
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_egui::EguiPlugin;
|
||||
|
||||
use crate::CurrentScene;
|
||||
use crate::{change_scaling, CurrentScene};
|
||||
|
||||
pub mod lobby;
|
||||
pub mod menu;
|
||||
|
@ -16,6 +16,7 @@ impl Plugin for ScenesPlugin {
|
|||
app.add_plugins(EguiPlugin)
|
||||
.add_state::<CurrentScene>()
|
||||
.add_plugins(menu::MenuPlugin)
|
||||
.add_plugins(lobby::LobbyPlugin);
|
||||
.add_plugins(lobby::LobbyPlugin)
|
||||
.add_systems(Update, change_scaling);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue
What is the main node?