Prettified code and added review scrolling
This commit is contained in:
parent
99af3eb2b8
commit
abc9d59810
4 changed files with 79 additions and 29 deletions
38
src/main.rs
38
src/main.rs
|
@ -43,31 +43,34 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let now = chrono::Local::now();
|
||||
let offset = now.hour() * 3600 + now.minute() * 60 + now.second();
|
||||
|
||||
let date: TomlDate = TomlDate { day: now.day() as u8, month: now.month() as u8, year: now.year() as u16 };
|
||||
let date: TomlDate = TomlDate {
|
||||
day: now.day() as u8,
|
||||
month: now.month() as u8,
|
||||
year: now.year() as u16
|
||||
};
|
||||
|
||||
let config: Arc<Config> = Arc::new(load_config());
|
||||
let writing_log: Arc<Mutex<Log>> = Arc::new(Mutex::new(Log::load_from(&config, date)));
|
||||
|
||||
{
|
||||
println!("Log: {:?}", writing_log.lock().unwrap().events);
|
||||
let ui_weak = ui.as_weak();
|
||||
let log = writing_log.clone();
|
||||
(move || {
|
||||
println!("c");
|
||||
let ui = ui_weak.unwrap();
|
||||
let log_guard = log.lock().expect("Log shouldn't be used twice");
|
||||
let events: Vec<TimelineEvent> = (*log_guard).events.iter().map(|event| TimelineEvent::from((*event).clone())).collect();
|
||||
let events: Vec<TimelineEvent> = (*log_guard)
|
||||
.events
|
||||
.iter()
|
||||
.map(|event| TimelineEvent::from((*event).clone()))
|
||||
.collect();
|
||||
let in_progress = events.iter().any(|event| !event.finished);
|
||||
let model: ModelRc<TimelineEvent> = Rc::new(VecModel::from(events)).into();
|
||||
println!("get: {:?}", model);
|
||||
ui.set_record_events(model);
|
||||
ui.set_in_progress(in_progress);
|
||||
})()
|
||||
}
|
||||
|
||||
ui.invoke_update_record_offset(offset as i32);
|
||||
ui.invoke_load_log();
|
||||
ui.invoke_another_call();
|
||||
|
||||
ui.on_save_log({
|
||||
let config = config.clone();
|
||||
|
@ -79,24 +82,20 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
ui.on_another_call({
|
||||
println!("outside move");
|
||||
move || {
|
||||
println!("inside move");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ui.on_update_record_visible_time({
|
||||
|
||||
ui.on_update_visible_time({
|
||||
let ui_weak = ui.as_weak();
|
||||
move |hours_string: SharedString| {
|
||||
move |is_record: bool, 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);
|
||||
if is_record {
|
||||
ui.set_record_visible_time(hours * 3600);
|
||||
} else {
|
||||
ui.set_review_visible_time(hours * 3600);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -106,7 +105,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
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>>()
|
||||
|
|
|
@ -4,14 +4,15 @@ import { ReviewWidget } from "review.slint";
|
|||
import { TimelineEvent } from "timeline.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 chain-event <=> record.chain-event;
|
||||
callback update-record-offset(int);
|
||||
callback save-log;
|
||||
callback another-call;
|
||||
callback load-log;
|
||||
|
||||
callback fetch-log <=> review.fetch-log;
|
||||
|
||||
callback update-visible-time(bool, string);
|
||||
|
||||
update-record-offset(new-offset) => {
|
||||
record.offset = new-offset;
|
||||
|
@ -19,8 +20,13 @@ export component AppWindow inherits Window {
|
|||
|
||||
in-out property record-events <=> record.events;
|
||||
in-out property record-offset <=> record.offset;
|
||||
in-out property<int> record-visible-time <=> record.visible-time;
|
||||
in-out property<bool> in-progress <=> record.in-progress;
|
||||
in-out property record-visible-time <=> record.visible-time;
|
||||
in-out property in-progress <=> record.in-progress;
|
||||
|
||||
in-out property review-events <=> review.events;
|
||||
in-out property review-offset <=> review.offset;
|
||||
in-out property review-visible-time <=> review.visible-time;
|
||||
|
||||
property<[string]> combo-spans: ["1 Hour", "4 Hours", "8 Hours", "24 Hours"];
|
||||
|
||||
title: "Aliveline";
|
||||
|
@ -30,11 +36,19 @@ export component AppWindow inherits Window {
|
|||
title: "Record";
|
||||
record := RecordWidget {
|
||||
combo-spans: combo-spans;
|
||||
update-visible-time(time) => {
|
||||
root.update-visible-time(true, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
Tab {
|
||||
title: "Review";
|
||||
review := ReviewWidget {}
|
||||
review := ReviewWidget {
|
||||
combo-spans: combo-spans;
|
||||
update-visible-time(time) => {
|
||||
root.update-visible-time(false, time)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,31 @@
|
|||
import { VerticalBox, LineEdit, Button, DatePickerPopup } from "std-widgets.slint";
|
||||
import { VerticalBox, LineEdit, Button, DatePickerPopup, ComboBox } from "std-widgets.slint";
|
||||
import { Timeline } from "timeline.slint";
|
||||
|
||||
export component ReviewWidget inherits VerticalBox {
|
||||
callback update-visible-time(string);
|
||||
callback fetch-log(int, int, int);
|
||||
|
||||
property<int> max-offset: 24 * 3600;
|
||||
property<int> current-year;
|
||||
property<int> current-month;
|
||||
property<int> current-day;
|
||||
|
||||
Timeline {
|
||||
in property<[string]> combo-spans: [];
|
||||
in-out property visible-time <=> tl.visible-time;
|
||||
in-out property offset <=> tl.offset;
|
||||
in-out property events <=> tl.events;
|
||||
|
||||
tl := Timeline {
|
||||
updating: false;
|
||||
TouchArea {
|
||||
preferred-width: 100%;
|
||||
preferred-height: 100%;
|
||||
moved => {
|
||||
if self.pressed {
|
||||
root.offset -= (self.mouse-x - self.pressed-x) / 1px;
|
||||
root.offset = clamp(root.offset, visible-time, max-offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GridLayout {
|
||||
spacing-vertical: 8px;
|
||||
|
@ -16,12 +34,30 @@ export component ReviewWidget inherits VerticalBox {
|
|||
text: "Day: \{current-day}/\{current-month}/\{current-year}";
|
||||
font-size: 32px;
|
||||
horizontal-alignment: right;
|
||||
row: 0;
|
||||
}
|
||||
Button {
|
||||
text: "Select";
|
||||
clicked => {
|
||||
date-picker.show()
|
||||
}
|
||||
row: 0;
|
||||
col: 1;
|
||||
}
|
||||
Text {
|
||||
text: "Span: ";
|
||||
font-size: 24px;
|
||||
row: 1;
|
||||
horizontal-alignment: right;
|
||||
}
|
||||
ComboBox {
|
||||
model: combo-spans;
|
||||
current-index: 0;
|
||||
row: 1;
|
||||
col: 1;
|
||||
selected(current-value) => {
|
||||
root.update-visible-time(current-value);
|
||||
}
|
||||
}
|
||||
}
|
||||
date-picker := DatePickerPopup {
|
||||
|
@ -32,6 +68,7 @@ export component ReviewWidget inherits VerticalBox {
|
|||
current-year = date.year;
|
||||
current-month = date.month;
|
||||
current-day = date.day;
|
||||
root.fetch-log(current-year, current-month, current-day);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,4 +85,5 @@ export component Timeline inherits Rectangle {
|
|||
visible: timeline-event.visible;
|
||||
}
|
||||
}
|
||||
@children
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue