Compare commits
4 commits
ca6e12c9e0
...
e815e5b439
Author | SHA1 | Date | |
---|---|---|---|
e815e5b439 | |||
8d5d3584b1 | |||
3509263a06 | |||
599b027d19 |
8 changed files with 247 additions and 36 deletions
70
Cargo.lock
generated
70
Cargo.lock
generated
|
@ -149,8 +149,11 @@ dependencies = [
|
||||||
name = "aliveline"
|
name = "aliveline"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"serde",
|
||||||
"slint",
|
"slint",
|
||||||
"slint-build",
|
"slint-build",
|
||||||
|
"toml 0.9.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -186,12 +189,6 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "android-tzdata"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android_system_properties"
|
name = "android_system_properties"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
@ -728,16 +725,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.41"
|
version = "0.4.42"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
|
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"windows-link",
|
"windows-link 0.2.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3839,6 +3835,15 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_spanned"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
@ -3899,7 +3904,7 @@ dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tar",
|
"tar",
|
||||||
"toml",
|
"toml 0.8.23",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4166,7 +4171,7 @@ dependencies = [
|
||||||
"cfg-expr",
|
"cfg-expr",
|
||||||
"heck",
|
"heck",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"toml",
|
"toml 0.8.23",
|
||||||
"version-compare",
|
"version-compare",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4340,11 +4345,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
|
checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned 0.6.9",
|
||||||
"toml_datetime 0.6.11",
|
"toml_datetime 0.6.11",
|
||||||
"toml_edit 0.22.27",
|
"toml_edit 0.22.27",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8"
|
||||||
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
|
"serde",
|
||||||
|
"serde_spanned 1.0.0",
|
||||||
|
"toml_datetime 0.7.0",
|
||||||
|
"toml_parser",
|
||||||
|
"toml_writer",
|
||||||
|
"winnow",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.11"
|
version = "0.6.11"
|
||||||
|
@ -4371,7 +4391,7 @@ checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_spanned",
|
"serde_spanned 0.6.9",
|
||||||
"toml_datetime 0.6.11",
|
"toml_datetime 0.6.11",
|
||||||
"toml_write",
|
"toml_write",
|
||||||
"winnow",
|
"winnow",
|
||||||
|
@ -4929,7 +4949,7 @@ dependencies = [
|
||||||
"windows-collections",
|
"windows-collections",
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-future",
|
"windows-future",
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
"windows-numerics",
|
"windows-numerics",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4963,7 +4983,7 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-implement 0.60.0",
|
"windows-implement 0.60.0",
|
||||||
"windows-interface 0.59.1",
|
"windows-interface 0.59.1",
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
"windows-result 0.3.4",
|
"windows-result 0.3.4",
|
||||||
"windows-strings 0.4.2",
|
"windows-strings 0.4.2",
|
||||||
]
|
]
|
||||||
|
@ -4975,7 +4995,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
"windows-threading",
|
"windows-threading",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5029,6 +5049,12 @@ version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-numerics"
|
name = "windows-numerics"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -5036,7 +5062,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
|
checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.61.2",
|
"windows-core 0.61.2",
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5054,7 +5080,7 @@ version = "0.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5073,7 +5099,7 @@ version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5173,7 +5199,7 @@ version = "0.53.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
"windows_aarch64_gnullvm 0.53.0",
|
"windows_aarch64_gnullvm 0.53.0",
|
||||||
"windows_aarch64_msvc 0.53.0",
|
"windows_aarch64_msvc 0.53.0",
|
||||||
"windows_i686_gnu 0.53.0",
|
"windows_i686_gnu 0.53.0",
|
||||||
|
@ -5190,7 +5216,7 @@ version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
|
checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -6,7 +6,10 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4.42"
|
||||||
|
serde = "1.0.219"
|
||||||
slint = "1.12.1"
|
slint = "1.12.1"
|
||||||
|
toml = "0.9.5"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
slint-build = "1.12.1"
|
slint-build = "1.12.1"
|
||||||
|
|
20
src/config.rs
Normal file
20
src/config.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
pub log_path: PathBuf
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Config {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Config { log_path: PathBuf::from("./logs") }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load(path: PathBuf) -> Self {
|
||||||
|
if let Ok(toml_string) = std::fs::read_to_string(path) {
|
||||||
|
return toml::from_str(&toml_string).unwrap_or(Config::new());
|
||||||
|
}
|
||||||
|
Config::new()
|
||||||
|
}
|
||||||
|
}
|
14
src/lib.rs
Normal file
14
src/lib.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
use config::Config;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub mod config;
|
||||||
|
|
||||||
|
pub fn load_config() -> Config {
|
||||||
|
if let Ok(path_str) = std::env::var("XDG_CONFIG_HOME") {
|
||||||
|
let mut path = PathBuf::from(path_str);
|
||||||
|
path.push("aliveline");
|
||||||
|
path.push("config.toml");
|
||||||
|
return Config::load(path);
|
||||||
|
}
|
||||||
|
Config::new()
|
||||||
|
}
|
71
src/main.rs
71
src/main.rs
|
@ -3,11 +3,82 @@
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
|
use aliveline::{config::Config, load_config};
|
||||||
|
use chrono::Timelike;
|
||||||
|
use slint::{Model, SharedString, VecModel};
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let ui = AppWindow::new()?;
|
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.on_update_record_visible_time({
|
||||||
|
let ui_weak = ui.as_weak();
|
||||||
|
move |hours_string: SharedString| {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
let hours = hours_string.split(' ')
|
||||||
|
.next()
|
||||||
|
.map(|h| h.parse::<i32>().unwrap())
|
||||||
|
.unwrap();
|
||||||
|
ui.set_record_visible_time(hours * 3600);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.on_start_new_event({
|
||||||
|
let ui_weak = ui.as_weak();
|
||||||
|
move |event_name: SharedString| {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
let events_rc = ui.get_record_events();
|
||||||
|
let events = events_rc.as_any()
|
||||||
|
.downcast_ref::<VecModel<TimelineEvent>>()
|
||||||
|
.unwrap();
|
||||||
|
let offset = ui.get_record_offset();
|
||||||
|
events.push(TimelineEvent {
|
||||||
|
duration: 0,
|
||||||
|
finished: false,
|
||||||
|
label: event_name,
|
||||||
|
start: offset
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.on_stop_event({
|
||||||
|
let ui_weak = ui.as_weak();
|
||||||
|
move || {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
let events_rc = ui.get_record_events();
|
||||||
|
let events = events_rc.as_any().downcast_ref::<VecModel<TimelineEvent>>().unwrap();
|
||||||
|
let offset = ui.get_record_offset();
|
||||||
|
|
||||||
|
let event_id = events.iter().position(|data| !data.finished).unwrap();
|
||||||
|
let event = events.row_data(event_id).expect("stop-event called without unfinished events");
|
||||||
|
let new_event = TimelineEvent {
|
||||||
|
duration: offset - event.start,
|
||||||
|
finished: true,
|
||||||
|
label: event.label,
|
||||||
|
start: event.start
|
||||||
|
};
|
||||||
|
|
||||||
|
events.set_row_data(event_id, new_event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.on_chain_event({
|
||||||
|
let ui_weak = ui.as_weak();
|
||||||
|
move |event_name: SharedString| {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
ui.invoke_stop_event();
|
||||||
|
ui.invoke_start_new_event(event_name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let config: Config = load_config();
|
||||||
|
println!("logs path: {}", config.log_path.to_str().unwrap());
|
||||||
|
|
||||||
ui.run()?;
|
ui.run()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,16 +1,36 @@
|
||||||
import { TabWidget } from "std-widgets.slint";
|
import { TabWidget } from "std-widgets.slint";
|
||||||
import { RecordWidget } from "record.slint";
|
import { RecordWidget } from "record.slint";
|
||||||
import { ReviewWidget } from "review.slint";
|
import { ReviewWidget } from "review.slint";
|
||||||
|
import { TimelineEvent } from "timeline.slint";
|
||||||
|
|
||||||
export component AppWindow inherits Window {
|
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 chain-event <=> record.chain-event;
|
||||||
|
callback update-record-offset(int);
|
||||||
|
|
||||||
|
update-record-offset(new-offset) => {
|
||||||
|
record.offset = new-offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
in-out property record-events <=> record.events;
|
||||||
|
in-out property record-offset <=> record.offset;
|
||||||
|
in-out property<int> record-visible-time <=> record.visible-time;
|
||||||
|
property<[string]> combo-spans: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
||||||
|
|
||||||
|
title: "Aliveline";
|
||||||
|
|
||||||
TabWidget {
|
TabWidget {
|
||||||
Tab {
|
Tab {
|
||||||
title: "Record";
|
title: "Record";
|
||||||
RecordWidget {}
|
record := RecordWidget {
|
||||||
|
combo-spans: combo-spans;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Tab {
|
Tab {
|
||||||
title: "Review";
|
title: "Review";
|
||||||
ReviewWidget {}
|
review := ReviewWidget {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,25 @@ import { VerticalBox, LineEdit, Button, ComboBox } from "std-widgets.slint";
|
||||||
import { Timeline } from "timeline.slint";
|
import { Timeline } from "timeline.slint";
|
||||||
|
|
||||||
export component RecordWidget inherits VerticalBox {
|
export component RecordWidget inherits VerticalBox {
|
||||||
Timeline {
|
callback update-visible-time(string);
|
||||||
|
callback start-new-event(string);
|
||||||
|
callback chain-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;
|
||||||
|
in-out property events <=> tl.events;
|
||||||
|
in property<[string]> combo-spans: [];
|
||||||
|
property<bool> in-progress: false;
|
||||||
|
property<string> event-name <=> le.text;
|
||||||
|
|
||||||
|
tl := Timeline {
|
||||||
updating: true;
|
updating: true;
|
||||||
}
|
}
|
||||||
GridLayout {
|
GridLayout {
|
||||||
spacing-vertical: 8px;
|
spacing-vertical: 8px;
|
||||||
spacing-horizontal: 16px;
|
spacing-horizontal: 16px;
|
||||||
LineEdit {
|
le := LineEdit {
|
||||||
placeholder-text: "Event name";
|
placeholder-text: "Event name";
|
||||||
text: "Event name";
|
text: "Event name";
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
|
@ -17,9 +29,25 @@ export component RecordWidget inherits VerticalBox {
|
||||||
row: 0;
|
row: 0;
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "Start";
|
text: in-progress ? "Stop" : "Start";
|
||||||
colspan: 2;
|
|
||||||
row: 1;
|
row: 1;
|
||||||
|
clicked => {
|
||||||
|
if in-progress {
|
||||||
|
root.stop-event();
|
||||||
|
} else {
|
||||||
|
root.start-new-event(event-name);
|
||||||
|
}
|
||||||
|
in-progress = !in-progress;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Button {
|
||||||
|
text: "Chain";
|
||||||
|
enabled: in-progress;
|
||||||
|
col: 1;
|
||||||
|
row: 1;
|
||||||
|
clicked => {
|
||||||
|
root.chain-event(event-name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
text: "Span:";
|
text: "Span:";
|
||||||
|
@ -28,10 +56,13 @@ export component RecordWidget inherits VerticalBox {
|
||||||
horizontal-alignment: right;
|
horizontal-alignment: right;
|
||||||
}
|
}
|
||||||
ComboBox {
|
ComboBox {
|
||||||
model: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
model: combo-spans;
|
||||||
current-index: 0;
|
current-index: 0;
|
||||||
row: 2;
|
row: 2;
|
||||||
col: 1;
|
col: 1;
|
||||||
|
selected(current-value) => {
|
||||||
|
root.update-visible-time(current-value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,16 +5,30 @@ export struct TimelineEvent {
|
||||||
label: string
|
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 {
|
export component Timeline inherits Rectangle {
|
||||||
in-out property<bool> updating: true;
|
in-out property<bool> updating: true;
|
||||||
in-out property<[TimelineEvent]> events: [
|
in-out property<[TimelineEvent]> events: [];
|
||||||
{ start: 5, duration: 3, finished: true, label: "Event 1" },
|
in-out property<int> visible-time: 3600;
|
||||||
{ 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;
|
|
||||||
property<int> visible-offset: max(offset, visible-time);
|
property<int> visible-offset: max(offset, visible-time);
|
||||||
in-out property<int> offset: 60;
|
in-out property<int> offset: 0;
|
||||||
|
|
||||||
timer := Timer {
|
timer := Timer {
|
||||||
interval: 1s;
|
interval: 1s;
|
||||||
|
@ -38,6 +52,18 @@ export component Timeline inherits Rectangle {
|
||||||
background: purple;
|
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 {
|
for event in events: timeline-event := Rectangle {
|
||||||
property<length> real-x: ((visible-time - (visible-offset - event.start)) / visible-time) * parent.width;
|
property<length> real-x: ((visible-time - (visible-offset - event.start)) / visible-time) * parent.width;
|
||||||
x: max(real-x, 0);
|
x: max(real-x, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue