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>>()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue