Allow making selections in menus

This commit is contained in:
2026-08-06 21:53:25 -04:00
parent 30afb37047
commit cc0af89820
2 changed files with 71 additions and 33 deletions
+1 -1
View File
@@ -68,7 +68,7 @@
] ]
}, },
{ {
"characterRegex": "[type:θ=]", "characterRegex": "[type:θ=EquilarIsocSn¯¹0123456789]",
"file": "mansalva_regular.ttf", "file": "mansalva_regular.ttf",
"name": "FONT_MANSALVA_REGULAR_22", "name": "FONT_MANSALVA_REGULAR_22",
"type": "font" "type": "font"
+69 -31
View File
@@ -29,6 +29,10 @@ static Layer *s_drop_bg_type_layer;
static Layer *s_drop_bg_function_layer; static Layer *s_drop_bg_function_layer;
static Layer *s_drop_bg_over_layer; static Layer *s_drop_bg_over_layer;
static Layer *s_drop_bg_under_layer; static Layer *s_drop_bg_under_layer;
static TextLayer *s_drop_txt_type_layer;
static TextLayer *s_drop_txt_function_layer;
static TextLayer *s_drop_txt_over_layer;
static TextLayer *s_drop_txt_under_layer;
static Layer *s_division_layer; static Layer *s_division_layer;
static Layer *s_alarm_highlight_layer; static Layer *s_alarm_highlight_layer;
static MenuLayer *s_drop_menu_layer; static MenuLayer *s_drop_menu_layer;
@@ -71,6 +75,12 @@ static const char *s_sin;
static const char *s_cos; static const char *s_cos;
static const char *s_tan; static const char *s_tan;
// alarm drop menu options
static const char *s_options_type[3] = {"equilateral", "isosceles", "scalene"};
static const char *s_options_function[3];
static char *s_options_over[3];
static char *s_options_under[3];
///////////////////////////////// /////////////////////////////////
static void glance_reload_callback(AppGlanceReloadSession *session, size_t limit, void *target) { static void glance_reload_callback(AppGlanceReloadSession *session, size_t limit, void *target) {
@@ -373,47 +383,34 @@ static uint16_t menu_get_num_rows(MenuLayer *menu_layer, uint16_t section_index,
static void menu_draw_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *context) { static void menu_draw_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cell_index, void *context) {
switch (s_highlight_pos) { switch (s_highlight_pos) {
case 0: case 0:
switch (cell_index->row) { menu_cell_basic_draw(ctx, cell_layer, s_options_type[cell_index->row], NULL, NULL);
case 0:
menu_cell_basic_draw(ctx, cell_layer, "Equilateral", NULL, NULL);
break; break;
case 1: case 1:
menu_cell_basic_draw(ctx, cell_layer, "Isosceles", NULL, NULL); menu_cell_basic_draw(ctx, cell_layer, s_options_function[cell_index->row], NULL, NULL);
break; break;
case 2: case 2:
menu_cell_basic_draw(ctx, cell_layer, "Scalene", NULL, NULL); menu_cell_basic_draw(ctx, cell_layer, s_options_over[cell_index->row], NULL, NULL);
}
break; break;
case 1:
switch (cell_index->row) {
case 0:
menu_cell_basic_draw(ctx, cell_layer, s_sin, NULL, NULL);
break;
case 1:
menu_cell_basic_draw(ctx, cell_layer, s_cos, NULL, NULL);
break;
case 2:
menu_cell_basic_draw(ctx, cell_layer, s_tan, NULL, NULL);
}
break;
case 2:
__attribute__((fallthrough));
case 3: case 3:
switch (cell_index->row) { menu_cell_basic_draw(ctx, cell_layer, s_options_under[cell_index->row], NULL, NULL);
case 0:
menu_cell_basic_draw(ctx, cell_layer, "1", NULL, NULL);
break;
case 1:
menu_cell_basic_draw(ctx, cell_layer, "2", NULL, NULL);
break;
case 2:
menu_cell_basic_draw(ctx, cell_layer, "3", NULL, NULL);
}
} }
} }
static void menu_select(MenuLayer *menu_layer, MenuIndex *cell_index, void *context) { static void menu_select(MenuLayer *menu_layer, MenuIndex *cell_index, void *context) {
// TODO switch (s_highlight_pos) {
case 0:
text_layer_set_text(s_drop_txt_type_layer, s_options_type[cell_index->row]);
break;
case 1:
text_layer_set_text(s_drop_txt_function_layer, s_options_function[cell_index->row]);
break;
case 2:
text_layer_set_text(s_drop_txt_over_layer, s_options_over[cell_index->row]);
break;
case 3:
text_layer_set_text(s_drop_txt_under_layer, s_options_under[cell_index->row]);
}
window_stack_remove(s_drop_window, true);
} }
// when the user presses select, call this to load a menu; // when the user presses select, call this to load a menu;
@@ -447,6 +444,17 @@ static void alarm_window_load() {
s_cos = s_cos_arr[rand() % 2]; s_cos = s_cos_arr[rand() % 2];
s_tan = s_tan_arr[rand() % 2]; s_tan = s_tan_arr[rand() % 2];
// set up menu options
s_options_function[0] = s_sin;
s_options_function[1] = s_cos;
s_options_function[2] = s_tan;
s_options_over[0] = "1"; // TODO
s_options_over[1] = "2"; // TODO
s_options_over[2] = "3"; // TODO
s_options_under[0] = "1"; // TODO
s_options_under[1] = "2"; // TODO
s_options_under[2] = "3"; // TODO
// drop window // drop window
s_drop_window = window_create(); // TODO destroy on window unload? s_drop_window = window_create(); // TODO destroy on window unload?
window_set_window_handlers( window_set_window_handlers(
@@ -493,6 +501,32 @@ static void alarm_window_load() {
layer_set_update_proc(s_drop_bg_under_layer, drop_layer_update_proc); layer_set_update_proc(s_drop_bg_under_layer, drop_layer_update_proc);
layer_add_child(window_layer, s_drop_bg_under_layer); layer_add_child(window_layer, s_drop_bg_under_layer);
// drop text (blank by default)
//// type
s_drop_txt_type_layer = text_layer_create(GRect(s_drop_type_grect.origin.x, s_drop_type_grect.origin.y - 3, s_drop_type_grect.size.w, s_drop_type_grect.size.h));
text_layer_set_background_color(s_drop_txt_type_layer, GColorClear);
text_layer_set_font(s_drop_txt_type_layer, s_font_mansalva_small);
text_layer_set_text_alignment(s_drop_txt_type_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_drop_txt_type_layer));
//// function
s_drop_txt_function_layer = text_layer_create(GRect(s_drop_function_grect.origin.x, s_drop_function_grect.origin.y - 3, s_drop_function_grect.size.w, s_drop_function_grect.size.h));
text_layer_set_background_color(s_drop_txt_function_layer, GColorClear);
text_layer_set_font(s_drop_txt_function_layer, s_font_mansalva_small);
text_layer_set_text_alignment(s_drop_txt_function_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_drop_txt_function_layer));
//// over
s_drop_txt_over_layer = text_layer_create(GRect(s_drop_over_grect.origin.x, s_drop_over_grect.origin.y - 3, s_drop_over_grect.size.w, s_drop_over_grect.size.h));
text_layer_set_background_color(s_drop_txt_over_layer, GColorClear);
text_layer_set_font(s_drop_txt_over_layer, s_font_mansalva_small);
text_layer_set_text_alignment(s_drop_txt_over_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_drop_txt_over_layer));
//// under
s_drop_txt_under_layer = text_layer_create(GRect(s_drop_under_grect.origin.x, s_drop_under_grect.origin.y - 3, s_drop_under_grect.size.w, s_drop_under_grect.size.h));
text_layer_set_background_color(s_drop_txt_under_layer, GColorClear);
text_layer_set_font(s_drop_txt_under_layer, s_font_mansalva_small);
text_layer_set_text_alignment(s_drop_txt_under_layer, GTextAlignmentCenter);
layer_add_child(window_layer, text_layer_get_layer(s_drop_txt_under_layer));
// parenthesis text // parenthesis text
s_font_mansalva_big = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MANSALVA_REGULAR_50)); s_font_mansalva_big = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MANSALVA_REGULAR_50));
s_parenthesis_txt_layer = text_layer_create(GRect(s_drop_function_grect.origin.x + s_drop_function_grect.size.w + 2, s_bottom_bar_grect.origin.y - PBL_IF_ROUND_ELSE(12, 5), 200, 60)); s_parenthesis_txt_layer = text_layer_create(GRect(s_drop_function_grect.origin.x + s_drop_function_grect.size.w + 2, s_bottom_bar_grect.origin.y - PBL_IF_ROUND_ELSE(12, 5), 200, 60));
@@ -520,6 +554,10 @@ static void alarm_window_unload() {
layer_destroy(s_alarm_highlight_layer); layer_destroy(s_alarm_highlight_layer);
layer_destroy(s_division_layer); layer_destroy(s_division_layer);
text_layer_destroy(s_parenthesis_txt_layer); text_layer_destroy(s_parenthesis_txt_layer);
text_layer_destroy(s_drop_txt_under_layer);
text_layer_destroy(s_drop_txt_over_layer);
text_layer_destroy(s_drop_txt_function_layer);
text_layer_destroy(s_drop_txt_type_layer);
layer_destroy(s_drop_bg_under_layer); layer_destroy(s_drop_bg_under_layer);
layer_destroy(s_drop_bg_over_layer); layer_destroy(s_drop_bg_over_layer);
layer_destroy(s_drop_bg_function_layer); layer_destroy(s_drop_bg_function_layer);