-
Heyy, im very new to slint and still a noob at rust so please excuse any beginner mistakes! I am trying to create a clock widget, and I am clueless on how to have an update loop after I only see updating in the #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use slint::ToSharedString;
mod clock;
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError>{
let window = MainWindow::new()?;
let mut timer = clock::Time {
minute: 15,
second: 0,
};
timer.dec_second();
// How to have this command running after window.run() has been invoked?
window.set_time(timer.to_str().to_shared_string());
window.run()
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
For synchronous, you could have a timer in your slint app that triggers a callback that you can then use to do whatever in rust. In your MainWindow in slint : callback refresh();
timer := Timer {
interval: 1s;
running: true;
triggered() => {
refresh();
}
} and then in rust before your window.on_refresh({
let window_handle = window.as_weak();
move || {
let window = window_handle.unwrap();
timer.dec_second();
window.set_time(timer.to_str().to_shared_string());
}
}); This is probably not the fastest way to do it, and if thats not enough you should indeed look into asynchronous with a timer directly in rust but thats a bit more work... |
Beta Was this translation helpful? Give feedback.
-
You can spawn an async local thread for this: https://docs.slint.dev/latest/docs/rust/slint/fn.spawn_local And for simple timer notifications from the backend, you can use tokio's notify without spinning a tokio runtime: https://docs.rs/tokio/latest/tokio/sync/struct.Notify.html
|
Beta Was this translation helpful? Give feedback.
For synchronous, you could have a timer in your slint app that triggers a callback that you can then use to do whatever in rust.
In your MainWindow in slint :
and then in rust before your
window.run()
:This is probably not the fastest way to do it, and if thats not enough you should indeed look into asynchronous with a timer directly in rust but thats …