Minor refactor
- Separate function to find Unit symbol
This commit is contained in:
parent
0a6cc079c2
commit
9a30647394
@ -4,6 +4,15 @@ use slint::SharedString;
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
fn unit_symbol(units: &str) -> char {
|
||||
match units {
|
||||
"metric" => 'C',
|
||||
"imperial" => 'F',
|
||||
"standard" => 'K',
|
||||
_ => '?',
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let ui = MainWindow::new()?;
|
||||
|
||||
@ -22,12 +31,7 @@ pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box<dyn st
|
||||
let temp = resp.main.as_ref().and_then(|m| m.temp).unwrap_or(0.0);
|
||||
let temperature = format!("{temp:.1}");
|
||||
|
||||
let unit = match cfg.query_params.units.as_str() {
|
||||
"metric" => 'C',
|
||||
"imperial" => 'F',
|
||||
"standard" => 'K',
|
||||
_ => '?',
|
||||
};
|
||||
let unit_symbol = unit_symbol(cfg.query_params.units.as_str());
|
||||
|
||||
ui.set_city(SharedString::from(city));
|
||||
ui.set_country(SharedString::from(country));
|
||||
@ -35,7 +39,7 @@ pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box<dyn st
|
||||
ui.set_weather_description(SharedString::from(weather_description));
|
||||
ui.set_weather_icon(SharedString::from(icon_to_nerd_font(&icon_code)));
|
||||
ui.set_temperature(SharedString::from(temperature));
|
||||
ui.set_unit(SharedString::from(unit));
|
||||
ui.set_unit(SharedString::from(unit_symbol));
|
||||
|
||||
ui.run()?;
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user