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!
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
}
}