auto enter on full entry
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -113,7 +113,7 @@ impl NumberInput {
|
|||||||
*self = Self::default();
|
*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 {
|
if val > 9 {
|
||||||
panic!("Bad significatn val");
|
panic!("Bad significatn val");
|
||||||
}
|
}
|
||||||
@@ -122,10 +122,10 @@ impl NumberInput {
|
|||||||
}
|
}
|
||||||
self.significant[self.significant_pos] = val;
|
self.significant[self.significant_pos] = val;
|
||||||
self.significant_pos += 1;
|
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 {
|
if val > 9 {
|
||||||
panic!("Bad exponent val");
|
panic!("Bad exponent val");
|
||||||
}
|
}
|
||||||
@@ -134,10 +134,10 @@ impl NumberInput {
|
|||||||
}
|
}
|
||||||
self.exponent[self.exponent_pos] = val;
|
self.exponent[self.exponent_pos] = val;
|
||||||
self.exponent_pos += 1;
|
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 {
|
if self.enter_exponent {
|
||||||
self.input_exponent(val)
|
self.input_exponent(val)
|
||||||
} else {
|
} else {
|
||||||
@@ -290,8 +290,12 @@ impl CalcluclatorState {
|
|||||||
Ok(CalcluclatorState::EnterSignificant)
|
Ok(CalcluclatorState::EnterSignificant)
|
||||||
}
|
}
|
||||||
KeyPress::Num(val) => {
|
KeyPress::Num(val) => {
|
||||||
number_input.input(val)?;
|
if number_input.input(val)? {
|
||||||
Ok(CalcluclatorState::EnterSignificant)
|
number_input.enter_exponent();
|
||||||
|
Ok(CalcluclatorState::EnterExponent)
|
||||||
|
} else {
|
||||||
|
Ok(CalcluclatorState::EnterSignificant)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
KeyPress::Minus => {
|
KeyPress::Minus => {
|
||||||
number_input.toggle_minus();
|
number_input.toggle_minus();
|
||||||
@@ -310,8 +314,13 @@ impl CalcluclatorState {
|
|||||||
Ok(CalcluclatorState::EnterSignificant)
|
Ok(CalcluclatorState::EnterSignificant)
|
||||||
}
|
}
|
||||||
KeyPress::Num(val) => {
|
KeyPress::Num(val) => {
|
||||||
number_input.input(val)?;
|
if number_input.input(val)? {
|
||||||
Ok(CalcluclatorState::EnterExponent)
|
number_input.done();
|
||||||
|
calc.push(number_input.to_decimal())?;
|
||||||
|
Ok(CalcluclatorState::EnterOperation)
|
||||||
|
} else {
|
||||||
|
Ok(CalcluclatorState::EnterExponent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
KeyPress::Minus => {
|
KeyPress::Minus => {
|
||||||
number_input.toggle_minus();
|
number_input.toggle_minus();
|
||||||
|
|||||||
Reference in New Issue
Block a user