Implement main menu
This commit is contained in:
parent
e30e71516e
commit
8c9afa6128
@ -272,31 +272,23 @@ impl State for EnterPinState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Clone)]
|
||||
enum MainMenuItem {
|
||||
#[default]
|
||||
Item1,
|
||||
Item2,
|
||||
Item3,
|
||||
Item4,
|
||||
Item5,
|
||||
Item6,
|
||||
SendSMS,
|
||||
ReadSMS,
|
||||
}
|
||||
impl MenuItem for MainMenuItem {
|
||||
fn as_text(&self) -> String {
|
||||
match self {
|
||||
MainMenuItem::Item1 => "item1",
|
||||
MainMenuItem::Item2 => "item2",
|
||||
MainMenuItem::Item3 => "item3",
|
||||
MainMenuItem::Item4 => "item4",
|
||||
MainMenuItem::Item5 => "item5",
|
||||
MainMenuItem::Item6 => "item6",
|
||||
MainMenuItem::SendSMS => "Send SMS",
|
||||
MainMenuItem::ReadSMS => "Read SMS",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MainMenuState {
|
||||
menu: Menu<MainMenuItem>,
|
||||
}
|
||||
@ -305,19 +297,20 @@ impl Default for MainMenuState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
menu: Menu::default()
|
||||
.with_item(MainMenuItem::Item1)
|
||||
.with_item(MainMenuItem::Item2)
|
||||
.with_item(MainMenuItem::Item3)
|
||||
.with_item(MainMenuItem::Item4)
|
||||
.with_item(MainMenuItem::Item5)
|
||||
.with_item(MainMenuItem::Item6),
|
||||
.with_item(MainMenuItem::SendSMS)
|
||||
.with_item(MainMenuItem::ReadSMS),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State for MainMenuState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
self.menu.poll(&mut data.io);
|
||||
if let Some(option) = self.menu.poll(&mut data.io) {
|
||||
match option {
|
||||
MainMenuItem::SendSMS => return Some(Box::new(PhoneNumberState::default())),
|
||||
MainMenuItem::ReadSMS => {}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
@ -375,15 +368,15 @@ impl State for MessageState {
|
||||
|resp| match resp.unwrap() {
|
||||
SendSMSResponse::MessageRefrence(refrence) => Box::new(TextState {
|
||||
text: format!("SMS sent\nRef: {}", refrence),
|
||||
after: PhoneNumberState::default(),
|
||||
after: MainMenuState::default(),
|
||||
}),
|
||||
SendSMSResponse::Error => Box::new(TextState {
|
||||
text: "ERROR!".to_owned(),
|
||||
after: PhoneNumberState::default(),
|
||||
after: MainMenuState::default(),
|
||||
}),
|
||||
SendSMSResponse::ErrorMessage(msg) => Box::new(TextState {
|
||||
text: format!("Error:\n{}", msg),
|
||||
after: PhoneNumberState::default(),
|
||||
after: MainMenuState::default(),
|
||||
}),
|
||||
},
|
||||
)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user