-
Notifications
You must be signed in to change notification settings - Fork 11
Fix window resize stretching the canvas instead of resizing the sketch surface (#127) #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
d56013b
a02f34f
9edce91
5ea6f2a
ac28b29
02d60e7
b2ad130
ee7f14c
141b1be
b689301
e30801c
807df63
ff87398
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,13 +21,14 @@ | |
| use bevy::{ | ||
| app::{App, Plugin}, | ||
| asset::Assets, | ||
| camera::RenderTarget, | ||
| ecs::query::QueryEntityError, | ||
| math::{IRect, IVec2}, | ||
| prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default}, | ||
| render::render_resource::{Extent3d, TextureFormat}, | ||
| window::{ | ||
| CompositeAlphaMode, Monitor, RawHandleWrapper, WindowLevel, WindowMode, WindowPosition, | ||
| WindowResolution, WindowWrapper, | ||
| WindowRef, WindowResolution, WindowWrapper, | ||
| }, | ||
| }; | ||
| use raw_window_handle::{ | ||
|
|
@@ -39,7 +40,7 @@ use processing_core::error::{self, ProcessingError, Result}; | |
| #[cfg(not(target_os = "windows"))] | ||
| use std::ptr::NonNull; | ||
|
|
||
| use crate::image::Image; | ||
| use crate::{graphics::SurfaceSize, image::Image}; | ||
|
|
||
| #[derive(Component, Debug, Clone)] | ||
| pub struct Surface; | ||
|
|
@@ -394,7 +395,11 @@ pub fn destroy( | |
| pub fn resize( | ||
| In((window_entity, width, height)): In<(Entity, u32, u32)>, | ||
| mut windows: Query<&mut Window>, | ||
| mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize)>, | ||
| ) -> Result<()> { | ||
| let width = width.max(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so width and height are clamped between 0 and 1?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let width = width.max(1);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arrxy i'm asking about 1. what is the significance there?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh I put the min limit 1, so that the box cannot be shrinked to nothing. |
||
| let height = height.max(1); | ||
|
|
||
| if let Ok(mut window) = windows.get_mut(window_entity) { | ||
| let scale = window.resolution.scale_factor(); | ||
| let physical_w = (width as f32 * scale) as u32; | ||
|
|
@@ -403,6 +408,15 @@ pub fn resize( | |
| .resolution | ||
| .set_physical_resolution(physical_w, physical_h); | ||
| } | ||
|
|
||
| // SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize | ||
| for (target, mut surface_size) in graphics_query.iter_mut() { | ||
| if let RenderTarget::Window(WindowRef::Entity(surface)) = *target | ||
| && surface == window_entity | ||
| { | ||
| *surface_size = SurfaceSize(width, height); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -448,6 +462,20 @@ pub fn physical_height(In(entity): In<Entity>, query: Query<&Window>) -> u32 { | |
| .unwrap_or(0) | ||
| } | ||
|
|
||
| pub fn width(In(entity): In<Entity>, query: Query<&Window>) -> u32 { | ||
| query | ||
| .get(entity) | ||
| .map(|w| w.resolution.width() as u32) | ||
| .unwrap_or(0) | ||
| } | ||
|
|
||
| pub fn height(In(entity): In<Entity>, query: Query<&Window>) -> u32 { | ||
| query | ||
| .get(entity) | ||
| .map(|w| w.resolution.height() as u32) | ||
| .unwrap_or(0) | ||
| } | ||
|
|
||
| pub fn set_title( | ||
| In((entity, title)): In<(Entity, String)>, | ||
| mut windows: Query<&mut Window>, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this TODO can be removed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed