#![warn(clippy::complexity, clippy::pedantic)]
#![deny(
clippy::manual_let_else,
clippy::manual_clamp,
clippy::manual_assert,
clippy::manual_ok_or,
clippy::manual_string_new
)]
#![allow(
clippy::semicolon_if_nothing_returned,
clippy::default_trait_access,
clippy::cast_possible_truncation,
clippy::module_name_repetitions,
clippy::must_use_candidate,
clippy::inline_always,
clippy::cast_possible_truncation,
clippy::match_wildcard_for_single_variants,
clippy::cast_sign_loss,
clippy::unused_self
)]
#![no_std]
extern crate alloc;
use alloc::vec::Vec;
use calc_common::Button;
use calc_common::Character;
use calc_common::MetaButton;
use calc_common::NUM_CHARS;
use evaluation_menu::EvaluationMenuPersistentData;
use evaluation_menu::EvaluationMenuState;
pub use math::number_to_chars;
use meta_menu::MetaMenuState;
use settings_menu::SettingsMenuState;
pub mod drawing;
pub mod evaluation_menu;
pub mod math;
mod meta_menu;
mod settings_menu;
mod util;
enum CalcMenuState {
EvaluationMenu(EvaluationMenuState),
Settings(SettingsMenuState),
Meta(MetaMenuState),
}
pub struct CalculatorState {
pub screen: drawing::ScreenBuffer,
pub msg: Vec<Character>,
menu: CalcMenuState,
evaluation_menu_persistent_data: EvaluationMenuPersistentData,
}
impl CalculatorState {
pub fn draw(&mut self) {
match &mut self.menu {
CalcMenuState::Meta(state) => state.draw(&mut self.screen),
CalcMenuState::EvaluationMenu(state) => {
state.draw(&mut self.screen, &self.evaluation_menu_persistent_data)
}
CalcMenuState::Settings(state) => state.draw(&mut self.screen),
}
}
pub fn on_button_press(&mut self, button: Button) {
if button == MetaButton::Menu.into() {
self.menu = CalcMenuState::Meta(Default::default());
self.draw();
return;
}
match &mut self.menu {
CalcMenuState::Meta(state) => {
if let Some(new_menu_state) = state.on_button_press(&mut self.screen, button) {
self.menu = new_menu_state;
self.draw();
}
}
CalcMenuState::EvaluationMenu(state) => state.on_button_press(
&mut self.screen,
button,
&mut self.evaluation_menu_persistent_data,
),
CalcMenuState::Settings(state) => state.on_button_press(&mut self.screen, button),
}
}
}
impl Default for CalculatorState {
fn default() -> Self {
let mut state = Self {
screen: Default::default(),
menu: CalcMenuState::EvaluationMenu(Default::default()),
msg: Vec::new(),
evaluation_menu_persistent_data: Default::default(),
};
state.draw();
state
}
}