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
905 downloads per month
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