From 90f42ad66feb6b77474d0da267d572eca16e2826 Mon Sep 17 00:00:00 2001 From: sam-anthony Date: Tue, 8 Mar 2022 19:55:08 -0330 Subject: switchable pressure unit --- src/ui.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs index 9411157..65b1ad0 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,10 +1,4 @@ -use crate::{ - app::App, - unit_of_measurement::{ - pressure::{self, Pressure}, - UnitOfMeasurement, - }, -}; +use crate::{app::App, input::InputParam, unit_of_measurement::UnitOfMeasurement}; use std::ptr; use tui::{ layout::Constraint, @@ -15,10 +9,15 @@ use tui::{ pub fn input_table(app: &App) -> impl Widget { let rows = app.rows().iter().map(|row| { let cells = row.iter().map(|item| { + let item_str = match item { + InputParam::Rpm(rpm) => rpm.to_string(), + InputParam::Ve(ve) => ve.to_string(), + InputParam::Map(p) => p.as_unit(app.pressure_unit).to_string(), + }; if ptr::eq(item, app.selected_input_param()) { - Cell::from(item.string()).style(Style::default().fg(Color::Yellow)) + Cell::from(item_str).style(Style::default().fg(Color::Yellow)) } else { - Cell::from(item.string()) + Cell::from(item_str) } }); widgets::Row::new(cells) @@ -35,10 +34,10 @@ pub fn input_table(app: &App) -> impl Widget { } pub fn output_table(app: &App) -> impl Widget { - let map = match app.rows()[0].map.string().parse::() { - Ok(p) => Pressure::from_unit(pressure::Unit::KiloPascal, p), - Err(_) => Pressure::default(), - }; - Paragraph::new(map.as_unit(pressure::Unit::KiloPascal).to_string()) - .block(Block::default().title("map").borders(Borders::ALL)) + if let InputParam::Map(p) = &app.rows()[0].map { + Paragraph::new(p.as_unit(app.pressure_unit).to_string()) + .block(Block::default().title("map").borders(Borders::ALL)) + } else { + Paragraph::new("err").block(Block::default().title("map").borders(Borders::ALL)) + } } -- cgit v1.2.3