generated from tipragot/rust
Add a responsive scaling for ui #73
|
@ -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
|
||||
}
|
||||
|
|
13
crates/border-wars/src/responsive_scale.rs
Normal file
13
crates/border-wars/src/responsive_scale.rs
Normal 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,
|
||||
|
||||
window.resolution.height() / DEFAULT_HEIGHT,
|
||||
);
|
||||
ui_scale.0 = if a < b { a } else { b } as f64
|
||||
}
|
Loading…
Reference in a new issue
You should put these constants in bevy's resources instead.
this can be changed in future settings.