-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleMenuLayerTutorial.c
96 lines (84 loc) · 2.43 KB
/
SimpleMenuLayerTutorial.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "pebble_os.h"
#include "pebble_app.h"
#include "pebble_fonts.h"
#define MY_UUID { 0xED, 0x8A, 0xEC, 0xFA, 0x23, 0xE0, 0x4F, 0x26, 0xB4, 0xD9, 0xE2, 0x0C, 0x0C, 0xB8, 0x6B, 0xD6 }
PBL_APP_INFO(MY_UUID,
"My App", "My Company",
1, 0, /* App version */
DEFAULT_MENU_ICON,
APP_INFO_STANDARD_APP);
static Window window;
static SimpleMenuLayer s_simple_menu_layer;
static SimpleMenuItem s_fruit_menu_items[4];
static SimpleMenuItem s_animal_menu_items[4];
static SimpleMenuSection s_menu_sections[2];
static char *s_fruit_names[4] = {"Apple", "Banana", "Grape", "Pear"};
static char *s_animal_names[4] = {"Cat", "Dog", "Horse", "Fish"};
void setup_window();
void window_load();
void setup_menu_items();
void setup_menu_sections();
void setup_menu_items()
{
for (int i = 0; i < (int)(sizeof(s_fruit_names) / sizeof(s_fruit_names[0])); i++)
{
s_fruit_menu_items[i] = (SimpleMenuItem){
.title = s_fruit_names[i],
};
}
for (int i = 0; i < (int)(sizeof(s_animal_names) / sizeof(s_animal_names[0])); i++)
{
s_animal_menu_items[i] = (SimpleMenuItem)
{
.title = s_animal_names[i],
};
}
}
void setup_menu_sections()
{
s_menu_sections[0] = (SimpleMenuSection)
{
.title = "Fruits",
.items = s_fruit_menu_items,
.num_items = sizeof(s_fruit_menu_items) / sizeof(s_fruit_menu_items[0])
};
s_menu_sections[1] = (SimpleMenuSection)
{
.title = "Animals",
.items = s_animal_menu_items,
.num_items = sizeof(s_animal_menu_items) / sizeof(s_animal_menu_items[0])
};
}
void setup_window()
{
window_init(&window, "Window Name");
window_set_window_handlers(&window, (WindowHandlers){
.load = window_load
});
}
void window_load(Window *window)
{
Layer *root_layer = window_get_root_layer(window);
simple_menu_layer_init(&s_simple_menu_layer,
layer_get_bounds(root_layer),
window,
s_menu_sections,
sizeof(s_menu_sections) / sizeof(s_menu_sections[0]),
NULL
);
layer_add_child(root_layer, (Layer *)&s_simple_menu_layer);
}
void handle_init(AppContextRef ctx)
{
setup_menu_items();
setup_menu_sections();
setup_window();
window_stack_push(&window, true /* Animated */);
}
void pbl_main(void *params)
{
PebbleAppHandlers handlers = {
.init_handler = &handle_init
};
app_event_loop(params, &handlers);
}