Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Energy monitor: Fix deprecated warning and improve menu on android #4808

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}
}
Loading