Skip to content

Commit

Permalink
Energy monitor: Fix deprecated warning and improve menu on android
Browse files Browse the repository at this point in the history
- `chrono::Duration::days` is marked as deprecated in the last release.
- Add a clip rectangle to the menu, otherwise it shows under the android
title bar.
- Make the menu animation a bid faster so it looks more fluid
  • Loading branch information
ogoffart committed Mar 11, 2024
1 parent 9345638 commit 524742e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/energy-monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
slint = { path = "../../api/rs/slint", default-features = false, features = ["compat-1-2"] }
mcu-board-support = { path = "../mcu-board-support", optional = true }
chrono = { version = "0.4.23", optional = true, default-features = false, features = ["clock", "std", "wasmbind"] }
chrono = { version = "0.4.34", optional = true, default-features = false, features = ["clock", "std", "wasmbind"] }
weer_api = { version = "0.1", optional = true }
tokio = { version = "1.25", optional = true, features = ["full"] }
futures = { version = "0.3.26", optional = true }
Expand Down
21 changes: 13 additions & 8 deletions examples/energy-monitor/src/controllers/weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ async fn weather_worker_loop(window_weak: Weak<MainWindow>) {
let mut forecast_days = vec![];

let client = Client::new(&api_key, true);
let mut forecast_list =
future::join_all((0..FORECAST_DAYS).map(|i| {
let client = client.clone();
async move {
current_forecast(client.clone(), lat, long, now + chrono::Duration::days(i)).await
}
}))
.await;
let mut forecast_list = future::join_all((0..FORECAST_DAYS).map(|i| {
let client = client.clone();
async move {
current_forecast(
client.clone(),
lat,
long,
now + chrono::TimeDelta::try_days(i).unwrap_or_default(),
)
.await
}
}))
.await;

for i in 0..forecast_list.len() {
if let Some((date, forecast)) = forecast_list.remove(0) {
Expand Down
52 changes: 28 additions & 24 deletions examples/energy-monitor/ui/widgets/menu.slint
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,37 @@ export component MobileMenu {
root.open = false;
}

menu := Rectangle {
x: root.menu-x;
y: -self.height;
width: root.menu-width;
height: root.height / 2;
visible: visibility > 0.0;
Rectangle {
clip: true;
menu := Rectangle {
x: root.menu-x;
y: -self.height;
width: root.menu-width;
height: root.height / 2;
visible: visibility > 0.0;

private property <float> visibility;

MenuBackground {
// avoid click-through
TouchArea {}

@children
}

private property <float> visibility;
states [
open when root.open : {
menu.y: end-y;
visibility: 1.0;

MenuBackground {
// avoid click-through
TouchArea {}
out {
animate visibility { duration: Theme.durations.medium; }
}
}
]

@children
animate y { duration: Theme.durations.fast; }
}

states [
open when root.open : {
menu.y: end-y;
visibility: 1.0;

out {
animate visibility { duration: Theme.durations.medium; }
}
}
]

animate y { duration: Theme.durations.slow; }
}
}
}

0 comments on commit 524742e

Please sign in to comment.