MaterialDialog

Struct MaterialDialog 

Source
pub struct MaterialDialog<'a> { /* private fields */ }
Expand description

Material Design dialog component following Material Design 3 specifications

Dialogs interrupt users with overlaid content that requires a response. They appear above all other content and disable all app functionality when shown.

§Usage Examples

let mut dialog_open = false;
 
// Basic dialog
let dialog = MaterialDialog::new("my_dialog", "Confirm Action", &mut dialog_open)
    .content(|ui| {
        ui.label("Are you sure you want to proceed?");
    })
    .action("Cancel", ActionType::Text, || {
        // Cancel action
    })
    .action("Confirm", ActionType::Filled, || {
        // Confirm action  
    });
 
dialog.show(ui.ctx());

§Material Design Spec

  • Max width: 560dp on large screens
  • Corner radius: 28dp
  • Elevation: 6dp (24dp shadow)
  • Surface color background
  • Minimum touch target: 48x48dp for actions

Implementations§

Source§

impl<'a> MaterialDialog<'a>

Source

pub fn new( id: impl Into<Id>, title: impl Into<String>, open: &'a mut bool, ) -> Self

Create a new Material Design dialog

§Parameters
  • id: Unique identifier for the dialog (used for egui state)
  • title: Title text displayed at the top of the dialog
  • open: Mutable reference to boolean controlling dialog visibility
§Returns

A new MaterialDialog instance ready for customization

Source

pub fn dialog_type(self, dialog_type: DialogType) -> Self

Set the dialog type (affects styling and behavior)

§Parameters
  • dialog_type: The type of dialog to display
§Returns

Self for method chaining

Source

pub fn icon(self, icon: impl Into<String>) -> Self

Set an optional icon to display in the dialog header

§Parameters
  • icon: The icon to display (as a string identifier)
§Returns

Self for method chaining

Source

pub fn content<F>(self, content: F) -> Self
where F: FnOnce(&mut Ui) + 'a,

Set the content of the dialog

§Parameters
  • content: A closure that renders the content UI
§Returns

Self for method chaining

Source

pub fn quick(self, quick: bool) -> Self

Set whether this is a quick/temporary dialog

§Parameters
  • quick: If true, the dialog is considered quick/temporary
§Returns

Self for method chaining

Source

pub fn no_focus_trap(self, no_focus_trap: bool) -> Self

Set whether to disable focus trapping within the dialog

§Parameters
  • no_focus_trap: If true, focus trapping is disabled
§Returns

Self for method chaining

Source

pub fn max_width(self, width: f32) -> Self

Set the maximum width constraint for the dialog

§Parameters
  • width: The maximum width in pixels
§Returns

Self for method chaining

Source

pub fn text_action<F>(self, text: impl Into<String>, action: F) -> Self
where F: FnOnce() + 'a,

Add a text action button to the dialog

§Parameters
  • text: The text label for the button
  • action: A closure that is called when the button is clicked
§Returns

Self for method chaining

Source

pub fn filled_tonal_action<F>(self, text: impl Into<String>, action: F) -> Self
where F: FnOnce() + 'a,

Add a filled tonal action button to the dialog

§Parameters
  • text: The text label for the button
  • action: A closure that is called when the button is clicked
§Returns

Self for method chaining

Source

pub fn filled_action<F>(self, text: impl Into<String>, action: F) -> Self
where F: FnOnce() + 'a,

Add a filled action button to the dialog

§Parameters
  • text: The text label for the button
  • action: A closure that is called when the button is clicked
§Returns

Self for method chaining

Source

pub fn action<F>(self, text: impl Into<String>, action: F) -> Self
where F: FnOnce() + 'a,

Backward compatibility methods

These methods exist to support older code that used different naming conventions for actions. They are functionally equivalent to the more descriptively named methods introduced later.

§Parameters
  • text: The text label for the button
  • action: A closure that is called when the button is clicked
§Returns

Self for method chaining

Source

pub fn primary_action<F>(self, text: impl Into<String>, action: F) -> Self
where F: FnOnce() + 'a,

Backward compatibility method for primary actions

This method is provided for convenience and is functionally equivalent to filled_action.

§Parameters
  • text: The text label for the button
  • action: A closure that is called when the button is clicked
§Returns

Self for method chaining

Source

pub fn show(self, ctx: &Context)

Show the dialog, rendering it in the given context

§Parameters
  • ctx: The egui context used for rendering the dialog
§Behavior
  • The dialog will be displayed as an overlay, blocking interaction with other windows
  • Clicking outside the dialog or pressing the escape key will close the dialog
  • Action buttons will execute their associated actions when clicked

Auto Trait Implementations§

§

impl<'a> Freeze for MaterialDialog<'a>

§

impl<'a> !RefUnwindSafe for MaterialDialog<'a>

§

impl<'a> !Send for MaterialDialog<'a>

§

impl<'a> !Sync for MaterialDialog<'a>

§

impl<'a> Unpin for MaterialDialog<'a>

§

impl<'a> !UnwindSafe for MaterialDialog<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,