-
-
Save C-D-Lewis/6d0e361ba83c4b6c0008 to your computer and use it in GitHub Desktop.
Simple two Windows app for Pebble.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pebble.h> | |
static Window *window_1, *window_2; | |
static TextLayer *text_layer_1, *text_layer_2; | |
/********************************* Window 2 stuff ***********************************/ | |
static void window_2_load(Window *window) { | |
text_layer_2 = text_layer_create(GRect(0, 0, 144, 168)); | |
text_layer_set_text(text_layer_2, "Window 2. \nBACK for Window 1."); | |
text_layer_set_text_alignment(text_layer_2, GTextAlignmentLeft); | |
text_layer_set_font(text_layer_2, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); | |
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer_2)); | |
} | |
static void window_2_unload(Window *window) { | |
text_layer_destroy(text_layer_2); | |
//Careful with this | |
window_destroy(window_2); | |
} | |
/********************************* Window 1 stuff ***********************************/ | |
static void select_click_handler(ClickRecognizerRef recognizer, void *context) { | |
//Load window 2 | |
window_2 = window_create(); | |
window_set_window_handlers(window_2, (WindowHandlers) { | |
.load = window_2_load, | |
.unload = window_2_unload, | |
}); | |
window_stack_push(window_2, true); //That's all there is too it! | |
} | |
static void click_config_provider(void *context) { | |
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); | |
} | |
static void window_1_load(Window *window) { | |
text_layer_1 = text_layer_create(GRect(0, 0, 144, 168)); | |
text_layer_set_text(text_layer_1, "Window 1. \nSELECT for Window 2."); | |
text_layer_set_text_alignment(text_layer_1, GTextAlignmentLeft); | |
text_layer_set_font(text_layer_1, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); | |
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer_1)); | |
} | |
static void window_1_unload(Window *window) { | |
text_layer_destroy(text_layer_1); | |
window_destroy(window_1); | |
} | |
/******************************** Main app stuff ************************************/ | |
static void init(void) { | |
//Start with window 1 | |
window_1 = window_create(); | |
window_set_click_config_provider(window_1, click_config_provider); | |
window_set_window_handlers(window_1, (WindowHandlers) { | |
.load = window_1_load, | |
.unload = window_1_unload, | |
}); | |
window_stack_push(window_1, true); | |
} | |
static void deinit(void) { | |
} | |
int main(void) { | |
init(); | |
app_event_loop(); | |
deinit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment