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§
Implementations§
Source§impl Outcome
impl Outcome
pub fn is_ignored(self) -> bool
Sourcepub fn is_consumed(self) -> bool
pub fn is_consumed(self) -> bool
Anything but Ignored.
Examples found in repository?
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 }Sourcepub fn is_changed(self) -> bool
pub fn is_changed(self) -> bool
Changed or Submitted: the value the widget owns is not what it was.
Examples found in repository?
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 }Sourcepub fn is_submitted(self) -> bool
pub fn is_submitted(self) -> bool
Submitted only: the user committed the value (Enter, activate, answer).
Sourcepub fn changed_if(flag: bool) -> Outcome
pub fn changed_if(flag: bool) -> Outcome
true → Changed, false → Consumed.
Trait Implementations§
Source§impl BitOrAssign for Outcome
impl BitOrAssign for Outcome
Source§fn bitor_assign(&mut self, rhs: Outcome)
fn bitor_assign(&mut self, rhs: Outcome)
|= operation. Read moreimpl Copy for Outcome
impl Eq for Outcome
Source§impl Ord for Outcome
impl Ord for Outcome
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Outcome
impl PartialOrd for Outcome
impl StructuralPartialEq for Outcome
Auto Trait Implementations§
impl Freeze for Outcome
impl RefUnwindSafe for Outcome
impl Send for Outcome
impl Sync for Outcome
impl Unpin for Outcome
impl UnsafeUnpin for Outcome
impl UnwindSafe for Outcome
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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