Skip to main content

Outcome

Enum Outcome 

Source
pub enum Outcome {
    Ignored,
    Consumed,
    Changed,
    Submitted,
}
Expand description

Result of feeding an event to a widget state.

Ignored → the widget did nothing, let someone else handle it. Consumed → handled, redraw is enough (hover moved, cursor blinked, scrolled). Changed → the value the widget owns changed (toggle flipped, text edited, row picked). Submitted → the value was committed (Enter in a field, a row activated, a dialog answered). Editing widgets report Changed per keystroke and Submitted once, so a screen that writes a config on commit does not write it on the first character typed.

The order is the composition order: | keeps the strongest outcome of a fan-out, and is_changed() is true for Submitted as well, since a commit is also a value change.

Variants§

§

Ignored

§

Consumed

§

Changed

§

Submitted

Implementations§

Source§

impl Outcome

Source

pub fn is_ignored(self) -> bool

Source

pub fn is_consumed(self) -> bool

Anything but Ignored.

Examples found in repository?
examples/minimal.rs (line 84)
79    fn event(&mut self, ev: Event, _now: Instant) -> Flow {
80        if let Event::Key(k) = &ev {
81            if ctrl(k, 'c') {
82                return Flow::Quit;
83            }
84            if self.focus.handle_key(*k).is_consumed() {
85                return Flow::Continue;
86            }
87        }
88        let out = match (&ev, self.focus.current()) {
89            (Event::Key(_), Some(Id::Dark)) => self.dark.handle(&ev),
90            (Event::Key(_), Some(Id::Name)) => self.name.handle(&ev),
91            (Event::Key(_), Some(Id::Save)) => self.save.handle(&ev),
92            // every widget sees every mouse event and checks its own rect
93            (Event::Mouse(_), _) => {
94                let mut o = self.dark.handle(&ev);
95                if o.is_changed() {
96                    self.focus.set(Id::Dark);
97                }
98                let n = self.name.handle(&ev);
99                if n.is_consumed() {
100                    self.focus.set(Id::Name);
101                }
102                let s = self.save.handle(&ev);
103                if s.is_changed() {
104                    self.focus.set(Id::Save);
105                }
106                o |= n | s;
107                o
108            }
109            _ => Outcome::Ignored,
110        };
111        if out.is_changed() {
112            if self.focus.is(Id::Dark) {
113                theme::set_by_name(if self.dark.on {
114                    "textual-dark"
115                } else {
116                    "textual-light"
117                });
118            }
119            if self.focus.is(Id::Save) {
120                self.toasts.success(format!("Saved {:?}", self.name.value));
121            }
122        }
123        Flow::Continue
124    }
Source

pub fn is_changed(self) -> bool

Changed or Submitted: the value the widget owns is not what it was.

Examples found in repository?
examples/minimal.rs (line 95)
79    fn event(&mut self, ev: Event, _now: Instant) -> Flow {
80        if let Event::Key(k) = &ev {
81            if ctrl(k, 'c') {
82                return Flow::Quit;
83            }
84            if self.focus.handle_key(*k).is_consumed() {
85                return Flow::Continue;
86            }
87        }
88        let out = match (&ev, self.focus.current()) {
89            (Event::Key(_), Some(Id::Dark)) => self.dark.handle(&ev),
90            (Event::Key(_), Some(Id::Name)) => self.name.handle(&ev),
91            (Event::Key(_), Some(Id::Save)) => self.save.handle(&ev),
92            // every widget sees every mouse event and checks its own rect
93            (Event::Mouse(_), _) => {
94                let mut o = self.dark.handle(&ev);
95                if o.is_changed() {
96                    self.focus.set(Id::Dark);
97                }
98                let n = self.name.handle(&ev);
99                if n.is_consumed() {
100                    self.focus.set(Id::Name);
101                }
102                let s = self.save.handle(&ev);
103                if s.is_changed() {
104                    self.focus.set(Id::Save);
105                }
106                o |= n | s;
107                o
108            }
109            _ => Outcome::Ignored,
110        };
111        if out.is_changed() {
112            if self.focus.is(Id::Dark) {
113                theme::set_by_name(if self.dark.on {
114                    "textual-dark"
115                } else {
116                    "textual-light"
117                });
118            }
119            if self.focus.is(Id::Save) {
120                self.toasts.success(format!("Saved {:?}", self.name.value));
121            }
122        }
123        Flow::Continue
124    }
Source

pub fn is_submitted(self) -> bool

Submitted only: the user committed the value (Enter, activate, answer).

Source

pub fn changed_if(flag: bool) -> Outcome

true → Changed, false → Consumed.

Trait Implementations§

Source§

impl BitOr for Outcome

Source§

type Output = Outcome

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Outcome) -> Outcome

Performs the | operation. Read more
Source§

impl BitOrAssign for Outcome

Source§

fn bitor_assign(&mut self, rhs: Outcome)

Performs the |= operation. Read more
Source§

impl Clone for Outcome

Source§

fn clone(&self) -> Outcome

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Outcome

Source§

impl Debug for Outcome

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Outcome

Source§

fn default() -> Outcome

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

impl Eq for Outcome

Source§

impl Hash for Outcome

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Outcome

Source§

fn cmp(&self, other: &Outcome) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Outcome

Source§

fn eq(&self, other: &Outcome) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Outcome

Source§

fn partial_cmp(&self, other: &Outcome) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Outcome

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.