Expand description
This crate provides high-level, low-overhead bindings to NvDialog for Rust, and serves as the successor to the
[nvdialog``](https://crates.io/crates/nvdialog) crate. Unlike its predecessor, this crate does not rely on libloading for system bindings to NvDialog, offering a more direct integration by manually building and linking with
libnvdialogthrough
nvdialog-sys`.
§Safety
The crate strives to replicate Rust’s compile-time safety checks within the context of NvDialog to ensure the integrity of your code. For instance, we use mutable references where necessary in FFI calls that modify data, avoiding plain references which aren’t checked by Rust’s borrow checker.
§Threading Considerations
NvDialog’s threading rules remain the same, regardless of the language. Dialogs should always be created and used on the same thread. While it’s technically possible to create dialogs from secondary threads, it is not officially supported and can lead to issues on certain platforms. Specifically:
- Windows: Creating dialogs from secondary threads may work in a lot of cases, but it is considered unsafe and not recommended.
- macOS: UI operations, including dialogs, must be performed on the main thread. Creating dialogs from other threads is not supported.
- Gtk3/4 (GNU/Linux): While Gtk does not directly support cross-thread UI operations, GLib provides mechanisms to safely send data between threads. However
nvdialog-rs
does not make use of them, meaning sending and receiving data across threads is still unsupported.
§Example dialog:
use nvdialog_rs::DialogBox;
use nvdialog_rs::DialogType;
/* Initialize the library. This corresponds to 'nvd_init' */
nvdialog_rs::init();
/* Creating the dialog box. */
let dialog_box = DialogBox::new(
"Hello from Rust!", /* Title of the dialog */
/* Message of the dialog */
"This dialog has been created using Rust and NvDialog bindings to the language.",
/* See documentation for more */
DialogType::Simple
);
/* Showing the dialog box. */
dialog_box.show();
Memory management is performed automatically internally by implementing Drop on all types, therefore every dialog is implicitly freeing any memory it used at the end of scope.
Macros§
Structs§
- About
Dialog - A struct for a dialog to show about your application.
- Dialog
Box - A struct representing a dialog box.
- File
Dialog - A struct representing a file dialog window.
- Image
- A simple image loaded from NvDialog. This is the equivalent to
NvdImage
, although the implementation makes a few extra safety checks from the Rust side. - Notification
- A notification dialog, which can be used to send a notification to the user through the system’s API.
- Question
Dialog - A dialog box for asking a question and getting a response from the user.
Enums§
- Dialog
Type - An enumeration of the different types of dialogs that can be created.
- Error
Error
is the main type for handling errors in the crate. It’s direct C equivalent isNvdError
(Located atinclude/nvdialog_types.h
, line 53). Errors are converted from the C side into this crate using theFrom<i32>
implementation.- File
Dialog Type - Mode of the file dialog
- Image
Error - Notification
Kind NotificationKind
defines a type that can represent different kinds of notifications. The enum has three variants:Simple
,Warning
, andError
, each representing a different kind of notification.- Question
Dialog Buttons - Represents the buttons that can be displayed on a
QuestionDialog
. - Reply
- An enum that holds all possible replies from a dialog.
Can be converted from a
u32
if needed.
Functions§
- init
- Initialize NvDialog in the current thread.
- set_
app_ name - Sets the application name for NvDialog.