Review function
This commit is contained in:
parent
abc9d59810
commit
bb230ab4dc
3 changed files with 50 additions and 18 deletions
|
@ -13,3 +13,6 @@ toml = "0.9.5"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
slint-build = "1.12.1"
|
slint-build = "1.12.1"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "s"
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -12,9 +12,18 @@ slint::include_modules!();
|
||||||
|
|
||||||
impl From<Event> for TimelineEvent {
|
impl From<Event> for TimelineEvent {
|
||||||
fn from(event: Event) -> Self {
|
fn from(event: Event) -> Self {
|
||||||
let start = (event.start.hour as i32) * 3600 + (event.start.minute as i32) * 60 + (event.start.second as i32);
|
let start = (event.start.hour as i32) * 3600
|
||||||
let end = (event.end.hour as i32) * 3600 + (event.end.minute as i32) * 60 + (event.end.second as i32);
|
+ (event.start.minute as i32) * 60
|
||||||
TimelineEvent { start, duration: end - start, label: event.name.to_shared_string(), finished: event.finished }
|
+ (event.start.second as i32);
|
||||||
|
let end = (event.end.hour as i32) * 3600
|
||||||
|
+ (event.end.minute as i32) * 60
|
||||||
|
+ (event.end.second as i32);
|
||||||
|
TimelineEvent {
|
||||||
|
start,
|
||||||
|
duration: end - start,
|
||||||
|
label: event.name.to_shared_string(),
|
||||||
|
finished: event.finished
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +81,26 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
ui.invoke_update_record_offset(offset as i32);
|
ui.invoke_update_record_offset(offset as i32);
|
||||||
|
|
||||||
|
ui.on_fetch_log({
|
||||||
|
let config = config.clone();
|
||||||
|
let ui_weak = ui.as_weak();
|
||||||
|
move |year: i32, month: i32, day: i32| {
|
||||||
|
let ui = ui_weak.unwrap();
|
||||||
|
let date = TomlDate {
|
||||||
|
year: year as u16,
|
||||||
|
month: month as u8,
|
||||||
|
day: day as u8
|
||||||
|
};
|
||||||
|
let events: Vec<TimelineEvent> = Log::load_from(&config, date)
|
||||||
|
.events
|
||||||
|
.iter()
|
||||||
|
.map(|event| TimelineEvent::from((*event).clone()))
|
||||||
|
.collect();
|
||||||
|
let model: ModelRc<TimelineEvent> = Rc::new(VecModel::from(events)).into();
|
||||||
|
ui.set_review_events(model);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ui.on_save_log({
|
ui.on_save_log({
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
let log = writing_log.clone();
|
let log = writing_log.clone();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { VerticalBox, LineEdit, Button, DatePickerPopup, ComboBox } from "std-widgets.slint";
|
import { VerticalBox, LineEdit, Button, DatePickerPopup, ComboBox, Slider } from "std-widgets.slint";
|
||||||
import { Timeline } from "timeline.slint";
|
import { Timeline } from "timeline.slint";
|
||||||
|
|
||||||
export component ReviewWidget inherits VerticalBox {
|
export component ReviewWidget inherits VerticalBox {
|
||||||
|
@ -16,44 +16,44 @@ export component ReviewWidget inherits VerticalBox {
|
||||||
|
|
||||||
tl := Timeline {
|
tl := Timeline {
|
||||||
updating: false;
|
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 {
|
GridLayout {
|
||||||
spacing-vertical: 8px;
|
spacing-vertical: 8px;
|
||||||
spacing-horizontal: 16px;
|
spacing-horizontal: 16px;
|
||||||
|
Slider {
|
||||||
|
minimum: visible-time;
|
||||||
|
maximum: 24 * 3600;
|
||||||
|
value: offset;
|
||||||
|
row: 0;
|
||||||
|
colspan: 2;
|
||||||
|
changed(value) => {
|
||||||
|
offset = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Text {
|
Text {
|
||||||
text: "Day: \{current-day}/\{current-month}/\{current-year}";
|
text: "Day: \{current-day}/\{current-month}/\{current-year}";
|
||||||
font-size: 32px;
|
font-size: 32px;
|
||||||
horizontal-alignment: right;
|
horizontal-alignment: right;
|
||||||
row: 0;
|
row: 1;
|
||||||
}
|
}
|
||||||
Button {
|
Button {
|
||||||
text: "Select";
|
text: "Select";
|
||||||
clicked => {
|
clicked => {
|
||||||
date-picker.show()
|
date-picker.show()
|
||||||
}
|
}
|
||||||
row: 0;
|
row: 1;
|
||||||
col: 1;
|
col: 1;
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
text: "Span: ";
|
text: "Span: ";
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
row: 1;
|
row: 2;
|
||||||
horizontal-alignment: right;
|
horizontal-alignment: right;
|
||||||
}
|
}
|
||||||
ComboBox {
|
ComboBox {
|
||||||
model: combo-spans;
|
model: combo-spans;
|
||||||
current-index: 0;
|
current-index: 0;
|
||||||
row: 1;
|
row: 2;
|
||||||
col: 1;
|
col: 1;
|
||||||
selected(current-value) => {
|
selected(current-value) => {
|
||||||
root.update-visible-time(current-value);
|
root.update-visible-time(current-value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue