web: Emit WindowEvent::Resized on Window::set_inner_size (#1717)
* web: Allow event to be queued from inside the EventLoop handler The Runner is behind a RefCell, which is mutably borrowed when the event handler is being called. To queue events, `send_events` needs to check `is_closed()` and the `is_busy` flag, but it cannot be done since the RefCell is already locked. This commit changes the conditions to work without needing a successful borrow. * web: Emit WindowEvent::Resized on Window::set_inner_size * Update changelog
This commit is contained in:
parent
47e7aa4209
commit
644dc13e00
3 changed files with 42 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
|
||||
use crate::error::{ExternalError, NotSupportedError, OsError as RootOE};
|
||||
use crate::event;
|
||||
use crate::icon::Icon;
|
||||
use crate::monitor::MonitorHandle as RootMH;
|
||||
use crate::window::{CursorIcon, Fullscreen, WindowAttributes, WindowId as RootWI};
|
||||
|
|
@ -18,6 +19,7 @@ pub struct Window {
|
|||
previous_pointer: RefCell<&'static str>,
|
||||
id: Id,
|
||||
register_redraw_request: Box<dyn Fn()>,
|
||||
resize_notify_fn: Box<dyn Fn(PhysicalSize<u32>)>,
|
||||
destroy_fn: Option<Box<dyn FnOnce()>>,
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +40,14 @@ impl Window {
|
|||
|
||||
target.register(&mut canvas, id);
|
||||
|
||||
let runner = target.runner.clone();
|
||||
let resize_notify_fn = Box::new(move |new_size| {
|
||||
runner.send_event(event::Event::WindowEvent {
|
||||
window_id: RootWI(id),
|
||||
event: event::WindowEvent::Resized(new_size),
|
||||
});
|
||||
});
|
||||
|
||||
let runner = target.runner.clone();
|
||||
let destroy_fn = Box::new(move || runner.notify_destroy_window(RootWI(id)));
|
||||
|
||||
|
|
@ -46,13 +56,17 @@ impl Window {
|
|||
previous_pointer: RefCell::new("auto"),
|
||||
id,
|
||||
register_redraw_request,
|
||||
resize_notify_fn,
|
||||
destroy_fn: Some(destroy_fn),
|
||||
};
|
||||
|
||||
window.set_inner_size(attr.inner_size.unwrap_or(Size::Logical(LogicalSize {
|
||||
width: 1024.0,
|
||||
height: 768.0,
|
||||
})));
|
||||
backend::set_canvas_size(
|
||||
window.canvas.borrow().raw(),
|
||||
attr.inner_size.unwrap_or(Size::Logical(LogicalSize {
|
||||
width: 1024.0,
|
||||
height: 768.0,
|
||||
})),
|
||||
);
|
||||
window.set_title(&attr.title);
|
||||
window.set_maximized(attr.maximized);
|
||||
window.set_visible(attr.visible);
|
||||
|
|
@ -112,7 +126,12 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn set_inner_size(&self, size: Size) {
|
||||
let old_size = self.inner_size();
|
||||
backend::set_canvas_size(self.canvas.borrow().raw(), size);
|
||||
let new_size = self.inner_size();
|
||||
if old_size != new_size {
|
||||
(self.resize_notify_fn)(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue