js_resized_event_channel

Crates.iojs_resized_event_channel
lib.rsjs_resized_event_channel
version0.1.9
sourcesrc
created_at2024-10-12 03:50:18.541742
updated_at2024-10-12 15:14:09.809401
descriptionjs resized event channel
homepage
repositoryhttps://github.com/Bruce0203/js_resized_event_channel
max_upload_size
id1406105
size4,765
(Bruce0203)

documentation

README


use js_resized_event_channel::JsResizeEventChannel;
use winit::{dpi::PhysicalSize, event_loop::EventLoop, window::WindowAttributes};

fn main() {
    let web_window = web_sys::window().unwrap();
    let event_loop: EventLoop<()> = EventLoop::builder().build().unwrap();
    let window = event_loop
        .create_window(WindowAttributes::default())
        .unwrap();
    let resize_event_channel = JsResizeEventChannel::init(
        &window,
        web_window
            .document()
            .unwrap()
            .get_element_by_id("container")
            .unwrap(),
    );
    event_loop
        .run(|_, _| {
            if resize_event_channel.try_recv_resized_event() {
                let _ = window.request_inner_size(PhysicalSize {
                    width: web_window.inner_width().unwrap().as_f64().unwrap() as u32 * 2,
                    height: web_window.inner_height().unwrap().as_f64().unwrap() as u32 * 2,
                });
            }
        })
        .unwrap();
}
Commit count: 19

cargo fmt