summaryrefslogtreecommitdiff
path: root/lcolonq/src/c/lcolonq.c
blob: ad449051dd6d831e92cb61b50bf05f775973151d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <pebble.h>

static Window *WINDOW;
static TextLayer *TIME_TEXT_LAYER;

static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
    (void) units_changed;
    static char buf[16];
    // time_t temp = time(NULL);
    // struct tm *tick_time = localtime(&temp);
    strftime(buf, sizeof(buf), "%H:%M", tick_time);
    text_layer_set_text(TIME_TEXT_LAYER, buf);
}

static void main_window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);
    TIME_TEXT_LAYER = text_layer_create(GRect(0, 52, bounds.size.w, 50));
    text_layer_set_background_color(TIME_TEXT_LAYER, GColorClear);
    text_layer_set_text_color(TIME_TEXT_LAYER, GColorWhite);
    text_layer_set_font(TIME_TEXT_LAYER, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
    text_layer_set_text_alignment(TIME_TEXT_LAYER, GTextAlignmentCenter);
    layer_add_child(window_layer, text_layer_get_layer(TIME_TEXT_LAYER));
}
static void main_window_unload(Window *window) {
    text_layer_destroy(TIME_TEXT_LAYER);
}

static void init() {
    WINDOW = window_create();
    window_set_background_color(WINDOW, GColorBlack);
    window_set_window_handlers(WINDOW, (WindowHandlers) {
        .load = main_window_load,
        .unload = main_window_unload
    });
    window_stack_push(WINDOW, true);
    time_t temp = time(NULL);
    struct tm *tick_time = localtime(&temp);
    tick_handler(tick_time, MINUTE_UNIT);
    tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
}

static void deinit() {
    window_destroy(WINDOW);
}

int main(void) {
    init();
    app_event_loop();
    deinit();
}