Skip to main content

ModalRequest

Struct ModalRequest 

Source
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: ModalPlacement

Where 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

Source

pub fn in_tree(content_id: WidgetId) -> Self

Present an existing widget subtree as modal content.

Source

pub fn deferred( builder: impl FnOnce(&mut WidgetTree) -> WidgetId + 'static, ) -> Self

Build modal content on demand in the presentation target tree.

Source

pub fn presentation(self, presentation: ModalPresentation) -> Self

Source

pub fn close_behavior(self, close_behavior: ModalCloseBehavior) -> Self

Source

pub fn title(self, title: impl Into<String>) -> Self

Source

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.

Source

pub fn placement(self, placement: ModalPlacement) -> Self

Where an in-tree presentation places the modal. See ModalPlacement.

Source

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.

Source

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).

Trait Implementations§

Source§

impl Debug for ModalRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.