pub struct ModalRequest {
pub content: ModalContent,
pub presentation: ModalPresentation,
pub close_behavior: ModalCloseBehavior,
pub title: Option<String>,
pub size: Option<(u32, u32)>,
pub placement: ModalPlacement,
pub focus_target: Option<WidgetId>,
pub on_dismiss: Option<OverlayDismissCallback>,
}Expand description
A framework-level request to present a modal.
Fields§
§content: ModalContent§presentation: ModalPresentation§close_behavior: ModalCloseBehavior§title: Option<String>§size: Option<(u32, u32)>§placement: ModalPlacementWhere an in-tree presentation places the modal. Ignored by a native window.
focus_target: Option<WidgetId>Optional explicit initial-focus target inside the modal content
subtree. When None, the framework falls back to
first_focusable_descendant(content_id). When Some, the id
is consulted first and the framework focuses it if the widget
exists and is still active in the target tree; otherwise it
falls back to first_focusable_descendant. Required for
MessageBox-style alerts where the default button may not be
the first focusable descendant in tree-walk order.
on_dismiss: Option<OverlayDismissCallback>Invoked when the modal is dismissed by any path (Escape, close
button, click-outside, explicit ctx.dismiss_modal()), and when the
window presenting it closes with it still up (a quit, a forced
close of the window), with
DismissReason::Programmatic.
For a native modal window, it runs in that window’s tree as the
window closes, whatever closes it.
Implementations§
Source§impl ModalRequest
impl ModalRequest
Sourcepub fn in_tree(content_id: WidgetId) -> Self
pub fn in_tree(content_id: WidgetId) -> Self
Present an existing widget subtree as modal content.
Sourcepub fn deferred(
builder: impl FnOnce(&mut WidgetTree) -> WidgetId + 'static,
) -> Self
pub fn deferred( builder: impl FnOnce(&mut WidgetTree) -> WidgetId + 'static, ) -> Self
Build modal content on demand in the presentation target tree.
pub fn presentation(self, presentation: ModalPresentation) -> Self
pub fn close_behavior(self, close_behavior: ModalCloseBehavior) -> Self
pub fn title(self, title: impl Into<String>) -> Self
Sourcepub fn size(self, width: u32, height: u32) -> Self
pub fn size(self, width: u32, height: u32) -> Self
The size, in logical pixels, of the native window the modal opens in when it is presented as one: its floor, since the window grows on either axis to fit its content (a dialog panel’s padding around content of this width, an expander opened). It is centred over the window it blocks on the size it first grows to; an expander opened later keeps its corner. Ignored in-tree, where the overlay takes its content’s size.
Sourcepub fn placement(self, placement: ModalPlacement) -> Self
pub fn placement(self, placement: ModalPlacement) -> Self
Where an in-tree presentation places the modal. See ModalPlacement.
Sourcepub fn on_dismiss(self, callback: OverlayDismissCallback) -> Self
pub fn on_dismiss(self, callback: OverlayDismissCallback) -> Self
Register a callback invoked when the modal is dismissed by any
path (Escape, close button, click-outside, explicit
ctx.dismiss_modal()), or closed with the window presenting it, in
the tree and as a native modal window alike, with the reason it
went.
Sourcepub fn focus_target(self, id: WidgetId) -> Self
pub fn focus_target(self, id: WidgetId) -> Self
Direct initial focus to a specific widget inside the modal
content subtree. The id must resolve to a widget that exists
and is active at the time the modal is presented; if it does
not, the framework falls back to
first_focusable_descendant(content_id).