#async #single-threaded #run-time #compio #gtk #cocoa

winio

Single-threaded async GUI runtime based on compio

16 releases

new 0.3.2 Nov 21, 2024
0.3.1 Oct 28, 2024
0.2.3 Oct 10, 2024
0.1.8 Oct 4, 2024
0.1.5 Sep 30, 2024

#157 in GUI

Download history 248/week @ 2024-09-23 815/week @ 2024-09-30 551/week @ 2024-10-07 34/week @ 2024-10-14 174/week @ 2024-10-21 152/week @ 2024-10-28 150/week @ 2024-11-18

307 downloads per month

MIT license

385KB
11K SLoC

Winio

Winio is a single-threaded asynchronous GUI runtime. It is based on compio, and the GUI part is powered by Win32, Qt, GTK and Cocoa. All IO requests could be issued in the same thread as GUI, without blocking the user interface!

Quick start

Winio follows ELM-like design, inspired by yew and relm4. The application starts with a root Component:

struct MainModel {
    window: Child<Window>,
}

enum MainMessage {
    Close,
}

impl Component for MainModel {
    type Event = ();
    type Init = ();
    type Message = MainMessage;
    type Root = ();

    fn init(_counter: Self::Init, _root: &Self::Root, sender: &ComponentSender<Self>) -> Self {
        // create & initialize the window
        let mut window = Child::<Window>::init((), &());
        window.set_text("Basic example");
        window.set_size(Size::new(800.0, 600.0));
        Self { window }
    }

    async fn start(&mut self, sender: &ComponentSender<Self>) {
        // listen to events
        self.window
            .start(sender, |e| match e {
                WindowEvent::Close => Some(MainMessage::Close),
                _ => None,
            })
            .await;
    }

    async fn update(&mut self, message: Self::Message, sender: &ComponentSender<Self>) -> bool {
        // update the window
        self.window.update().await;
        // deal with custom messages
        match message {
            MainMessage::Close => {
                // the root component output stops the application
                sender.output(());
                // need not to call `render`
                false
            }
        }
    }

    fn render(&mut self, _sender: &ComponentSender<Self>) {
        // adjust layout and draw widgets here
    }
}

Dependencies

~5–51MB
~848K SLoC