refactor show

This commit is contained in:
2025-07-18 20:31:23 +01:00
parent 59a001b94c
commit 82fed85229
2 changed files with 40 additions and 11 deletions

View File

@@ -299,6 +299,10 @@ impl DispalyState {
self[7].off();
self[8].off();
}
pub fn slice(&mut self, start: usize, len: usize) -> &mut [Segment] {
&mut self.0.as_mut_slice()[start..(start + len)]
}
}
// Show data on segment display

View File

@@ -192,22 +192,47 @@ impl Show for NumberInput {
fn show(&self, display: &mut DispalyState) {
display.off();
display[1].dp();
if !self.enter_exponent && self.significant_pos < DISPLAY_SEGMENTS_SIG {
display[self.significant_pos + 1].prompt();
} else if self.enter_exponent && self.exponent_pos < DISPLAY_SEGMENTS_EXP {
display[DISPLAY_SEGMENTS_SIG + 2 + self.exponent_pos].prompt();
}
let (minus, sig) = display.slice(0, 1 + DISPLAY_SEGMENTS_SIG).split_at_mut(1);
if self.minus {
display[DISPLAY_SEGMENT_SIG_MINUS].minus();
minus[0].minus();
}
for i in 0..self.significant_pos {
display[DISPLAY_SEGMENT_SIG_MINUS + 1 + i].num(self.significant[i]);
for (seg, num) in sig
.iter_mut()
.zip(self.significant.iter())
.take(self.significant_pos)
{
seg.num(*num);
}
if !self.enter_exponent {
if let Some(seg) = sig.get_mut(self.significant_pos) {
seg.prompt();
}
}
let (minus, exp) = display
.slice(1 + DISPLAY_SEGMENTS_SIG, 1 + DISPLAY_SEGMENTS_EXP)
.split_at_mut(1);
if self.minus_exponent {
display[DISPLAY_SEGMENT_EXP_MINUS].minus();
minus[0].minus();
}
for (seg, num) in exp
.iter_mut()
.zip(self.exponent.iter())
.take(self.exponent_pos)
{
seg.num(*num);
}
if self.enter_exponent {
if let Some(seg) = exp.get_mut(self.exponent_pos) {
seg.prompt();
}
for i in 0..self.exponent_pos {
display[DISPLAY_SEGMENT_EXP_MINUS + 1 + i].num(self.exponent[i]);
}
}
}