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

winio

Single-threaded async GUI runtime based on compio

15 releases

0.3.1 Oct 28, 2024
0.3.0 Oct 21, 2024
0.2.3 Oct 10, 2024
0.1.8 Oct 4, 2024
0.1.5 Sep 30, 2024

#127 in GUI

Download history 804/week @ 2024-09-25 266/week @ 2024-10-02 565/week @ 2024-10-09 155/week @ 2024-10-16 158/week @ 2024-10-23 26/week @ 2024-10-30

905 downloads per month

MIT license

375KB
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