diff options
| author | sam-anthony <samanthony6@protonmail.com> | 2022-03-08 19:55:08 -0330 |
|---|---|---|
| committer | sam-anthony <samanthony6@protonmail.com> | 2022-03-08 19:55:08 -0330 |
| commit | 90f42ad66feb6b77474d0da267d572eca16e2826 (patch) | |
| tree | a35319f2457e2e65bf8ff4536e142b7211fb09b9 /src/ui.rs | |
| parent | d286ed3eb877365c01f7a7ec56de9a0dc84bab2e (diff) | |
| download | volute-90f42ad66feb6b77474d0da267d572eca16e2826.zip | |
switchable pressure unit
Diffstat (limited to 'src/ui.rs')
| -rw-r--r-- | src/ui.rs | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -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::<i32>() { - 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)) + } } |