-
use dali::choose_video_file;
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError> {
let ui: AppWindow = AppWindow::new()?;
let ui_handle: slint::Weak<AppWindow> = ui.as_weak();
let mut input: Option<std::path::PathBuf> = None;
ui.on_choose_video_file(move || {
input = choose_video_file();
if !input.is_none() {
ui_handle.unwrap().set_compress_enabled(true);
}
});
ui.on_compress_video(move || {
println!("{:?}", input);
todo!()
});
ui.run()
} I don't know what to do, I don't think I should do it this way, is there another standard way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You could add a string property to your If you want to avoid doing that you need to code your (Note that I'm still relatively new to Rust, there might be better ways...) |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply, I think the first method would be better, as I need to show the file path in the UI to alert the user
|
Beta Was this translation helpful? Give feedback.
You could add a string property to your
AppWindow
to store the chosen path there, then read it from there in theon_compress_video
callback (or pass it in as parameter). This would have the added benefit, that you can easily display the selected value in the UI.If you want to avoid doing that you need to code your
input
in a way that the two closures can both reference the same value. You can do this for example by constructing anRc<RefCell<Option<PathBuf>>>
usingRc::new(RefCell::new(input))
, cloning that reference-counted value for each closure, and using.borrow_mut()
and.borrow()
in the first and last closure respectively.(Note that I'm still relatively new to Rust, there might be…