Receiving current local time

This commit is contained in:
Alexey 2025-09-08 14:07:18 +03:00
commit 599b027d19
6 changed files with 94 additions and 30 deletions

36
Cargo.lock generated
View file

@ -149,6 +149,7 @@ dependencies = [
name = "aliveline"
version = "0.1.0"
dependencies = [
"chrono",
"slint",
"slint-build",
]
@ -186,12 +187,6 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
@ -728,16 +723,15 @@ dependencies = [
[[package]]
name = "chrono"
version = "0.4.41"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
"windows-link 0.2.0",
]
[[package]]
@ -4929,7 +4923,7 @@ dependencies = [
"windows-collections",
"windows-core 0.61.2",
"windows-future",
"windows-link",
"windows-link 0.1.3",
"windows-numerics",
]
@ -4963,7 +4957,7 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [
"windows-implement 0.60.0",
"windows-interface 0.59.1",
"windows-link",
"windows-link 0.1.3",
"windows-result 0.3.4",
"windows-strings 0.4.2",
]
@ -4975,7 +4969,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-link",
"windows-link 0.1.3",
"windows-threading",
]
@ -5029,6 +5023,12 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-link"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
[[package]]
name = "windows-numerics"
version = "0.2.0"
@ -5036,7 +5036,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
dependencies = [
"windows-core 0.61.2",
"windows-link",
"windows-link 0.1.3",
]
[[package]]
@ -5054,7 +5054,7 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link",
"windows-link 0.1.3",
]
[[package]]
@ -5073,7 +5073,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [
"windows-link",
"windows-link 0.1.3",
]
[[package]]
@ -5173,7 +5173,7 @@ version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link",
"windows-link 0.1.3",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
@ -5190,7 +5190,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
dependencies = [
"windows-link",
"windows-link 0.1.3",
]
[[package]]

View file

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
chrono = "0.4.42"
slint = "1.12.1"
[build-dependencies]

View file

@ -3,11 +3,17 @@
use std::error::Error;
use chrono::Timelike;
slint::include_modules!();
fn main() -> Result<(), Box<dyn Error>> {
let ui = AppWindow::new()?;
let now = chrono::Local::now();
let offset = now.hour() * 3600 + now.minute() * 60 + now.second();
ui.invoke_update_record_offset(offset as i32);
ui.run()?;
Ok(())

View file

@ -3,14 +3,25 @@ import { RecordWidget } from "record.slint";
import { ReviewWidget } from "review.slint";
export component AppWindow inherits Window {
callback update-record-visible-time <=> record.update-visible-time;
callback start-new-event <=> record.start-new-event;
callback stop-event <=> record.stop-event;
callback update-record-offset(int);
update-record-offset(new-offset) => {
record.offset = new-offset;
}
property<[string]> combo-spans: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
TabWidget {
Tab {
title: "Record";
RecordWidget {}
record := RecordWidget {}
}
Tab {
title: "Review";
ReviewWidget {}
review := ReviewWidget {}
}
}
}

View file

@ -2,13 +2,22 @@ import { VerticalBox, LineEdit, Button, ComboBox } from "std-widgets.slint";
import { Timeline } from "timeline.slint";
export component RecordWidget inherits VerticalBox {
Timeline {
callback update-visible-time(string);
callback start-new-event(string);
callback stop-event;
in-out property visible-time <=> tl.visible-time;
in-out property updating <=> tl.updating;
in-out property offset <=> tl.offset;
property<bool> in-progress: false;
property<string> event-name <=> le.text;
tl := Timeline {
updating: true;
}
GridLayout {
spacing-vertical: 8px;
spacing-horizontal: 16px;
LineEdit {
le := LineEdit {
placeholder-text: "Event name";
text: "Event name";
font-size: 24px;
@ -17,9 +26,17 @@ export component RecordWidget inherits VerticalBox {
row: 0;
}
Button {
text: "Start";
text: updating ? "Stop" : "Start";
colspan: 2;
row: 1;
clicked => {
if in-progress {
root.stop-event();
} else {
root.start-new-event(event-name);
}
in-progress = !in-progress;
}
}
Text {
text: "Span:";
@ -32,6 +49,9 @@ export component RecordWidget inherits VerticalBox {
current-index: 0;
row: 2;
col: 1;
selected(current-value) => {
root.update-visible-time(current-value);
}
}
}
}

View file

@ -5,16 +5,30 @@ export struct TimelineEvent {
label: string
}
global TimeString {
pure function pad-mh(seconds: int, param: int) -> string {
if seconds / param < 10 {
return "0\{floor(seconds / param)}";
}
return "\{floor(seconds / param)}";
}
pure function pad-s(seconds: int) -> string {
if mod(seconds, 60) < 10 {
return "0\{mod(seconds, 60)}";
}
return "\{mod(seconds, 60)}";
}
public pure function from(seconds: int) -> string {
return "\{pad-mh(seconds, 3600)}:\{pad-mh(mod(seconds, 3600), 60)}:\{pad-s(seconds)}";
}
}
export component Timeline inherits Rectangle {
in-out property<bool> updating: true;
in-out property<[TimelineEvent]> events: [
{ start: 5, duration: 3, finished: true, label: "Event 1" },
{ start: 10, duration: 15, finished: true, label: "Event 2" },
{ start: 30, duration: 0, finished: false, label: "Event 3" }
];
in-out property<int> visible-time: 60;
in-out property<[TimelineEvent]> events: [];
in-out property<int> visible-time: 3600;
property<int> visible-offset: max(offset, visible-time);
in-out property<int> offset: 60;
in-out property<int> offset: 0;
timer := Timer {
interval: 1s;
@ -38,6 +52,18 @@ export component Timeline inherits Rectangle {
background: purple;
}
Text {
x: 0;
y: parent.height - self.height;
text: TimeString.from(visible-offset - visible-time);
}
Text {
x: parent.width - self.width;
y: parent.height - self.height;
text: TimeString.from(visible-offset);
}
for event in events: timeline-event := Rectangle {
property<length> real-x: ((visible-time - (visible-offset - event.start)) / visible-time) * parent.width;
x: max(real-x, 0);