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!();
|
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>> {
|
pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let ui = MainWindow::new()?;
|
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 temp = resp.main.as_ref().and_then(|m| m.temp).unwrap_or(0.0);
|
||||||
let temperature = format!("{temp:.1}");
|
let temperature = format!("{temp:.1}");
|
||||||
|
|
||||||
let unit = match cfg.query_params.units.as_str() {
|
let unit_symbol = unit_symbol(cfg.query_params.units.as_str());
|
||||||
"metric" => 'C',
|
|
||||||
"imperial" => 'F',
|
|
||||||
"standard" => 'K',
|
|
||||||
_ => '?',
|
|
||||||
};
|
|
||||||
|
|
||||||
ui.set_city(SharedString::from(city));
|
ui.set_city(SharedString::from(city));
|
||||||
ui.set_country(SharedString::from(country));
|
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_description(SharedString::from(weather_description));
|
||||||
ui.set_weather_icon(SharedString::from(icon_to_nerd_font(&icon_code)));
|
ui.set_weather_icon(SharedString::from(icon_to_nerd_font(&icon_code)));
|
||||||
ui.set_temperature(SharedString::from(temperature));
|
ui.set_temperature(SharedString::from(temperature));
|
||||||
ui.set_unit(SharedString::from(unit));
|
ui.set_unit(SharedString::from(unit_symbol));
|
||||||
|
|
||||||
ui.run()?;
|
ui.run()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user