mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Add current time indicator of the current day on the Calendar
This commit is contained in:
parent
ab2200ecc1
commit
e2cd994026
9 changed files with 54 additions and 8 deletions
|
@ -48,6 +48,9 @@ struct Date {
|
|||
|
||||
struct Time {
|
||||
|
||||
explicit Time(int hour, int minute);
|
||||
explicit Time(std::chrono::time_point<std::chrono::system_clock> tp);
|
||||
|
||||
bool operator==(const Time &other) const;
|
||||
bool operator<(const Time &other) const;
|
||||
bool operator>(const Time &other) const;
|
||||
|
|
20
external/mirai-core/src/DateTime.cpp
vendored
20
external/mirai-core/src/DateTime.cpp
vendored
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "DateTime.h"
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <ranges>
|
||||
#include <string>
|
||||
|
@ -54,10 +55,6 @@ Date::Date(std::chrono::year_month_day chronoDate)
|
|||
day = static_cast<unsigned>(chronoDate.day());
|
||||
}
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
|
||||
bool Date::operator==(const Date &other) const
|
||||
{
|
||||
return other.year == year && other.month == month && other.day == day;
|
||||
|
@ -92,6 +89,21 @@ bool Date::operator<=(const Date &other) const
|
|||
return (*this < other) || (*this == other);
|
||||
}
|
||||
|
||||
Time::Time(int hour, int minute) : hour(hour), minute(minute)
|
||||
{
|
||||
}
|
||||
|
||||
Time::Time(std::chrono::time_point<std::chrono::system_clock> tp)
|
||||
{
|
||||
auto localTp = std::chrono::zoned_time{std::chrono::current_zone(), tp}.get_local_time();
|
||||
auto chronoDate = std::chrono::floor<std::chrono::days>(localTp);
|
||||
auto chronoTime =
|
||||
std::chrono::hh_mm_ss{std::chrono::duration_cast<std::chrono::minutes>(localTp - chronoDate)
|
||||
};
|
||||
hour = static_cast<int>(chronoTime.hours().count());
|
||||
minute = static_cast<int>(chronoTime.minutes().count());
|
||||
}
|
||||
|
||||
bool Time::operator==(const Time &other) const
|
||||
{
|
||||
return other.hour == hour && other.minute == minute;
|
||||
|
|
|
@ -61,9 +61,10 @@ Time stringToTime(const std::string &str)
|
|||
if (str[2] != 'h') {
|
||||
throw std::runtime_error("Malformated time range");
|
||||
}
|
||||
Time time{};
|
||||
std::from_chars(str.data(), str.data() + 2, time.hour);
|
||||
std::from_chars(str.data() + 3, str.data() + 5, time.minute);
|
||||
int hour, minute;
|
||||
std::from_chars(str.data(), str.data() + 2, hour);
|
||||
std::from_chars(str.data() + 3, str.data() + 5, minute);
|
||||
Time time{hour, minute};
|
||||
|
||||
return time;
|
||||
}
|
||||
|
|
8
external/mirai-core/src/View.cpp
vendored
8
external/mirai-core/src/View.cpp
vendored
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "View.h"
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <ranges>
|
||||
|
@ -104,6 +105,13 @@ void View::update()
|
|||
auto tasks = source->getUnscheduledTasks();
|
||||
unscheduledTasks_.insert(unscheduledTasks_.end(), tasks.begin(), tasks.end());
|
||||
}
|
||||
|
||||
for (auto &date : dates) {
|
||||
auto &events = date.second.events;
|
||||
std::sort(events.begin(), events.end(), [](const Event &a, const Event &b) {
|
||||
return a.startsAt() < b.startsAt();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void View::removeSources()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -101,6 +101,7 @@ export component EventGroup {
|
|||
padding-bottom: 8px;
|
||||
TaskLine {
|
||||
title: task.title;
|
||||
checked: task.checked;
|
||||
delete => {
|
||||
root.delete-task(task.id)
|
||||
}
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
|
|
|
@ -16,4 +16,7 @@ export global Utils {
|
|||
}
|
||||
|
||||
pure callback format-date(Date) -> string;
|
||||
|
||||
in property <Date> current-date;
|
||||
in property <Time> current-time;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue