Crates.io | xdialog |
lib.rs | xdialog |
version | 0.1.1 |
source | src |
created_at | 2024-07-18 20:34:15.290284 |
updated_at | 2024-07-20 23:30:40.455626 |
description | A small native-ish cross platform dialogs library with zero runtime dependencies. |
homepage | |
repository | https://github.com/velopack/xdialog |
max_upload_size | |
id | 1308014 |
size | 867,147 |
A cross-platform library for displaying native(-ish) dialogs in Rust. This library does not use native system dialogs, but instead creates its own dialog windows which are designed to look and feel like native dialogs. This allows for a simplified API and consistent behavior.
This is not a replacement for a proper GUI framework. It is meant to be used for CLI / background applications which occasionally need to show dialogs (such as alerts, or progress) to the user.
It's main use-case is for the Velopack application installation and update framework.
Add the following to your Cargo.toml
:
[dependencies]
xdialog = "0" # replace with the latest version
Or, run the following command:
cargo install xdialog
Since some platforms require UI to be run on the main thread, xdialog expects to own the main thread, and will launch your core application logic in another thread.
use xdialog::*;
fn main() -> i32 {
XDialogBuilder::new().run(your_main_logic)
}
fn your_main_logic() -> i32 {
// ... do something here
let should_update_now = show_message_yes_no(
"My App Incorporated",
"New version available",
"Would you like to to the new version now?",
XDialogIcon::Warning,
).unwrap();
if !should_update_now {
return -1; // user declined the dialog
}
// ... do something here
let progress = show_progress(
"My App Incorporated",
"Main instruction",
"Body text",
XDialogIcon::Information
).unwrap();
progress.set_value(0.5).unwrap();
progress.set_text("Extracting...").unwrap();
std::thread::sleep(std::time::Duration::from_secs(3));
progress.set_value(1.0).unwrap();
progress.set_text("Updating...").unwrap();
std::thread::sleep(std::time::Duration::from_secs(3));
progress.set_indeterminate().unwrap();
progress.set_text("Wrapping Up...").unwrap();
std::thread::sleep(std::time::Duration::from_secs(3));
progress.close().unwrap();
0 // return exit code
}
There are more examples in the examples
directory.
cargo run --example various_options
This library uses fltk-rs for it's primary backend. By default, fltk-rs provides pre-compiled binaries for most platforms (win-x64, linux-x64, linux-arm64, mac-x64, mac-arm64).
If you are compiling for a platform that does not have pre-compiled binaries, you will need
to disable the fltk-bundled
feature and ensure that cmake is installed on your system.
[dependencies]
xdialog = { version = "0", default-features = false }