Refine calendar event data display, prevent overlapping and display
event's end time.
This commit is contained in:
+18
-12
@@ -1170,31 +1170,37 @@ display:
|
||||
break;
|
||||
}
|
||||
|
||||
const int group_y = agenda_y;
|
||||
int event_y = group_y;
|
||||
const int day_number = day["day"] | 0;
|
||||
const char *weekday = day["weekday"] | "";
|
||||
const bool is_today = (day["today"] | 0) == 1;
|
||||
it.printf(30, agenda_y, id(sub_sensor_font), TextAlign::TOP_CENTER, "%d", day_number);
|
||||
it.printf(30, agenda_y + 28, id(footer_font), TextAlign::TOP_CENTER, "%s", weekday);
|
||||
it.print(68, agenda_y + 2, id(footer_font), TextAlign::TOP_LEFT, is_today ? "HEUTE" : "");
|
||||
it.line(58, agenda_y, 58, agenda_y + 32 + events.size() * 35);
|
||||
agenda_y += 36;
|
||||
it.printf(30, group_y, id(sub_sensor_font), TextAlign::TOP_CENTER, "%d", day_number);
|
||||
it.printf(30, group_y + 28, id(footer_font), TextAlign::TOP_CENTER, "%s", weekday);
|
||||
|
||||
for (JsonVariant event_variant : events) {
|
||||
if (agenda_y + 33 > 345) {
|
||||
if (event_y + 33 > 345) {
|
||||
has_hidden_events = true;
|
||||
break;
|
||||
}
|
||||
JsonObject event = event_variant.as<JsonObject>();
|
||||
const char *title = event["title"] | "Ohne Titel";
|
||||
const char *time = event["time"] | "";
|
||||
const char *end_time = event["end"] | "";
|
||||
const char *meta = event["meta"] | "";
|
||||
it.printf(72, agenda_y, id(sensor_unit), TextAlign::TOP_LEFT, "%s", title);
|
||||
it.printf(350, agenda_y, id(sensor_unit), TextAlign::TOP_RIGHT, "%s", time);
|
||||
it.printf(72, agenda_y + 20, id(footer_font), TextAlign::TOP_LEFT, "%s", meta);
|
||||
agenda_y += 35;
|
||||
it.printf(72, event_y, id(sensor_unit), TextAlign::TOP_LEFT, "%s", title);
|
||||
it.printf(350, event_y, id(sensor_unit), TextAlign::TOP_RIGHT, "%s", time);
|
||||
it.printf(72, event_y + 20, id(footer_font), TextAlign::TOP_LEFT, "%s", meta);
|
||||
if (end_time[0] != '\0') {
|
||||
it.printf(350, event_y + 20, id(footer_font), TextAlign::TOP_RIGHT, "%s", end_time);
|
||||
}
|
||||
event_y += 35;
|
||||
has_events = true;
|
||||
}
|
||||
agenda_y += 5;
|
||||
|
||||
int group_bottom = event_y;
|
||||
if (group_bottom < group_y + 36) group_bottom = group_y + 36;
|
||||
it.line(58, group_y, 58, group_bottom);
|
||||
agenda_y = group_bottom + 5;
|
||||
if (has_hidden_events) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ CALENDAR_NAMES = {
|
||||
}
|
||||
DAY_NAMES = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
|
||||
MAX_ENTRIES = 8
|
||||
MAX_TITLE_LENGTH = 28
|
||||
MAX_META_LENGTH = 32
|
||||
# Reserve the right side of each row for start and end times.
|
||||
MAX_TITLE_LENGTH = 19
|
||||
MAX_META_LENGTH = 28
|
||||
|
||||
|
||||
def shorten(value, maximum):
|
||||
@@ -19,7 +20,9 @@ def shorten(value, maximum):
|
||||
def compact_event(event, calendar_name):
|
||||
start = event.get("start", "")
|
||||
all_day = "T" not in start
|
||||
end = event.get("end", "")
|
||||
time = "ganztägig" if all_day else start[11:16]
|
||||
end_time = "" if all_day or "T" not in end else end[11:16]
|
||||
|
||||
location = (event.get("location") or "").split("\n")[0].strip()
|
||||
meta = calendar_name
|
||||
@@ -29,6 +32,7 @@ def compact_event(event, calendar_name):
|
||||
return {
|
||||
"title": shorten(event.get("summary", "Ohne Titel"), MAX_TITLE_LENGTH),
|
||||
"time": time,
|
||||
"end": end_time,
|
||||
"meta": shorten(meta, MAX_META_LENGTH),
|
||||
"all_day": int(all_day),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user