diff --git a/examples/window.rs b/examples/window.rs index d3775fe..bb22f95 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -2,9 +2,20 @@ use games::*; fn main() { App::new() - .add_plugins(BaseGamePlugin { target_resolution: (360.0, 640.0).into(), ..default() }) + .add_plugins(BaseGamePlugin { + target_resolution: (360.0, 640.0).into(), + resize_constraints: WindowResizeConstraints { + max_height: 1080.0, + min_height: 640.0, + ..default() + }, + ..default() + }) .add_systems(Startup, init_window_info) - .add_systems(Update, update_window_info.run_if(any_component_changed::)) + .add_systems( + Update, + update_window_info.run_if(any_component_changed::), + ) .run(); } diff --git a/src/base_game.rs b/src/base_game.rs index 05f493e..201b32b 100644 --- a/src/base_game.rs +++ b/src/base_game.rs @@ -6,6 +6,7 @@ pub struct BaseGamePlugin { pub name: String, pub game_type: GameType, pub target_resolution: WindowResolution, + pub resize_constraints: WindowResizeConstraints, } pub enum GameType { @@ -20,6 +21,7 @@ impl Default for BaseGamePlugin { name: "mygame".into(), game_type: GameType::Three, target_resolution: WindowResolution::default(), + resize_constraints: WindowResizeConstraints::default(), } } } @@ -32,6 +34,7 @@ impl Plugin for BaseGamePlugin { primary_window: Some(Window { fit_canvas_to_parent: true, resolution: self.target_resolution.clone(), + resize_constraints: self.resize_constraints.clone(), ..default() }), ..default() diff --git a/src/debug.rs b/src/debug.rs index 573f07a..153be82 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -13,6 +13,7 @@ impl Plugin for DebuggingPlugin { .init_resource::() .init_resource::() .init_resource::() + .init_resource::() .init_resource::() .add_systems(Startup, init_debug_ui) .add_systems( @@ -33,7 +34,9 @@ impl Plugin for DebuggingPlugin { track_fps, sync_resource_to_ui::.run_if(resource_changed::), track_entity_count, + track_window_info.run_if(any_component_changed::), sync_resource_to_ui::.run_if(resource_changed::), + sync_resource_to_ui::.run_if(resource_changed::), sync_resource_to_ui::.run_if(resource_changed::), ) .run_if(in_state(DebuggingState::On)), @@ -170,6 +173,15 @@ fn init_debug_ui(mut commands: Commands) { TextColor(BLACK.into()), SyncResource::::default(), )); + parent.spawn(( + // Window info + DebuggingState::On, + Name::new("Window Info"), + GlobalZIndex(i32::MAX - 1), + Text::new("Window Info..."), + TextColor(BLACK.into()), + SyncResource::::default(), + )); }); // Tooltip @@ -492,6 +504,33 @@ fn track_entity_count(query: Query, mut count: ResMut) { count.0 = query.iter().len(); } +#[derive(Resource, Default, Debug)] +struct WindowInfo { + logical_size: (f32, f32), + physical_size: (f32, f32), + scale_factor: f32, + mode: String, +} + +impl Display for WindowInfo { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + writeln!( + f, + "Res (Logi): {:?}\nRes (Phys): {:?}\nWindow Scale: {}\nWindow Mode: {}", + self.logical_size, self.physical_size, self.scale_factor, self.mode + ) + } +} + +fn track_window_info(window: Single<&Window>, mut info: ResMut) { + (info.logical_size.0, info.logical_size.1) = + (window.resolution.size().x, window.resolution.size().y); + (info.physical_size.0, info.physical_size.1) = + (window.resolution.size().x, window.resolution.size().y); + info.scale_factor = window.resolution.scale_factor(); + info.mode = format!("{:?}", window.mode); +} + /// Toggle the debug state when a button is clicked fn toggle_debug( _trigger: Trigger>, diff --git a/src/lib.rs b/src/lib.rs index 8abbec8..4877358 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ pub use std::fmt::Display; // Community libraries pub use bevy::{ - asset::{AssetLoader, LoadContext, LoadState, LoadedFolder, io::Reader, AssetMetaCheck}, + asset::{AssetLoader, AssetMetaCheck, LoadContext, LoadState, LoadedFolder, io::Reader}, color::palettes::css::*, gizmos::{aabb::AabbGizmoPlugin, light::LightGizmoPlugin}, input::{