egui_dialogs
Platform-agnostic, customizable dialogs for egui library.
Quick start
Run the example
# cd into the crate directory
Basic usage
Install the crate:
Then add a Dialogs
field to your App
struct:
use Dialogs;
Then somewhere in your App::update
function:
And when you want to show a dialog:
self.dialogs.info;
Handle reply
Using callback functions
Use DialogDetails
struct to build
a dialog with custom attributes.
The following is an example to comfirm a window close request:
use ;
use ;
// in your app state
pub allow_to_close: ,
// and initialize it with false
// when received a close request in the update function
if ctx.input
Using IDs
As rust compiler thinks that your dialog callbacks may be called at any time, it limits your callback from visiting your app states.
To avoid filling your app state struct with Rc
and RefCell
, you can specify an ID for your dialog and use it to identify the dialog reply when a dialog is closed:
use Id;
use ;
// in your app state
pub allow_to_close: bool,
// and initialize it with false
// define an ID for your dialog
const CLOSE_CONFIRM_DIALOG_ID: &str = "close_confirm_dialog";
// in your update function
if let Some = self.dialogs.show
// when you want to show the dialog
if ctx.input
Customization
Customize standard dialog
You can show a customized dialog based on the standard dialogs:
use include_image;
use ;
let standard_dialog = info
.buttons
.image;
new
.on_reply
.show;
Customize dialog appearance and behavior
To show a completely customized dialog, you can first design your dialog state struct like this:
Then implement the Dialog
trait to implement dialog logic
with a generic type parameter to specify the dialog reply type:
use ;
The dialog_window
function is a helper function
to draw a suggested dialog window with a title and a close button.
Now you can show your customized dialog:
.on_reply
.show;
new