Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
lucasmerlin and emilk authored Nov 28, 2024
1 parent afea434 commit 46c13fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions crates/egui/src/containers/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use emath::{Align2, Vec2};
/// Similar to a [`crate::Window`] but centered and with a backdrop that
/// blocks input to the rest of the UI.
///
/// You can show multiple modals on top of each other. The top most modal will always be
/// You can show multiple modals on top of each other. The topmost modal will always be
/// the most recently shown one.
pub struct Modal {
pub area: Area,
Expand Down Expand Up @@ -129,13 +129,16 @@ pub struct ModalResponse<T> {
/// The response of the modal contents
pub response: Response,

/// The response of the modal backdrop
/// The response of the modal backdrop.
///
/// A click on this means the user clicked outside the modal,
/// in which case you might want to close the modal.
pub backdrop_response: Response,

/// The inner response from the content closure
pub inner: T,

/// Is this the top most modal?
/// Is this the topmost modal?
pub is_top_modal: bool,

/// Is there any popup open?
Expand All @@ -148,7 +151,7 @@ impl<T> ModalResponse<T> {
/// Should the modal be closed?
/// Returns true if:
/// - the backdrop was clicked
/// - this is the top most modal, no popup is open and the escape key was pressed
/// - this is the topmost modal, no popup is open and the escape key was pressed
pub fn should_close(&self) -> bool {
let ctx = &self.response.ctx;
let escape_clicked = ctx.input(|i| i.key_pressed(crate::Key::Escape));
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_demo_lib/src/demo/modals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl crate::View for Modals {
ui.label("Click one of the buttons to open a modal.");
ui.label("Modals have a backdrop and prevent interaction with the rest of the UI.");
ui.label(
"You can show modals on top of each other and close the top most modal with \
"You can show modals on top of each other and close the topmost modal with \
escape or by clicking outside the modal.",
);

Expand Down Expand Up @@ -129,7 +129,7 @@ impl crate::View for Modals {
if let Some(progress) = *save_progress {
Modal::new(Id::new("Modal C")).show(ui.ctx(), |ui| {
ui.set_width(70.0);
ui.heading("Saving...");
ui.heading("Saving");

ProgressBar::new(progress).ui(ui);

Expand Down

0 comments on commit 46c13fe

Please sign in to comment.