Struct egui_modal::Modal

source ·
pub struct Modal { /* private fields */ }
Expand description

A Modal is created using Modal::new(). Make sure to use a let binding when using Modal::new() to ensure you can call things like Modal::open() later on.

let modal = Modal::new(ctx, "my_modal");
modal.show(|ui| {
    ui.label("Hello world!")
});
if ui.button("modal").clicked() {
    modal.open();
}

Helper functions are also available to use that help apply margins based on the modal’s ModalStyle. They are not necessary to use, but may help reduce boilerplate.

let other_modal = Modal::new(ctx, "another_modal");
other_modal.show(|ui| {
    other_modal.frame(ui, |ui| {
        other_modal.body(ui, "Hello again, world!");
    });
    other_modal.buttons(ui, |ui| {
        other_modal.button(ui, "Close");
    });
});
if ui.button("open the other modal").clicked() {
    other_modal.open();
}

Implementations§

Creates a new Modal. Can use constructor functions like Modal::with_style to modify upon creation.

Was the outer overlay clicked this frame?

Is the modal currently open?

Open the modal; make it visible. The modal prevents user input to other parts of the application.

Close the modal so that it is no longer visible, allowing input to flow back into the application.

If set to true, the modal will close itself if the user clicks outside on the modal window (onto the overlay).

Change the ModalStyle of the modal upon creation.

Helper function for styling the title of the modal.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.title(ui, "my title");
});

Helper function for styling the icon of the modal.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.frame(ui, |ui| {
        modal.icon(ui, Icon::Info);
    });
});

Helper function for styling the container the of body and icon.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.title(ui, "my title");
    modal.frame(ui, |ui| {
        // inner modal contents go here
    });
    modal.buttons(ui, |ui| {
        // button contents go here
    });
});

Helper function that should be used when using a body and icon together.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.frame(ui, |ui| {
        modal.body_and_icon(ui, "my modal body", Icon::Warning);
    });
});

Helper function for styling the body of the modal.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.frame(ui, |ui| {
        modal.body(ui, "my modal body");
    });
});

Helper function for styling the button container of the modal.

let modal = Modal::new(ctx, "modal");
modal.show(|ui| {
    modal.buttons(ui, |ui| {
        modal.button(ui, "my modal button");
    });
});

Helper function for creating a normal button for the modal. Automatically closes the modal on click.

Helper function for creating a “cautioned” button for the modal. Automatically closes the modal on click.

Helper function for creating a “suggested” button for the modal. Automatically closes the modal on click.

The ui contained in this function will be shown within the modal window. The modal will only actually show when Modal::open is used.

Open the modal as a dialog. This is a shorthand way of defining a Modal::show once, for example, if a function returns an Error. This should be used in conjunction with Modal::show_dialog. This function should be put AFTER any calls to

Needed in order to use Modal::open_dialog. Make sure this is called every frame, as it renders the necessary ui when using a modal as a dialog.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.