#include static Window *s_main_window; static TextLayer *s_text_layer; // ==================== BUTTON HANDLERS ==================== static void select_click_handler(ClickRecognizerRef recognizer, void *context) { text_layer_set_text(s_text_layer, "Hello!"); APP_LOG(APP_LOG_LEVEL_INFO, "SELECT pressed - Hello!"); } static void down_click_handler(ClickRecognizerRef recognizer, void *context) { APP_LOG(APP_LOG_LEVEL_INFO, "DOWN pressed - Quitting app..."); window_stack_pop_all(false); // Cleanly quit the app } // ==================== CLICK CONFIG ==================== static void click_config_provider(void *context) { window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler); } // ==================== WINDOW LOAD / UNLOAD ==================== static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_text_layer = text_layer_create(GRect(0, 20, bounds.size.w, bounds.size.h - 40)); text_layer_set_background_color(s_text_layer, GColorClear); text_layer_set_text_color(s_text_layer, GColorBlack); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); text_layer_set_text(s_text_layer, "Press SELECT\nfor Hello\n\nDOWN to quit"); layer_add_child(window_layer, text_layer_get_layer(s_text_layer)); } static void window_unload(Window *window) { text_layer_destroy(s_text_layer); } // ==================== APP INIT / DEINIT ==================== static void init(void) { s_main_window = window_create(); window_set_click_config_provider(s_main_window, click_config_provider); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = window_load, .unload = window_unload, }); window_stack_push(s_main_window, true); } static void deinit(void) { window_destroy(s_main_window); } int main(void) { init(); app_event_loop(); deinit(); }