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

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);