2024-10-16 11:40:45 +02:00
|
|
|
import { Button, DatePickerPopup, Date, Palette } from "std-widgets.slint";
|
|
|
|
import { VLabeledComponent } from "LabeledComponent.slint";
|
|
|
|
import { VActionButton } from "ActionButton.slint";
|
|
|
|
import { VButton } from "Button.slint";
|
|
|
|
import { Svg } from "Svg.slint";
|
|
|
|
|
|
|
|
export component VDatePicker inherits VLabeledComponent {
|
|
|
|
in-out property<Date> date;
|
|
|
|
in-out property<string> dateDisplay;
|
|
|
|
|
2024-11-01 13:41:11 +01:00
|
|
|
callback edited(Date);
|
|
|
|
|
2024-10-16 11:40:45 +02:00
|
|
|
pure function formatZeroPadding(number: int) -> string {
|
|
|
|
if (number < 10) {
|
|
|
|
return "0\{number}";
|
|
|
|
}
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
|
|
|
pure function getDateDisplay() -> string {
|
|
|
|
if (date.year == 0) {
|
|
|
|
return "Unscheduled";
|
|
|
|
}
|
|
|
|
return formatZeroPadding(date.day) + "/" + formatZeroPadding(date.month) + "/" + date.year;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetDate() {
|
|
|
|
date.year = 0;
|
|
|
|
date.month = 0;
|
|
|
|
date.day = 0;
|
2024-11-01 13:41:11 +01:00
|
|
|
root.edited(date);
|
2024-10-16 11:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HorizontalLayout {
|
|
|
|
VButton {
|
|
|
|
text: getDateDisplay();
|
|
|
|
enabled: root.enabled;
|
2024-11-01 13:41:11 +01:00
|
|
|
clicked => {taskDateInput.show() }
|
2024-10-16 11:40:45 +02:00
|
|
|
}
|
|
|
|
VActionButton {
|
|
|
|
icon-svg: Svg.reset;
|
|
|
|
icon-svg-stroke-width: 1px;
|
|
|
|
enabled: root.enabled;
|
|
|
|
clicked => { resetDate() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
taskDateInput := DatePickerPopup {
|
2024-11-01 13:41:11 +01:00
|
|
|
accepted(date) => {
|
|
|
|
root.date = date;
|
|
|
|
root.edited(date);
|
|
|
|
}
|
2024-10-16 11:40:45 +02:00
|
|
|
}
|
|
|
|
}
|