1786193359
This commit is contained in:
@@ -97,19 +97,17 @@ supported_features: int
|
||||
*/
|
||||
impl From<&HassEntity> for WeatherData {
|
||||
fn from(value: &HassEntity) -> Self {
|
||||
let kind = match value.state.as_str() {
|
||||
"sunny" => "sun",
|
||||
"clear-night" => "moon",
|
||||
// "partlycloudy" if is_night => "cloud-moon",
|
||||
"partlycloudy" => "cloud-sun",
|
||||
"rainy" => "cloud-rain",
|
||||
"pouring" | "windy" | "windy-variant" => "cloud-rain-wind",
|
||||
"lightning" | "lightning-rainy" => "cloud-lightning",
|
||||
"snowy" | "snowy-rainy" | "hail" => "snowflake",
|
||||
"fog" => "cloud-fog",
|
||||
_ => "cloud",
|
||||
}
|
||||
.to_shared_string();
|
||||
let icon_index = match value.state.as_str() {
|
||||
"sunny" => 0,
|
||||
"partlycloudy" => 1,
|
||||
"clear-night" => 9,
|
||||
"rainy" => 4,
|
||||
"pouring" | "windy" | "windy-variant" => 5,
|
||||
"lightning" | "lightning-rainy" => 6,
|
||||
"snowy" | "snowy-rainy" | "hail" => 7,
|
||||
"fog" => 8,
|
||||
_ => 3,
|
||||
};
|
||||
|
||||
let label = pretty_label(&value.state).to_shared_string();
|
||||
|
||||
@@ -217,7 +215,7 @@ impl From<&HassEntity> for WeatherData {
|
||||
.to_shared_string();
|
||||
|
||||
Self {
|
||||
kind,
|
||||
icon_index,
|
||||
label,
|
||||
attribution,
|
||||
cloud_coverage,
|
||||
|
||||
@@ -7,7 +7,7 @@ in property <string> : "cloud";
|
||||
|
||||
import { Palette, HorizontalBox, VerticalBox } from "std-widgets.slint";
|
||||
export struct WeatherData {
|
||||
kind: string,
|
||||
icon-index: int,
|
||||
label: string,
|
||||
temperature: float,
|
||||
dew_point: float,
|
||||
@@ -31,10 +31,19 @@ export component Climate inherits Rectangle {
|
||||
in property <WeatherData> weather;
|
||||
in property <bool> is-night;
|
||||
|
||||
property <int> icon-index: weather.icon-index == 1 && is-night ? 2 : weather.icon-index;
|
||||
|
||||
property <[image]> icons: [
|
||||
@image-url("icons/sun.svg"),
|
||||
@image-url("icons/cloud-sun.svg"),
|
||||
@image-url("icons/cloud-moon.svg")
|
||||
@image-url("icons/cloud-moon.svg"),
|
||||
@image-url("icons/cloud.svg"),
|
||||
@image-url("icons/cloud-rain.svg"),
|
||||
@image-url("icons/cloud-rain-wind.svg"),
|
||||
@image-url("icons/cloud-lightning.svg"),
|
||||
@image-url("icons/snowflake.svg"),
|
||||
@image-url("icons/cloud-fog.svg"),
|
||||
@image-url("icons/moon.svg"),
|
||||
];
|
||||
|
||||
VerticalLayout {
|
||||
@@ -63,20 +72,11 @@ export component Climate inherits Rectangle {
|
||||
colorize: Palette.foreground;
|
||||
width: 120px;
|
||||
height: 105px;
|
||||
source: icons[0];
|
||||
source: icons[icon-index];
|
||||
image-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle { }
|
||||
}
|
||||
|
||||
// Text {
|
||||
// width: 150px;
|
||||
// height: 32px;
|
||||
// text: weather.outside-high;
|
||||
// font-size: 20px;
|
||||
// font-weight: 700;
|
||||
// vertical-alignment: center;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user