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("my_modal");
modal.show(ctx, |ui| {
ui.label("Hello world!")
});
if ui.button("modal").clicked() {
modal.open(ctx);
}Implementations
sourceimpl Modal
impl Modal
sourcepub fn new(ctx: &Context, id_source: impl Display) -> Self
pub fn new(ctx: &Context, id_source: impl Display) -> Self
Creates a new Modal. Can use constructor functions like Modal::with_style
to modify upon creation.
sourcepub fn open(&self)
pub fn open(&self)
Open the modal; make it visible. The modal prevents user input to other parts of the application.
sourcepub fn close(&self)
pub fn close(&self)
Close the modal so that it is no longer visible, allowing input to flow back into the application.
sourcepub fn with_close_on_outside_click(self, do_close_on_click_ouside: bool) -> Self
pub fn with_close_on_outside_click(self, do_close_on_click_ouside: bool) -> Self
If set to true, the modal will close itself if the user clicks outside on the modal window
(onto the overlay).
sourcepub fn with_style(self, style: &ModalStyle) -> Self
pub fn with_style(self, style: &ModalStyle) -> Self
Change the ModalStyle of the modal upon creation.
sourcepub fn title(&self, ui: &mut Ui, text: impl Into<RichText>)
pub fn title(&self, ui: &mut Ui, text: impl Into<RichText>)
Helper function for styling the title of the modal.
sourcepub fn body(&self, ui: &mut Ui, text: impl Into<RichText>)
pub fn body(&self, ui: &mut Ui, text: impl Into<RichText>)
Helper function for styling the body of the modal.
Helper function for styling the button container of the modal.
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.
sourcepub fn show<R>(&self, add_contents: impl FnOnce(&mut Ui) -> R)
pub fn show<R>(&self, add_contents: impl FnOnce(&mut Ui) -> R)
The ui contained in this function will be shown within the modal window. The modal will only actually show
when Modal::open is used.