|
| 1 | +#include <pebble.h> |
| 2 | + |
| 3 | +static Window *window; |
| 4 | +static TextLayer *text_layer; |
| 5 | + |
| 6 | +static void select_click_handler(ClickRecognizerRef recognizer, void *context) { |
| 7 | + text_layer_set_text(text_layer, "Select"); |
| 8 | +} |
| 9 | + |
| 10 | +static void up_click_handler(ClickRecognizerRef recognizer, void *context) { |
| 11 | + text_layer_set_text(text_layer, "Up"); |
| 12 | +} |
| 13 | + |
| 14 | +static void down_click_handler(ClickRecognizerRef recognizer, void *context) { |
| 15 | + text_layer_set_text(text_layer, "Down"); |
| 16 | +} |
| 17 | + |
| 18 | +static void click_config_provider(void *context) { |
| 19 | + window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); |
| 20 | + window_single_click_subscribe(BUTTON_ID_UP, up_click_handler); |
| 21 | + window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler); |
| 22 | +} |
| 23 | + |
| 24 | +static void window_load(Window *window) { |
| 25 | + Layer *window_layer = window_get_root_layer(window); |
| 26 | + GRect bounds = layer_get_bounds(window_layer); |
| 27 | + |
| 28 | + text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } }); |
| 29 | + text_layer_set_text(text_layer, "Press a button"); |
| 30 | + text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); |
| 31 | + layer_add_child(window_layer, text_layer_get_layer(text_layer)); |
| 32 | +} |
| 33 | + |
| 34 | +static void window_unload(Window *window) { |
| 35 | + text_layer_destroy(text_layer); |
| 36 | +} |
| 37 | + |
| 38 | +static void init(void) { |
| 39 | + window = window_create(); |
| 40 | + window_set_click_config_provider(window, click_config_provider); |
| 41 | + window_set_window_handlers(window, (WindowHandlers) { |
| 42 | + .load = window_load, |
| 43 | + .unload = window_unload, |
| 44 | + }); |
| 45 | + const bool animated = true; |
| 46 | + window_stack_push(window, animated); |
| 47 | +} |
| 48 | + |
| 49 | +static void deinit(void) { |
| 50 | + window_destroy(window); |
| 51 | +} |
| 52 | + |
| 53 | +int main(void) { |
| 54 | + init(); |
| 55 | + |
| 56 | + APP_LOG(APP_LOG_LEVEL_DEBUG, "Done initializing, pushed window: %p", window); |
| 57 | + |
| 58 | + app_event_loop(); |
| 59 | + deinit(); |
| 60 | +} |
0 commit comments