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
|
|
@ -5,7 +5,7 @@ mod timeout;
|
|||
pub use self::canvas::Canvas;
|
||||
pub use self::timeout::Timeout;
|
||||
|
||||
use crate::dpi::LogicalSize;
|
||||
use crate::dpi::{LogicalSize, Size};
|
||||
use crate::platform::web::WindowExtStdweb;
|
||||
use crate::window::Window;
|
||||
|
||||
|
|
@ -41,6 +41,28 @@ pub fn window_size() -> LogicalSize<f64> {
|
|||
LogicalSize { width, height }
|
||||
}
|
||||
|
||||
pub fn hidpi_factor() -> f64 {
|
||||
let window = window();
|
||||
window.device_pixel_ratio()
|
||||
}
|
||||
|
||||
pub fn set_canvas_size(raw: &CanvasElement, size: Size) {
|
||||
use stdweb::*;
|
||||
|
||||
let hidpi_factor = hidpi_factor();
|
||||
|
||||
let physical_size = size.to_physical::<u32>(hidpi_factor);
|
||||
let logical_size = size.to_logical::<f64>(hidpi_factor);
|
||||
|
||||
raw.set_width(physical_size.width);
|
||||
raw.set_height(physical_size.height);
|
||||
|
||||
js! {
|
||||
@{raw.as_ref()}.style.width = @{logical_size.width} + "px";
|
||||
@{raw.as_ref()}.style.height = @{logical_size.height} + "px";
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_fullscreen(canvas: &CanvasElement) -> bool {
|
||||
match document().fullscreen_element() {
|
||||
Some(elem) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue