rustty_oxide/core/
button.rs

1use core::{ButtonResult, Widget};
2
3/// Helper function for finding the location of the key in the string
4/// that is to be bolded
5pub fn find_accel_char_index(s: &str, accel: char) -> Option<usize> {
6    let lower_accel = accel.to_lowercase().next().unwrap_or(accel);
7    for (i, c) in s.chars().enumerate() {
8        if c.to_lowercase().next().unwrap_or(c) == lower_accel {
9            return Some(i)
10        }
11    }
12    None
13}
14
15/// Trait used when designing new buttons. All buttons implement some 
16/// key that is recorded, and returns some result that can be matched
17/// to run some action
18pub trait Button: Widget { 
19    /// Return the char that is acting as the key in the Button
20    fn accel(&self) -> char;
21    /// Return the `ButtonResult` which would be returned if the
22    /// key is detected
23    fn result(&self) -> ButtonResult;
24    /// If a button is to do some special action upon being pressed,
25    /// then this function will do so. StdButton for example does
26    /// nothing when pressed, while CheckButton changes it's ballot
27    fn pressed(&mut self) { }
28    /// If a button has a state involved, e.g. needs to keep track 
29    /// of a certain event, this function will return the state of
30    /// the button.
31    fn state(&self) -> bool { false }
32}
33