1786192210

This commit is contained in:
2026-08-08 14:30:10 +02:00
parent 6ae41ef85d
commit c3111e9018
2 changed files with 30 additions and 0 deletions

View File

@@ -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(" ")
}

View File

@@ -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;