1786192210
This commit is contained in:
@@ -111,6 +111,8 @@ impl From<&HassEntity> for WeatherData {
|
||||
}
|
||||
.to_shared_string();
|
||||
|
||||
let label = pretty_label(&kind).to_shared_string();
|
||||
|
||||
let attribution = value
|
||||
.attributes
|
||||
.get("attribution")
|
||||
@@ -216,6 +218,7 @@ impl From<&HassEntity> for WeatherData {
|
||||
|
||||
Self {
|
||||
kind,
|
||||
label,
|
||||
attribution,
|
||||
cloud_coverage,
|
||||
dew_point,
|
||||
@@ -235,3 +238,22 @@ impl From<&HassEntity> for WeatherData {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pretty_label(value: &str) -> String {
|
||||
let value = match value {
|
||||
"partlycloudy" => "partly cloudy",
|
||||
other => other,
|
||||
};
|
||||
value
|
||||
.split(['_', '-', ' '])
|
||||
.filter(|word| !word.is_empty())
|
||||
.map(|word| {
|
||||
let mut chars = word.chars();
|
||||
match chars.next() {
|
||||
Some(first) => first.to_uppercase().collect::<String>() + chars.as_str(),
|
||||
None => String::new(),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ in property <string> : "cloud";
|
||||
import { Palette } from "std-widgets.slint";
|
||||
export struct WeatherData {
|
||||
kind: string,
|
||||
label: string,
|
||||
temperature: float,
|
||||
dew_point: float,
|
||||
temperature_unit: string,
|
||||
@@ -37,6 +38,13 @@ export component Climate inherits Rectangle {
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
Text {
|
||||
text: weather.label;
|
||||
font-size: 24px;
|
||||
font-weight: 500;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
// Text {
|
||||
// width: 150px;
|
||||
// height: 32px;
|
||||
|
||||
Reference in New Issue
Block a user