Begin adding support for Window creation
This commit is contained in:
parent
60d6022d46
commit
4f6aedc4fa
118
src/calc.c
118
src/calc.c
|
@ -107,28 +107,29 @@ static uint16_t get_num_rows_callback(MenuLayer *menu_layer,
|
||||||
|
|
||||||
static void draw_row_callback(GContext *ctx, const Layer *cell_layer,
|
static void draw_row_callback(GContext *ctx, const Layer *cell_layer,
|
||||||
MenuIndex *cell_index, void *context) {
|
MenuIndex *cell_index, void *context) {
|
||||||
static char s_buff[16];
|
static char s_buff[16];
|
||||||
snprintf(s_buff, sizeof(s_buff), "Script %d", 1 + (int)cell_index->row);
|
snprintf(s_buff, sizeof(s_buff), "Script %d", 1 + (int)cell_index->row);
|
||||||
|
|
||||||
// Draw this row's index
|
// Draw this row's index
|
||||||
menu_cell_basic_draw(ctx, cell_layer, s_buff, NULL, NULL);
|
menu_cell_basic_draw(ctx, cell_layer, s_buff, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int16_t get_cell_height_callback(struct MenuLayer *menu_layer,
|
static int16_t get_cell_height_callback(struct MenuLayer *menu_layer,
|
||||||
MenuIndex *cell_index, void *context) {
|
MenuIndex *cell_index, void *context) {
|
||||||
const int16_t cell_height = 44;
|
const int16_t cell_height = 44;
|
||||||
return cell_height;
|
return cell_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void code_window_push() {
|
void code_window_push() {
|
||||||
if(!s_code_window) {
|
if(!s_code_window) {
|
||||||
s_code_window = window_create();
|
s_code_window = window_create();
|
||||||
WindowHandlers wh = {
|
WindowHandlers wh = {
|
||||||
.load = code_window_load,
|
.load = code_window_load,
|
||||||
.unload = code_window_unload };
|
.unload = code_window_unload };
|
||||||
window_set_window_handlers(s_code_window, wh);
|
window_set_window_handlers(s_code_window, wh);
|
||||||
}
|
}
|
||||||
window_stack_push(s_code_window, true);
|
|
||||||
|
window_stack_push(s_code_window, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void select_callback(struct MenuLayer *menu_layer,
|
static void select_callback(struct MenuLayer *menu_layer,
|
||||||
|
@ -140,22 +141,22 @@ static void select_callback(struct MenuLayer *menu_layer,
|
||||||
|
|
||||||
static void menu_load(Window *window)
|
static void menu_load(Window *window)
|
||||||
{
|
{
|
||||||
Layer *window_layer = window_get_root_layer(window);
|
Layer *window_layer = window_get_root_layer(window);
|
||||||
GRect bounds = layer_get_bounds(window_layer);
|
GRect bounds = layer_get_bounds(window_layer);
|
||||||
|
|
||||||
s_menu_layer = menu_layer_create(bounds);
|
s_menu_layer = menu_layer_create(bounds);
|
||||||
menu_layer_set_click_config_onto_window(s_menu_layer, window);
|
menu_layer_set_click_config_onto_window(s_menu_layer, window);
|
||||||
#if defined(PBL_COLOR)
|
#if defined(PBL_COLOR)
|
||||||
menu_layer_set_normal_colors(s_menu_layer, GColorBlack, GColorWhite);
|
menu_layer_set_normal_colors(s_menu_layer, GColorBlack, GColorWhite);
|
||||||
menu_layer_set_highlight_colors(s_menu_layer, GColorDukeBlue, GColorWhite);
|
menu_layer_set_highlight_colors(s_menu_layer, GColorDukeBlue, GColorWhite);
|
||||||
#endif
|
#endif
|
||||||
menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks) {
|
menu_layer_set_callbacks(s_menu_layer, NULL, (MenuLayerCallbacks) {
|
||||||
.get_num_rows = get_num_rows_callback,
|
.get_num_rows = get_num_rows_callback,
|
||||||
.draw_row = draw_row_callback,
|
.draw_row = draw_row_callback,
|
||||||
.get_cell_height = get_cell_height_callback,
|
.get_cell_height = get_cell_height_callback,
|
||||||
.select_click = select_callback,
|
.select_click = select_callback,
|
||||||
});
|
});
|
||||||
layer_add_child(window_layer, menu_layer_get_layer(s_menu_layer));
|
layer_add_child(window_layer, menu_layer_get_layer(s_menu_layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void menu_unload(Window *window)
|
static void menu_unload(Window *window)
|
||||||
|
@ -190,12 +191,6 @@ void code_window_load(Window *window)
|
||||||
window_stack_push(s_code_window, true);
|
window_stack_push(s_code_window, true);
|
||||||
|
|
||||||
// If possible, load the previous code text
|
// If possible, load the previous code text
|
||||||
// Object obj = parseEval("(def ad (fn (a) (* 3 a)))", &env);
|
|
||||||
// Object obj2 = parseEval("(map ad (1 50 99))", &env);
|
|
||||||
// printObj(&obj);
|
|
||||||
// printObj(&obj2);
|
|
||||||
// cleanObject(&obj);
|
|
||||||
// cleanObject(&obj2);
|
|
||||||
if(persist_exists(current_code)) {
|
if(persist_exists(current_code)) {
|
||||||
persist_read_string(current_code, mytext, SMAX_LENGTH);
|
persist_read_string(current_code, mytext, SMAX_LENGTH);
|
||||||
updateText();
|
updateText();
|
||||||
|
@ -214,8 +209,63 @@ void code_window_unload(Window *window)
|
||||||
s_code_window = NULL;
|
s_code_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void custom_load(Window *window)
|
||||||
|
{
|
||||||
|
Layer *window_layer = window_get_root_layer(window);
|
||||||
|
GRect bounds = layer_get_bounds(window_layer);
|
||||||
|
|
||||||
|
// Register click config provider
|
||||||
|
window_set_click_config_provider(s_custom_window, click_config_provider);
|
||||||
|
|
||||||
|
// Header text layer setup
|
||||||
|
s_heading_text_layer = text_layer_create(bounds);
|
||||||
|
text_layer_set_text(s_heading_text_layer, header);
|
||||||
|
text_layer_set_font(s_heading_text_layer,
|
||||||
|
fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK));
|
||||||
|
layer_add_child(window_get_root_layer(s_custom_window),
|
||||||
|
text_layer_get_layer(s_heading_text_layer));
|
||||||
|
|
||||||
|
// Push the window, setting the window animation to 'true'
|
||||||
|
window_stack_push(s_custom_window, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void custom_unload(Window *window)
|
||||||
|
{
|
||||||
|
text_layer_destroy(s_heading_text_layer);
|
||||||
|
//text_layer_destroy(s_input_text_layer);
|
||||||
|
|
||||||
|
window_destroy(window);
|
||||||
|
s_custom_window = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object add_window(Object obj1, Object obj2, struct Environment *env)
|
||||||
|
{
|
||||||
|
if(obj1.type == TYPE_STRING) {
|
||||||
|
strcpy(header, obj1.string);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!s_custom_window) {
|
||||||
|
s_custom_window = window_create();
|
||||||
|
WindowHandlers wh = {
|
||||||
|
.load = custom_load,
|
||||||
|
.unload = custom_unload };
|
||||||
|
window_set_window_handlers(s_custom_window, wh);
|
||||||
|
}
|
||||||
|
|
||||||
|
window_stack_push(s_custom_window, true);
|
||||||
|
|
||||||
|
return numberObject(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct Environment pebbleEnv() {
|
||||||
|
struct Environment e = defaultEnv();
|
||||||
|
// Needs two args
|
||||||
|
addFunc("window", &add_window, &e);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
static void init(void) {
|
static void init(void) {
|
||||||
env = defaultEnv();
|
env = pebbleEnv();
|
||||||
s_menu_window = window_create();
|
s_menu_window = window_create();
|
||||||
window_set_window_handlers(s_menu_window, (WindowHandlers) {
|
window_set_window_handlers(s_menu_window, (WindowHandlers) {
|
||||||
.load = menu_load,
|
.load = menu_load,
|
||||||
|
|
|
@ -13,6 +13,11 @@
|
||||||
Window *s_menu_window;
|
Window *s_menu_window;
|
||||||
Window *s_code_window;
|
Window *s_code_window;
|
||||||
|
|
||||||
|
// Custom layers
|
||||||
|
Window *s_custom_window;
|
||||||
|
TextLayer *s_heading_text_layer;
|
||||||
|
char header[30] = "";
|
||||||
|
|
||||||
// Code layers
|
// Code layers
|
||||||
TextLayer *s_input_text_layer;
|
TextLayer *s_input_text_layer;
|
||||||
TextLayer *s_result_text_layer;
|
TextLayer *s_result_text_layer;
|
||||||
|
@ -43,7 +48,7 @@ char *tokens[] = {
|
||||||
"7","8","9", "0",
|
"7","8","9", "0",
|
||||||
"a", "b", "c", "d", "e",
|
"a", "b", "c", "d", "e",
|
||||||
"= ", "< ", "> ",
|
"= ", "< ", "> ",
|
||||||
"spent",
|
"spent", "window",
|
||||||
"\"",
|
"\"",
|
||||||
"map", "fn", "def", "if", "\n",
|
"map", "fn", "def", "if", "\n",
|
||||||
END_PHRASE
|
END_PHRASE
|
||||||
|
|
Loading…
Reference in New Issue