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>
impl<Msg: Clone + 'static> Modal<Msg>
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty dialog. Add its content with View::add_with.
Sourcepub fn title(self, title: impl Into<String>) -> Self
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.
Sourcepub fn variant(self, variant: impl Into<String>) -> Self
pub fn variant(self, variant: impl Into<String>) -> Self
Theme variant; "danger" gives a destructive dialog a danger pillar.
Sourcepub fn width(self, cells: u16) -> Self
pub fn width(self, cells: u16) -> Self
Width in cells, padding included; 56 by default. Narrow screens shrink it.
Sourcepub fn on_close(self, message: Msg) -> Self
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.
Sourcepub fn dismissable(self, dismissable: bool) -> Self
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.
Sourcepub fn close_on_click_outside(self, closes: bool) -> Self
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.
Sourcepub fn action(self, button: Button<Msg>) -> Self
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>
impl<Msg: Clone + 'static> Container<Msg> for Modal<Msg>
Source§fn set_children(&mut self, children: Vec<Node<Msg>>)
fn set_children(&mut self, children: Vec<Node<Msg>>)
Source§impl<Msg: Clone + 'static> Widget<Msg> for Modal<Msg>
impl<Msg: Clone + 'static> Widget<Msg> for Modal<Msg>
Source§fn measure(&self, _cx: &mut MeasureCx<'_>, _available: Size) -> Size
fn measure(&self, _cx: &mut MeasureCx<'_>, _available: Size) -> Size
available.Source§fn paint_overlay(&self, cx: &mut PaintCx<'_>, _anchor: Rect)
fn paint_overlay(&self, cx: &mut PaintCx<'_>, _anchor: Rect)
PaintCx::request_overlay. anchor is the area the widget was painted in.Source§fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
fn event(&self, cx: &mut EventCx<'_, Msg>, event: &Event) -> bool
true when the event was used; unused key and scroll events
bubble to the parent widget.Source§fn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
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>
impl<Msg> Unpin for Modal<Msg>
impl<Msg> UnsafeUnpin for Modal<Msg>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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