Add current time indicator of the current day on the Calendar

This commit is contained in:
Vyn 2024-11-06 18:38:42 +01:00
parent ab2200ecc1
commit e2cd994026
9 changed files with 54 additions and 8 deletions

View file

@ -22,6 +22,8 @@ export enum CalendarDateDisplayFormat {
export component Calendar inherits Rectangle {
in property<[CalendarDay]> days;
in property <CalendarDateDisplayFormat> format;
in property <Date> current-date;
in property <Time> current-time;
private property <length> header-height: 64px;
private property <length> available-day-space: self.height - header-height;
private property <length> day-start-y: header-height;
@ -83,6 +85,13 @@ export component Calendar inherits Rectangle {
y: day-start-y + hour-spacing * hour-index;
height: 1px;
}
if day.date == root.current-date : Rectangle {
background: Palette.red;
x: 0px;
width: parent.width;
y: day-start-y + hour-spacing * root.current-time.hour + (root.current-time.minute / 60 * hour-spacing);
height: 1px;
}
for event[event-index] in day.events : Rectangle {
background: Palette.card-background;
border-radius: 4px;

View file

@ -101,6 +101,7 @@ export component EventGroup {
padding-bottom: 8px;
TaskLine {
title: task.title;
checked: task.checked;
delete => {
root.delete-task(task.id)
}

View file

@ -6,6 +6,7 @@
#include "Utils.h"
#include <cctype>
#include <chrono>
#include <format>
#include <string>
@ -19,6 +20,12 @@ void bindSlintUtils(const ui::Utils &utils)
};
return std::format("{:%B %d}", chronoDate);
});
auto currentDate = MiraiDateToSlintDate(mirai::Date(std::chrono::system_clock::now()));
utils.set_current_date(currentDate);
auto currentTime = MiraiTimeToSlintTime(mirai::Time(std::chrono::system_clock::now()));
utils.set_current_time(currentTime);
}
std::string formatZeroPadding(const int number)
@ -81,5 +88,5 @@ ui::Time MiraiTimeToSlintTime(const mirai::Time &time)
mirai::Time SlintTimeToMiraiTime(const ui::Time &time)
{
return {.hour = time.hour, .minute = time.minute};
return mirai::Time{time.hour, time.minute};
}

View file

@ -16,4 +16,7 @@ export global Utils {
}
pure callback format-date(Date) -> string;
in property <Date> current-date;
in property <Time> current-time;
}

View file

@ -215,6 +215,8 @@ export component MainView inherits Rectangle {
Calendar {
init => { debug("cal len", AppWindowModels.calendar.length) }
days: AppWindowModels.calendar;
current-date: Utils.current-date;
current-time: Utils.current-time;
}
}