Skip to main content

Confirm

Struct Confirm 

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

A question for Command::confirm: a title, an optional message, and the messages for the answers.

The dialog has two buttons, Cancel and the confirm button, labelled from quvyta.confirm.cancel and quvyta.confirm.confirm unless given. Cancel has focus. The question is dismissable by default: Esc and the close mark × at the top right cancel, always together; dismissable(false) turns both off so only the buttons answer. A click on the dimmed screen never answers, so a stray click is harmless.

alternative adds a third way between the two, such as “Save · Continue · Discard” for recovered work. The buttons then read Cancel, the alternative and the confirm button from left to right, Tab and Shift+Tab visit them in that order, and Cancel still has focus when the dialog opens; Esc and the close mark still cancel.

require_word asks the user to type a word before the confirm button works, for actions that cannot be undone.

Implementations§

Source§

impl<Msg> Confirm<Msg>

Source

pub fn new(title: impl Into<String>, on_confirm: Msg) -> Self

Asks title; confirming sends on_confirm.

Source

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

Explains the consequences below the title.

Source

pub fn danger(self) -> Self

Marks the question as destructive: a danger pillar down the dialog’s left edge and a danger confirm button.

Source

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

Whether Esc and the close mark cancel the question; true by default. With false neither works, the mark is not drawn and only the buttons answer.

Source

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

The confirm button’s label, e.g. the action’s own verb: “Remove”.

Source

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

The cancel button’s label.

Source

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

The message sent when the question is cancelled; without it cancelling only closes the dialog.

Source

pub fn alternative(self, label: impl Into<String>, message: Msg) -> Self

A third answer between Cancel and the confirm button: a button labelled label that sends message, such as “Continue” beside “Discard” and “Save”. Without it the dialog has its two buttons exactly as before.

Source

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

Asks the user to type word before confirming, for an action that cannot be undone, such as emptying the trash for good: the dialog gains a line “Type word to confirm” (quvyta.confirm.type-word, with the word in the title tone among secondary text) and a text field below the message.

The field has focus when the dialog opens and each question starts with it empty. The confirm button is disabled, drawn in the disabled tone and passed over by Tab, until the typed text matches the word; then it takes its danger or primary tone and Enter in the field confirms too. Before that Enter does nothing and the dialog stays. Esc and the close mark still cancel, and Tab and Shift+Tab visit the field, Cancel, the alternative and the confirm button in that order.

Only the confirm button waits for the word: an alternative is a different, safe way out and works at once.

Matching ignores spaces around the text and case, the Turkish way included: İ, I, ı and i are all the same letter, so “sil”, “SİL”, “SIL” and “ Sil “ all match “SİL”, and “iptal” matches “İPTAL”. Typing the word is meant as a deliberate act, not a secret, so a keyboard’s idea of the dotted and dotless i never stands in the way. A blank word asks for nothing and leaves the dialog as it is without this option.

Keep it for what cannot be undone; a question that always asks for typing teaches people to type without reading.

Auto Trait Implementations§

§

impl<Msg> Freeze for Confirm<Msg>
where Msg: Freeze, Option<Msg>: Freeze, Option<(String, Msg)>: Freeze,

§

impl<Msg> RefUnwindSafe for Confirm<Msg>

§

impl<Msg> Send for Confirm<Msg>
where Msg: Send, Option<Msg>: Send, Option<(String, Msg)>: Send,

§

impl<Msg> Sync for Confirm<Msg>
where Msg: Sync, Option<Msg>: Sync, Option<(String, Msg)>: Sync,

§

impl<Msg> Unpin for Confirm<Msg>
where Msg: Unpin, Option<Msg>: Unpin, Option<(String, Msg)>: Unpin,

§

impl<Msg> UnsafeUnpin for Confirm<Msg>
where Msg: UnsafeUnpin, Option<Msg>: UnsafeUnpin, Option<(String, Msg)>: UnsafeUnpin,

§

impl<Msg> UnwindSafe for Confirm<Msg>
where Msg: UnwindSafe, Option<Msg>: UnwindSafe, Option<(String, Msg)>: UnwindSafe,

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.