Add EventResult::and

This commit is contained in:
Alexandre Bury 2018-09-05 08:51:32 -07:00
parent b607be40d4
commit b21224cf1c

View File

@ -140,6 +140,25 @@ impl EventResult {
other => other, other => other,
} }
} }
/// Returns an event result that combines `self` and `other`.
pub fn and(self, other: Self) -> Self {
match (self, other) {
(EventResult::Ignored, result)
| (result, EventResult::Ignored) => result,
(EventResult::Consumed(None), EventResult::Consumed(cb))
| (EventResult::Consumed(cb), EventResult::Consumed(None)) => {
EventResult::Consumed(cb)
}
(
EventResult::Consumed(Some(cb1)),
EventResult::Consumed(Some(cb2)),
) => EventResult::with_cb(move |siv| {
(cb1)(siv);
(cb2)(siv);
}),
}
}
} }
/// A non-character key on the keyboard /// A non-character key on the keyboard