Show calendar icon when counting down to an appointment

Adds a small calendar icon (outline + header bar + two date squares) in the
bottom-right corner, to the left of the battery icon. It appears only when
the countdown bar is tracking a calendar event rather than the half-hour cycle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-23 21:02:29 +02:00
parent 8d509af3f8
commit 6c239163de
+30 -1
View File
@@ -5,8 +5,11 @@ static TextLayer *s_time_layer;
static TextLayer *s_date_layer;
static Layer *s_bar_layer;
static Layer *s_battery_layer;
static Layer *s_calendar_layer;
static GFont s_date_font;
static bool s_tracking_appt = false;
static const char * const MONTHS[] = {
"JAN","FEB","MAR","APR","MAY","JUN",
"JUL","AUG","SEP","OCT","NOV","DEC"
@@ -26,7 +29,8 @@ static void update_bar(void) {
int half_mins = mins_to_next_half();
int target = half_mins;
if (s_appt_mins >= 0 && s_appt_mins < half_mins) {
s_tracking_appt = (s_appt_mins >= 0 && s_appt_mins < half_mins);
if (s_tracking_appt) {
target = s_appt_mins;
}
@@ -35,6 +39,7 @@ static void update_bar(void) {
if (s_bar_fill < 0) s_bar_fill = 0;
layer_mark_dirty(s_bar_layer);
layer_mark_dirty(s_calendar_layer);
}
static void bar_draw(Layer *layer, GContext *ctx) {
@@ -81,6 +86,24 @@ static void battery_draw(Layer *layer, GContext *ctx) {
}
}
static void calendar_draw(Layer *layer, GContext *ctx) {
GRect bounds = layer_get_bounds(layer);
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
if (!s_tracking_appt) return;
// Outline
graphics_context_set_stroke_color(ctx, GColorWhite);
graphics_draw_rect(ctx, GRect(0, 0, 12, 12));
// Header bar
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_fill_rect(ctx, GRect(1, 1, 10, 3), 0, GCornerNone);
// Two date squares
graphics_fill_rect(ctx, GRect(2, 6, 3, 3), 0, GCornerNone);
graphics_fill_rect(ctx, GRect(7, 6, 3, 3), 0, GCornerNone);
}
static void inbox_received(DictionaryIterator *iter, void *context) {
Tuple *t = dict_find(iter, MESSAGE_KEY_APPOINTMENT_MINUTES);
if (t) {
@@ -149,6 +172,11 @@ static void main_window_load(Window *window) {
text_layer_set_text(s_date_layer, "1 JAN");
layer_add_child(root, text_layer_get_layer(s_date_layer));
// Calendar icon — bottom right, visible when counting down to an appointment
s_calendar_layer = layer_create(GRect(bounds.size.w - 42, bounds.size.h - 16, 12, 12));
layer_set_update_proc(s_calendar_layer, calendar_draw);
layer_add_child(root, s_calendar_layer);
// Battery icon — bottom right, only visible below 20%
s_battery_layer = layer_create(GRect(bounds.size.w - 26, bounds.size.h - 16, 23, 12));
layer_set_update_proc(s_battery_layer, battery_draw);
@@ -159,6 +187,7 @@ static void main_window_unload(Window *window) {
text_layer_destroy(s_time_layer);
text_layer_destroy(s_date_layer);
layer_destroy(s_bar_layer);
layer_destroy(s_calendar_layer);
layer_destroy(s_battery_layer);
fonts_unload_custom_font(s_date_font);
}