rustphone/src/apps/dial.rs
2023-09-11 22:22:20 +02:00

46 lines
863 B
Rust

use crate::{
apps::App,
display::Display,
keypad::{Key, KeyEvent, KeyEventType, KeyEvents, KeyInputMode},
state::{ModeState, State},
Context,
};
use arrayvec::ArrayString;
pub struct Dial;
pub struct DialState {
// TODO what should max length be?
pub line: ArrayString<255>,
}
impl App for Dial {
type AppModeState = DialState;
fn update(ctx: &mut Context, mode_state: &mut DialState) -> Option<ModeState> {
for key_event in &ctx.key_events {
if key_event.event_type != KeyEventType::Pressed {
continue;
}
match key_event.key {
Key::HangUp => {
return Some(ModeState::Clock(Default::default()));
}
Key::PickUp => {
// TODO
}
_ => {
if let Some(ch) = key_event.get_char(KeyInputMode::Digit) {
if mode_state.line.try_push(ch).is_err() {
// TODO
}
}
}
}
}
None
}
}