Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "winio"
version = "0.6.1"
version = "0.7.0"
edition = "2021"
description = "Single-threaded async GUI runtime based on compio."
license = "MIT"
Expand Down Expand Up @@ -180,7 +180,6 @@ objc-static = [
"objc2/unstable-static-sel-inlined",
"objc2-foundation/unstable-static-nsstring",
]
clang-lto = []

[profile.release]
lto = true
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use winio::{
};

fn main() {
App::new().run::<MainModel>(());
App::new("rs.compio.winio.example").run::<MainModel>(());
}

struct MainModel {
Expand All @@ -34,25 +34,24 @@ impl Component for MainModel {

fn init(_init: Self::Init<'_>, _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));
init! {
window: Window = (()) => {
text: "Basic example",
size: Size::new(800.0, 600.0),
}
}
window.show();
Self { window }
}

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

async fn update(&mut self, message: Self::Message, sender: &ComponentSender<Self>) -> bool {
Expand All @@ -71,6 +70,7 @@ impl Component for MainModel {
}

fn render(&mut self, _sender: &ComponentSender<Self>) {
self.window.render();
// adjust layout and draw widgets here
}
}
Expand Down
14 changes: 10 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ fn main() {
qt_build_utils::QtBuild::new(vec!["Core".into(), "Gui".into(), "Widgets".into()])
.unwrap();

let major = qbuild.version().major;
if major != 5 && major != 6 {
panic!("Unsupported Qt version: {major}");
}
println!("cargo::rustc-check-cfg=cfg(qtver, values(\"5\", \"6\"))");
println!("cargo::rustc-cfg=qtver=\"{major}\"");

let sources = [
"src/runtime/qt",
"src/ui/qt/common",
"src/ui/qt/widget",
"src/ui/qt/monitor",
"src/ui/qt/msgbox",
Expand All @@ -44,10 +52,8 @@ fn main() {
build
.std("c++17")
.files(sources.map(|s| format!("{s}.cpp")))
.includes(inc);
if cfg!(feature = "clang-lto") && std::env::var("PROFILE").as_deref() == Ok("release") {
build.flag("-flto").compiler("clang++");
}
.includes(inc)
.cpp(true);
qbuild.cargo_link_libraries(&mut build);
build.compile("winio");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>(0usize);
App::new("rs.compio.winio.basic").run::<MainModel>(0usize);
}

struct MainModel {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Component for MainModel {
}
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
Expand Down
4 changes: 2 additions & 2 deletions examples/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>("Cargo.toml")
App::new("rs.compio.winio.fs").run::<MainModel>("Cargo.toml")
}

struct MainModel {
Expand Down Expand Up @@ -79,7 +79,7 @@ impl Component for MainModel {
}
}

async fn start(&mut self, sender: &winio::ComponentSender<Self>) {
async fn start(&mut self, sender: &winio::ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
Expand Down
4 changes: 2 additions & 2 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>(dirs::picture_dir())
App::new("rs.compio.winio.gallery").run::<MainModel>(dirs::picture_dir())
}

struct MainModel {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Component for MainModel {
}
}

async fn start(&mut self, sender: &winio::ComponentSender<Self>) {
async fn start(&mut self, sender: &winio::ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
Expand Down
6 changes: 3 additions & 3 deletions examples/mdi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>(());
App::new("rs.compio.winio.mdi").run::<MainModel>(());
}

struct MainModel {
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Component for MainModel {
Self { window, cwindow }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl Component for ChildModel {
Self { window, check }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
start! {
sender, default: ChildMessage::Noop,
self.window => {
Expand Down
4 changes: 2 additions & 2 deletions examples/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>("https://www.example.com/");
App::new("rs.compio.winio.net").run::<MainModel>("https://www.example.com/");
}

struct MainModel {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Component for MainModel {
}
}

async fn start(&mut self, sender: &winio::ComponentSender<Self>) {
async fn start(&mut self, sender: &winio::ComponentSender<Self>) -> ! {
start! {
sender, default: MainMessage::Noop,
self.window => {
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
.with_max_level(compio_log::Level::INFO)
.init();

App::new().run::<MainModel>(());
App::new("rs.compio.winio.widgets").run::<MainModel>(());
}

struct MainModel {
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Component for MainModel {
}
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
let mut radio_group = RadioButtonGroup::new([&mut *self.r1, &mut self.r2, &mut self.r3]);
start! {
sender, default: MainMessage::Noop,
Expand Down
2 changes: 1 addition & 1 deletion src/elm/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Component for Button {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
loop {
self.widget.wait_click().await;
sender.output(ButtonEvent::Click);
Expand Down
6 changes: 4 additions & 2 deletions src/elm/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Component for Canvas {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
let fut_redraw = async {
loop {
self.widget.wait_redraw().await;
Expand All @@ -102,7 +102,9 @@ impl Component for Canvas {
sender.output(CanvasEvent::MouseUp(b));
}
};
futures_util::future::join4(fut_redraw, fut_move, fut_down, fut_up).await;
futures_util::future::join4(fut_redraw, fut_move, fut_down, fut_up)
.await
.0
}

async fn update(&mut self, _message: Self::Message, _sender: &ComponentSender<Self>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/elm/check_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Component for CheckBox {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
loop {
self.widget.wait_click().await;
sender.output(CheckBoxEvent::Click);
Expand Down
4 changes: 2 additions & 2 deletions src/elm/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<T: Component> Child<T> {
sender: &ComponentSender<C>,
mut f: impl FnMut(T::Event) -> Option<C::Message>,
mut propagate: impl FnMut() -> C::Message,
) {
) -> ! {
let fut_start = self.model.start(&self.sender);
let fut_forward = async {
loop {
Expand All @@ -93,7 +93,7 @@ impl<T: Component> Child<T> {
}
}
};
futures_util::future::join(fut_start, fut_forward).await;
futures_util::future::join(fut_start, fut_forward).await.0
}

/// Emit message to the child component.
Expand Down
4 changes: 3 additions & 1 deletion src/elm/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ impl<T: Clone> Component for ObservableVec<T> {
}
}

async fn start(&mut self, _sender: &ComponentSender<Self>) {}
async fn start(&mut self, _sender: &ComponentSender<Self>) -> ! {
std::future::pending().await
}

async fn update(&mut self, _message: Self::Message, _sender: &ComponentSender<Self>) -> bool {
false
Expand Down
6 changes: 3 additions & 3 deletions src/elm/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Component for ComboBox {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
loop {
self.widget.wait_select().await;
sender.output(ComboBoxEvent::Select);
Expand Down Expand Up @@ -313,7 +313,7 @@ impl Component for ComboEntry {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
let fut_select = async {
loop {
self.widget.wait_select().await;
Expand All @@ -326,7 +326,7 @@ impl Component for ComboEntry {
sender.output(ComboEntryEvent::Change);
}
};
futures_util::future::join(fut_select, fut_change).await;
futures_util::future::join(fut_select, fut_change).await.0
}

async fn update(&mut self, message: Self::Message, _sender: &ComponentSender<Self>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/elm/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Component for Edit {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
loop {
self.widget.wait_change().await;
sender.output(EditEvent::Change);
Expand Down
4 changes: 3 additions & 1 deletion src/elm/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ impl Component for Label {
Self { widget }
}

async fn start(&mut self, _sender: &ComponentSender<Self>) {}
async fn start(&mut self, _sender: &ComponentSender<Self>) -> ! {
std::future::pending().await
}

async fn update(&mut self, _message: Self::Message, _sender: &ComponentSender<Self>) -> bool {
false
Expand Down
2 changes: 1 addition & 1 deletion src/elm/list_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Component for ListBox {
Self { widget }
}

async fn start(&mut self, sender: &ComponentSender<Self>) {
async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
loop {
self.widget.wait_select().await;
sender.output(ListBoxEvent::Select);
Expand Down
11 changes: 8 additions & 3 deletions src/elm/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ macro_rules! __init_assign {
/// # fn init(_init: Self::Init<'_>, _sender: &ComponentSender<Self>) -> Self { todo!() }
/// # async fn update(&mut self, _msg: Self::Message, _sender: &ComponentSender<Self>) -> bool { false }
/// # fn render(&mut self, _sender: &ComponentSender<Self>) {}
/// async fn start(&mut self, sender: &ComponentSender<Self>) {
/// async fn start(&mut self, sender: &ComponentSender<Self>) -> ! {
/// start! {
/// sender,
/// default: MainMessage::Noop,
Expand All @@ -79,16 +79,21 @@ macro_rules! __init_assign {
/// ```
#[macro_export]
macro_rules! start {
($sender:expr, default: $noop:expr $(,)?) => {};
($sender:expr, default: $noop:expr $(,)?) => {
let _sender = $sender;
let _default = $noop;
::core::future::pending().await
};
($sender:expr, default: $noop:expr, $($(#[$m:meta])* $w:expr => { $($t:tt)* }),+$(,)?) => {
#[allow(unreachable_code)]
$crate::__join!($(
$(#[$m])*
$w.start(
$sender,
$crate::__start_map!($($t)*),
|| $noop
),
)*);
)*).0;
};
}

Expand Down
Loading