Begin adding support for Window creation

This commit is contained in:
= 2020-05-11 06:15:24 +01:00
parent 60d6022d46
commit 4f6aedc4fa
2 changed files with 90 additions and 35 deletions

View File

@ -128,6 +128,7 @@ void code_window_push() {
.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);
} }
@ -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,

View File

@ -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