#windows #window #asynchronous #window-event #receiver #events #window-creation

awita

An asynchronous window library in Rust for Windows

13 releases

0.2.3 Jan 14, 2022
0.2.2 Nov 21, 2021
0.2.0 Oct 29, 2021
0.1.1 Oct 4, 2021
0.0.3 Aug 13, 2021

#14 in #window-event

35 downloads per month

MIT license

86KB
2.5K SLoC

awita

awita at crates.io awita at docs.rs

An asynchronous window library for Windows

Overview

"awita" is an asynchronous window creation and management library for Windows. A window event can be received asynchronously using a receiver.

Examples

Waiting event loop

#[tokio::main]
async main() {
    let window = awita::Window::builder()
        .title("awita hello")
        .build()
        .await
        .unwrap();
    let mut closed = window.closed_receiver().await;
    loop {
        tokio::select! {
            Ok(_) = closed.recv() => println!("closed"),
            _ = awita::UiThread::join() => break,
        }
    }
    awita::UiThread::maybe_unwind().await;
}

Non-waiting event loop

#[tokio::main]
async fn main() {
    let window = awita::Window::builder()
        .title("await non_waiting")
        .build()
        .await
        .unwrap();
    let mut resized = window.resized_receiver().await;
    let mut closed = window.closed_receiver().await;
    tokio::spawn(async move {
        loop {
            tokio::select! {
                Ok(_) = closed.recv() => println!("closed"),
                _ = awita::UiThread::join() => break,
            }
        }
    });
    tokio::task::spawn_blocking(move || {
        while awita::UiThread::is_running() {
            // For example, write a rendering code.

            if let Ok(Some(size)) = resized.try_recv() {
                println!("resized: ({}, {})", size.width, size.height);
            }
        }
    })
    .await?;
    awita::UiThread::maybe_unwind().await;
}

License

MIT license


Copyright (c) 2021 LNSEAB

Dependencies

~134MB
~2M SLoC