Skip to main content

agg_gui/widgets/window/
close.rs

1//! Close-semantics types for [`super::Window`]: the reason a window closed and
2//! the policy for pointer presses that land outside a modal window.
3//!
4//! These live in their own module so the main `window.rs` stays under the
5//! 800-line guardrail. [`CloseReason`] is threaded through the unified
6//! [`Window::close`](super::Window) path and delivered to the `on_close`
7//! callback, letting a dialog distinguish a *commit-style* dismissal
8//! (click-away, when a live change should be kept) from a *cancel-style* one
9//! (Escape / the × button, which restore prior state).
10
11/// Why a [`Window`](super::Window) is closing. Delivered to the `on_close`
12/// callback so a host can react differently per route — the colour dialog
13/// commits a live preview on [`ClickAway`](CloseReason::ClickAway) but cancels
14/// it on [`Escape`](CloseReason::Escape) / [`CloseButton`](CloseReason::CloseButton).
15#[derive(Clone, Copy, Debug, PartialEq, Eq)]
16pub enum CloseReason {
17    /// The user clicked the title-bar × button.
18    CloseButton,
19    /// The user pressed Escape while the modal window held focus.
20    Escape,
21    /// The user pressed the pointer outside a click-away-enabled modal window.
22    ClickAway,
23}
24
25/// What a modal [`Window`](super::Window) does when the pointer is pressed
26/// outside its own bounds.
27///
28/// The modal grab routes *every* press to the window's subtree (so nothing
29/// leaks to widgets painted beneath); this decides what the window does with an
30/// outside press once it arrives.
31#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
32pub enum ClickAwayAction {
33    /// Swallow the outside press and stay open (the default — preserves the
34    /// behaviour of plain modal windows).
35    #[default]
36    None,
37    /// Close via the unified [`Window::close`](super::Window) path with
38    /// [`CloseReason::ClickAway`], and swallow the press so it never activates
39    /// whatever sat underneath.
40    Close,
41}