Separate calculator display code

This commit is contained in:
Austen Adler 2021-05-19 18:06:15 -04:00
parent af00ba5e28
commit 5d5a3e4a21

View File

@ -225,23 +225,22 @@ impl App {
.enumerate() .enumerate()
.rev() .rev()
.map(|(i, m)| { .map(|(i, m)| {
let content = vec![Spans::from(Span::raw( let number = match self.calculator.get_display_mode() {
match self.calculator.get_display_mode() { CalculatorDisplayMode::Default => format!("{}", m),
CalculatorDisplayMode::Default => format!("{:>2}: {}", i, *m), CalculatorDisplayMode::Separated { separator } => {
CalculatorDisplayMode::Separated { separator } => { format::separated(*m, *separator)
format!("{:>2}: {}", i, format::separated(*m, *separator)) }
} CalculatorDisplayMode::Scientific { precision } => {
CalculatorDisplayMode::Scientific { precision } => { format::scientific(*m, *precision)
format!("{:>2}: {}", i, format::scientific(*m, *precision)) }
} CalculatorDisplayMode::Engineering { precision } => {
CalculatorDisplayMode::Engineering { precision } => { format::engineering(*m, *precision)
format!("{:>2}: {}", i, format::engineering(*m, *precision)) }
} CalculatorDisplayMode::Fixed { precision } => {
CalculatorDisplayMode::Fixed { precision } => { format!("{:0>.precision$}", m, precision = precision)
format!("{:>2}: {:.precision$}", i, m, precision = precision) }
} };
}, let content = vec![Spans::from(Span::raw(format!("{:>2}: {}", i, number)))];
))];
ListItem::new(content) ListItem::new(content)
}) })
.collect(); .collect();