Skip to main content

Modal

Struct Modal 

Source
pub struct Modal<Msg> { /* private fields */ }
Expand description

A dialog over a dimmed screen: a title, any content and action buttons.

Add it to the view while it should be shown, anywhere in the tree: it takes no room where it is added and is drawn over everything as a layer, centred on the screen. It enters with a short pop over the theme’s motion.enter (at once with reduced motion). While it is open, focus stays inside (the first focusable widget is focused), Tab cycles through its widgets, nothing beneath reacts to keys or the pointer and application shortcuts are paused; when it is removed, focus returns to where it was. Dialogs stack: one added inside another, or later in the view, is on top.

A pillar runs down the whole left edge of the surface, accent-muted, in the danger colour for variant("danger").

With no options it is a plain surface with its content that only the application closes. on_close makes it dismissable: Esc and the close mark × at the top right send the message, always together, and close_on_click_outside adds a click on the dimmed screen. dismissable(false) turns all of them off at once (and hides the mark) while keeping the message, e.g. while the dialog is busy. title and variant("danger") mark it, action adds buttons at the bottom right; on a screen too narrow for them side by side they stand one under another, in Tab order, and never get cut. A faint hint line at the bottom left names Esc and Tab when they do something.

Style keys: modal (bg, padding, pillar) with variants such as modal.danger, modal-title (fg, bold), close-mark, layer-backdrop (scrim, strength in percent), layer-hint-key, layer-hint-label. Hint labels: quvyta.layer.close, quvyta.layer.switch.

Implementations§

Source§

impl<Msg: Clone + 'static> Modal<Msg>

Source

pub fn new() -> Self

An empty dialog. Add its content with View::add_with.

Source

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

A bold heading in the first row; a title wider than the dialog wraps onto more rows.

Source

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

Theme variant; "danger" gives a destructive dialog a danger pillar.

Source

pub fn width(self, cells: u16) -> Self

Width in cells, padding included; 56 by default. Narrow screens shrink it.

Source

pub fn on_close(self, message: Msg) -> Self

The message sent when the dialog is dismissed: Esc inside it or a click on its close mark. Without it neither exists and the dialog closes only through its own buttons.

Source

pub fn dismissable(self, dismissable: bool) -> Self

Whether the dialog can be dismissed; true by default. false turns off Esc, the close mark and the click outside together, and hides the mark, without removing on_close.

Source

pub fn close_on_click_outside(self, closes: bool) -> Self

Also sends the close message when the dimmed screen around the dialog is clicked, while the dialog is dismissable.

Source

pub fn action(self, button: Button<Msg>) -> Self

Adds a button to the action row at the bottom right, after the ones added before. Put the safe action first: the first focusable widget has focus when the dialog opens. When the buttons do not fit on one row they stand one under another, first added on top, so the last one, usually the confirming button, stays last: at the right end of the row, at the bottom of the column.

Trait Implementations§

Source§

impl<Msg: Clone + 'static> Container<Msg> for Modal<Msg>

Source§

fn set_children(&mut self, children: Vec<Node<Msg>>)

Receives the children built for this widget.
Source§

impl<Msg: Clone + 'static> Default for Modal<Msg>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Msg: Clone + 'static> Widget<Msg> for Modal<Msg>

Source§

fn measure(&self, _cx: &mut MeasureCx<'_>, _available: Size) -> Size

The size the widget wants when it may use up to available.
Source§

fn paint(&self, cx: &mut PaintCx<'_>, area: Rect)

Draws the widget into area.
Source§

fn paint_overlay(&self, cx: &mut PaintCx<'_>, _anchor: Rect)

Draws the widget’s overlay after the whole view was painted, when it asked for one with PaintCx::request_overlay. anchor is the area the widget was painted in.
Source§

fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool

Handles input. Returns true when the event was used; unused key and scroll events bubble to the parent widget.
Source§

fn children(&self) -> &[Node<Msg>]

Child nodes, for widgets that contain other widgets.
Source§

fn children_mut(&mut self) -> &mut [Node<Msg>]

Mutable child nodes, used to assign ids.
Source§

fn focusable(&self) -> bool

Whether the widget can take keyboard focus.

Auto Trait Implementations§

§

impl<Msg> !RefUnwindSafe for Modal<Msg>

§

impl<Msg> !Send for Modal<Msg>

§

impl<Msg> !Sync for Modal<Msg>

§

impl<Msg> !UnwindSafe for Modal<Msg>

§

impl<Msg> Freeze for Modal<Msg>
where Option<Msg>: Freeze, Vec<Node<Msg>>: Freeze,

§

impl<Msg> Unpin for Modal<Msg>
where Option<Msg>: Unpin, Vec<Node<Msg>>: Unpin,

§

impl<Msg> UnsafeUnpin for Modal<Msg>
where Option<Msg>: UnsafeUnpin, Vec<Node<Msg>>: UnsafeUnpin,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.