Events starting and stopping
This commit is contained in:
parent
599b027d19
commit
3509263a06
3 changed files with 50 additions and 3 deletions
37
src/main.rs
37
src/main.rs
|
@ -4,6 +4,7 @@
|
|||
use std::error::Error;
|
||||
|
||||
use chrono::Timelike;
|
||||
use slint::{Model, SharedString, VecModel};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
|
@ -14,6 +15,42 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
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(|a| a.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.run()?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { TabWidget } from "std-widgets.slint";
|
||||
import { RecordWidget } from "record.slint";
|
||||
import { ReviewWidget } from "review.slint";
|
||||
import { TimelineEvent } from "timeline.slint";
|
||||
|
||||
export component AppWindow inherits Window {
|
||||
callback update-record-visible-time <=> record.update-visible-time;
|
||||
|
@ -12,12 +13,19 @@ export component AppWindow inherits Window {
|
|||
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 {
|
||||
Tab {
|
||||
title: "Record";
|
||||
record := RecordWidget {}
|
||||
record := RecordWidget {
|
||||
combo-spans: combo-spans;
|
||||
}
|
||||
}
|
||||
Tab {
|
||||
title: "Review";
|
||||
|
|
|
@ -8,6 +8,8 @@ export component RecordWidget inherits VerticalBox {
|
|||
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;
|
||||
|
||||
|
@ -26,7 +28,7 @@ export component RecordWidget inherits VerticalBox {
|
|||
row: 0;
|
||||
}
|
||||
Button {
|
||||
text: updating ? "Stop" : "Start";
|
||||
text: in-progress ? "Stop" : "Start";
|
||||
colspan: 2;
|
||||
row: 1;
|
||||
clicked => {
|
||||
|
@ -45,7 +47,7 @@ export component RecordWidget inherits VerticalBox {
|
|||
horizontal-alignment: right;
|
||||
}
|
||||
ComboBox {
|
||||
model: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
||||
model: combo-spans;
|
||||
current-index: 0;
|
||||
row: 2;
|
||||
col: 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue