winio

Crates.iowinio
lib.rswinio
version
sourcesrc
created_at2024-09-26 17:39:20.141697
updated_at2024-11-21 16:59:21.195039
descriptionSingle-threaded async GUI runtime based on compio.
homepage
repositoryhttps://github.com/compio-rs/winio
max_upload_size
id1387868
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
王宇逸 (Berrysoft)

documentation

README

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
    }
}
Commit count: 253

cargo fmt