auto enter on full entry

This commit is contained in:
2025-07-18 20:31:23 +01:00
parent a60df862f4
commit ae4e558b52

View File

@@ -113,7 +113,7 @@ impl NumberInput {
*self = Self::default();
}
pub fn input_significant(&mut self, val: u8) -> Result<(), NumberInputError> {
pub fn input_significant(&mut self, val: u8) -> Result<bool, NumberInputError> {
if val > 9 {
panic!("Bad significatn val");
}
@@ -122,10 +122,10 @@ impl NumberInput {
}
self.significant[self.significant_pos] = val;
self.significant_pos += 1;
return Ok(());
Ok(self.significant_pos == DISPLAY_SEGMENTS_SIG)
}
pub fn input_exponent(&mut self, val: u8) -> Result<(), NumberInputError> {
pub fn input_exponent(&mut self, val: u8) -> Result<bool, NumberInputError> {
if val > 9 {
panic!("Bad exponent val");
}
@@ -134,10 +134,10 @@ impl NumberInput {
}
self.exponent[self.exponent_pos] = val;
self.exponent_pos += 1;
Ok(())
Ok(self.exponent_pos == DISPLAY_SEGMENTS_EXP)
}
pub fn input(&mut self, val: u8) -> Result<(), NumberInputError> {
pub fn input(&mut self, val: u8) -> Result<bool, NumberInputError> {
if self.enter_exponent {
self.input_exponent(val)
} else {
@@ -290,8 +290,12 @@ impl CalcluclatorState {
Ok(CalcluclatorState::EnterSignificant)
}
KeyPress::Num(val) => {
number_input.input(val)?;
Ok(CalcluclatorState::EnterSignificant)
if number_input.input(val)? {
number_input.enter_exponent();
Ok(CalcluclatorState::EnterExponent)
} else {
Ok(CalcluclatorState::EnterSignificant)
}
}
KeyPress::Minus => {
number_input.toggle_minus();
@@ -310,8 +314,13 @@ impl CalcluclatorState {
Ok(CalcluclatorState::EnterSignificant)
}
KeyPress::Num(val) => {
number_input.input(val)?;
Ok(CalcluclatorState::EnterExponent)
if number_input.input(val)? {
number_input.done();
calc.push(number_input.to_decimal())?;
Ok(CalcluclatorState::EnterOperation)
} else {
Ok(CalcluclatorState::EnterExponent)
}
}
KeyPress::Minus => {
number_input.toggle_minus();