Scale factor for smaller windows, move dialog box to top of screen

main
Elijah Voigt 4 months ago
parent 5c7e9eff20
commit 4b2c40ea85

@ -3,7 +3,7 @@
mod mono;
use bevy::color::palettes::css::{DARK_ORANGE, ORANGE};
use bevy::{color::palettes::css::{DARK_ORANGE, ORANGE}, window::WindowResized};
use games::*;
use mono::*;
@ -35,6 +35,7 @@ fn main() {
dialog_box_visibility.run_if(state_changed::<DialogState>),
monologue_asset_tooltip
.run_if(on_event::<Pointer<Over>>.or(on_event::<Pointer<Out>>)),
scale_window.run_if(on_event::<WindowResized>)
),
)
.add_observer(add_dialog_option)
@ -127,10 +128,10 @@ fn init_ui(mut commands: Commands) {
BackgroundColor(BLACK.with_alpha(0.9).into()),
DialogState::Ongoing,
Node {
align_self: AlignSelf::End,
align_self: AlignSelf::Start,
justify_self: JustifySelf::Center,
width: Val::Percent(98.0),
max_height: Val::Percent(25.0),
max_height: Val::Percent(50.0),
align_items: AlignItems::Center,
margin: UiRect::all(Val::Percent(1.0)),
padding: UiRect::all(Val::Percent(1.0)),
@ -485,3 +486,32 @@ fn remove_tree_monologue(
}
}
}
fn scale_window(events: EventReader<WindowResized>, mut window: Single<&mut Window>) {
debug_assert!(!events.is_empty(), "Only scale window when resized");
let r = &mut window.resolution;
let a: f32 = match r.physical_width() as usize {
0..=640 => 0.6,
641..=1280 => 1.0,
1281..=1920 => 1.6,
1921.. => 2.0,
};
let b: f32 = match r.physical_height() as usize {
0..=360 => 0.6,
361..=720 => 1.0,
721..=1080 => 1.6,
1081.. => 2.0,
};
let n = a.min(b);
r.set_scale_factor(n);
info!(
"Proposed scale factor: ({} -> {a} / {} -> {b}) {n}",
r.width(),
r.height(),
);
}

Loading…
Cancel
Save