Skip to content

Commit e7741e0

Browse files
author
Ruslan
committed
Get the bins sorta rendered
1 parent d3161ee commit e7741e0

5 files changed

Lines changed: 64 additions & 7 deletions

File tree

src/main.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use chrono::{Datelike, Local, Timelike};
1+
use std::sync::Arc;
2+
3+
use chrono::{Datelike, Local, TimeZone, Timelike};
24
use slint::{Timer, TimerMode};
35

46
#[cfg(target_arch = "wasm32")]
@@ -16,12 +18,15 @@ pub fn main() {
1618
let app = App::new().unwrap();
1719
let app_weak = app.as_weak();
1820

21+
let app_arc = Arc::new(app_weak);
22+
23+
let app_clock = Arc::clone(&app_arc);
1924
let timer = Timer::default();
2025
timer.start(
2126
TimerMode::Repeated,
2227
std::time::Duration::from_millis(1000),
2328
move || {
24-
if let Some(app) = app_weak.upgrade() {
29+
if let Some(app) = app_clock.upgrade() {
2530
let api = app.global::<Api>();
2631
let now = Local::now();
2732
let mut date = Date::default();
@@ -39,5 +44,33 @@ pub fn main() {
3944
},
4045
);
4146

47+
let app_bin = Arc::clone(&app_arc);
48+
Timer::default().start(
49+
TimerMode::Repeated,
50+
std::time::Duration::from_secs(60 * 60),
51+
move || {
52+
if let Some(app) = app_bin.upgrade() {
53+
let api = app.global::<Api>();
54+
api.set_is_yellow_bin(is_yellow_bin());
55+
}
56+
},
57+
);
58+
4259
app.run().expect("AppWindow::run() failed");
4360
}
61+
62+
// Yellow alternate every week
63+
pub fn is_yellow_bin() -> bool {
64+
let known_yellow_bin_day = Local.with_ymd_and_hms(2024, 5, 13, 0, 0, 0).unwrap();
65+
let diff = Local::now() - known_yellow_bin_day;
66+
67+
// I threw 💩 until it sorta worked
68+
// Good luck
69+
70+
let wat = diff.num_days() % 14;
71+
72+
if wat != 0 && wat <= 7 {
73+
return false;
74+
}
75+
return true;
76+
}

ui/api.slint

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { Date, Time } from "std-widgets.slint";
22

33
export global Api {
4-
in property <float> indoor-temperature: 22.0;
5-
in property <float> outdoor-temperature: 24.0;
6-
7-
in property <float> price-of-electricity: 13.0;
8-
in property <float> current-electricity-use: 152.9;
4+
in-out property <bool> is-yellow-bin:true;
95

106
in-out property <Date> current-date: {
117
year: 2025,

ui/app.slint

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AboutSlint, VerticalBox, HorizontalBox } from "std-widgets.slint";
22
import { Api } from "./api.slint";
33
import { Time } from "components/time.slint";
4+
import { Bin } from "components/bin.slint";
45

56
export {Api}
67

@@ -11,6 +12,21 @@ export component App inherits Window {
1112

1213
HorizontalLayout {
1314

15+
HorizontalBox {
16+
17+
Bin {
18+
color: red;
19+
}
20+
21+
Bin {
22+
color: green;
23+
}
24+
25+
if(Api.is-yellow-bin): Bin {
26+
color: yellow;
27+
}
28+
}
29+
1430
Time {
1531
time: Api.current-time;
1632
date: Api.current-date;

ui/components/bin.slint

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import "../fa-regular-400.ttf";
2+
3+
4+
export component Bin {
5+
in property <color> color;
6+
Text {
7+
font-size: 48px;
8+
font-family: "Font Awesome 6 Free";
9+
color: color;
10+
text: @tr(""); // https://fontawesome.com/icons/trash-can?f=classic&s=regular
11+
}
12+
}

ui/fa-regular-400.ttf

66.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)