From 4b2c40ea850734dcf72749e9645865ce6ed30f4b Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 8 Jul 2025 14:38:34 -0700 Subject: [PATCH] Scale factor for smaller windows, move dialog box to top of screen --- src/bin/trees/main.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index 017e09c..0a986ff 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -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::), monologue_asset_tooltip .run_if(on_event::>.or(on_event::>)), + scale_window.run_if(on_event::) ), ) .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, 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(), + ); +}