2121use bevy:: {
2222 app:: { App , Plugin } ,
2323 asset:: Assets ,
24+ camera:: RenderTarget ,
2425 ecs:: query:: QueryEntityError ,
2526 math:: { IRect , IVec2 } ,
2627 prelude:: { Commands , Component , Entity , In , Query , ResMut , Window , With , default} ,
2728 render:: render_resource:: { Extent3d , TextureFormat } ,
2829 window:: {
2930 CompositeAlphaMode , Monitor , RawHandleWrapper , WindowLevel , WindowMode , WindowPosition ,
30- WindowResolution , WindowWrapper ,
31+ WindowRef , WindowResolution , WindowWrapper ,
3132 } ,
3233} ;
3334use raw_window_handle:: {
@@ -39,7 +40,7 @@ use processing_core::error::{self, ProcessingError, Result};
3940#[ cfg( not( target_os = "windows" ) ) ]
4041use std:: ptr:: NonNull ;
4142
42- use crate :: image:: Image ;
43+ use crate :: { graphics :: SurfaceSize , image:: Image } ;
4344
4445#[ derive( Component , Debug , Clone ) ]
4546pub struct Surface ;
@@ -394,7 +395,11 @@ pub fn destroy(
394395pub fn resize (
395396 In ( ( window_entity, width, height) ) : In < ( Entity , u32 , u32 ) > ,
396397 mut windows : Query < & mut Window > ,
398+ mut graphics_query : Query < ( & RenderTarget , & mut SurfaceSize ) > ,
397399) -> Result < ( ) > {
400+ let width = width. max ( 1 ) ;
401+ let height = height. max ( 1 ) ;
402+
398403 if let Ok ( mut window) = windows. get_mut ( window_entity) {
399404 let scale = window. resolution . scale_factor ( ) ;
400405 let physical_w = ( width as f32 * scale) as u32 ;
@@ -403,6 +408,15 @@ pub fn resize(
403408 . resolution
404409 . set_physical_resolution ( physical_w, physical_h) ;
405410 }
411+
412+ // SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize
413+ for ( target, mut surface_size) in graphics_query. iter_mut ( ) {
414+ if let RenderTarget :: Window ( WindowRef :: Entity ( surface) ) = * target {
415+ if surface == window_entity {
416+ * surface_size = SurfaceSize ( width, height) ;
417+ }
418+ }
419+ }
406420 Ok ( ( ) )
407421}
408422
@@ -448,6 +462,20 @@ pub fn physical_height(In(entity): In<Entity>, query: Query<&Window>) -> u32 {
448462 . unwrap_or ( 0 )
449463}
450464
465+ pub fn width ( In ( entity) : In < Entity > , query : Query < & Window > ) -> u32 {
466+ query
467+ . get ( entity)
468+ . map ( |w| w. resolution . width ( ) as u32 )
469+ . unwrap_or ( 0 )
470+ }
471+
472+ pub fn height ( In ( entity) : In < Entity > , query : Query < & Window > ) -> u32 {
473+ query
474+ . get ( entity)
475+ . map ( |w| w. resolution . height ( ) as u32 )
476+ . unwrap_or ( 0 )
477+ }
478+
451479pub fn set_title (
452480 In ( ( entity, title) ) : In < ( Entity , String ) > ,
453481 mut windows : Query < & mut Window > ,
0 commit comments