From ee814c4afee84e987fcbaf02687cdb4c2cfd8039 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Sat, 11 Jul 2026 22:26:08 +0200 Subject: [PATCH] Refine calendar event data display, prevent overlapping and display event's end time. --- esphome/epaperframe.yaml | 30 +++++++++++++++----------- python_scripts/epaper_calendar_data.py | 8 +++++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/esphome/epaperframe.yaml b/esphome/epaperframe.yaml index c35a688..8134bd0 100644 --- a/esphome/epaperframe.yaml +++ b/esphome/epaperframe.yaml @@ -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(); 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; } } diff --git a/python_scripts/epaper_calendar_data.py b/python_scripts/epaper_calendar_data.py index 222e670..b5e38f5 100644 --- a/python_scripts/epaper_calendar_data.py +++ b/python_scripts/epaper_calendar_data.py @@ -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), }