summaryrefslogtreecommitdiff
path: root/watchapp/src/mainmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'watchapp/src/mainmenu.c')
-rw-r--r--watchapp/src/mainmenu.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/watchapp/src/mainmenu.c b/watchapp/src/mainmenu.c
new file mode 100644
index 0000000..8a2a93b
--- /dev/null
+++ b/watchapp/src/mainmenu.c
@@ -0,0 +1,64 @@
+#include <pebble.h>
+
+static Window *window;
+
+static SimpleMenuLayer *mainmenu_layer;
+
+static SimpleMenuSection menu_sections[1];
+
+static SimpleMenuItem first_menu_items[1];
+
+static void handle_exit(int index, void *context)
+{
+ /* Pop the menu */
+ window_stack_pop(true);
+ /* And pop the main window, causing app to exit */
+ window_stack_pop(true);
+}
+
+static void window_load(Window *window)
+{
+ first_menu_items[0] = (SimpleMenuItem){
+ .title = "Exit App",
+ .callback = handle_exit,
+ };
+
+ menu_sections[0] = (SimpleMenuSection){
+ .num_items = 1,
+ .items = first_menu_items,
+ };
+
+ Layer *window_layer = window_get_root_layer(window);
+ GRect bounds = layer_get_frame(window_layer);
+
+ mainmenu_layer = simple_menu_layer_create(bounds, window, menu_sections, 1, NULL);
+
+ layer_add_child(window_layer, simple_menu_layer_get_layer(mainmenu_layer));
+}
+
+static void window_unload(Window *window)
+{
+ simple_menu_layer_destroy(mainmenu_layer);
+}
+
+void create_menu(void)
+{
+ window = window_create();
+
+ // Setup the window handlers
+ window_set_window_handlers(window, (WindowHandlers) {
+ .load = window_load,
+ .unload = window_unload,
+ });
+}
+
+void push_menu(void)
+{
+ window_stack_push(window, true /* Animated */);
+}
+
+void destroy_menu(void)
+{
+ window_destroy(window);
+}
+