awita

Crates.ioawita
lib.rsawita
version0.2.3
sourcesrc
created_at2021-08-04 00:00:53.026588
updated_at2022-01-14 06:02:02.506298
descriptionAn asynchronous window library in Rust for Windows
homepage
repositoryhttps://github.com/LNSEAB/awita
max_upload_size
id431261
size111,129
LNSEAB (LNSEAB)

documentation

https://docs.rs/awita

README

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

Commit count: 79

cargo fmt