Implement hidpi for web platform (#1233)
* fix: use a 'static lifetime for the web backend's `Event` types * implement hidpi for stdweb (web-sys wip?) * fix: make all canvas resizes go through backend::set_canvas_size * update Window docs for web, make `inner/outer_position` return the position in the viewport
This commit is contained in:
parent
28a20aec10
commit
777d9edeaa
11 changed files with 137 additions and 91 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use super::{backend, device, proxy::Proxy, runner, window};
|
||||
use crate::dpi::LogicalSize;
|
||||
use crate::dpi::{PhysicalSize, Size};
|
||||
use crate::event::{DeviceId, ElementState, Event, KeyboardInput, TouchPhase, WindowEvent};
|
||||
use crate::event_loop::ControlFlow;
|
||||
use crate::window::WindowId;
|
||||
|
|
@ -28,7 +28,7 @@ impl<T> WindowTarget<T> {
|
|||
Proxy::new(self.runner.clone())
|
||||
}
|
||||
|
||||
pub fn run(&self, event_handler: Box<dyn FnMut(Event<T>, &mut ControlFlow)>) {
|
||||
pub fn run(&self, event_handler: Box<dyn FnMut(Event<'static, T>, &mut ControlFlow)>) {
|
||||
self.runner.set_listener(event_handler);
|
||||
}
|
||||
|
||||
|
|
@ -170,25 +170,27 @@ impl<T> WindowTarget<T> {
|
|||
|
||||
let runner = self.runner.clone();
|
||||
let raw = canvas.raw().clone();
|
||||
let mut intended_size = LogicalSize {
|
||||
width: raw.width() as f64,
|
||||
height: raw.height() as f64,
|
||||
|
||||
// The size to restore to after exiting fullscreen.
|
||||
let mut intended_size = PhysicalSize {
|
||||
width: raw.width() as u32,
|
||||
height: raw.height() as u32,
|
||||
};
|
||||
canvas.on_fullscreen_change(move || {
|
||||
// If the canvas is marked as fullscreen, it is moving *into* fullscreen
|
||||
// If it is not, it is moving *out of* fullscreen
|
||||
let new_size = if backend::is_fullscreen(&raw) {
|
||||
intended_size = LogicalSize {
|
||||
width: raw.width() as f64,
|
||||
height: raw.height() as f64,
|
||||
intended_size = PhysicalSize {
|
||||
width: raw.width() as u32,
|
||||
height: raw.height() as u32,
|
||||
};
|
||||
|
||||
backend::window_size()
|
||||
backend::window_size().to_physical(backend::hidpi_factor())
|
||||
} else {
|
||||
intended_size
|
||||
};
|
||||
raw.set_width(new_size.width as u32);
|
||||
raw.set_height(new_size.height as u32);
|
||||
|
||||
backend::set_canvas_size(&raw, Size::Physical(new_size));
|
||||
runner.send_event(Event::WindowEvent {
|
||||
window_id: WindowId(id),
|
||||
event: WindowEvent::Resized(new_size),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue