this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #2120 from sthilaid/menu-item-hotkey-cleaned

Added hotkey option to menu items. Used in Yes/No dialog.

authored by

Vadim Grigoruk and committed by
GitHub
b12c1716 39d96f70

+18 -4
+10 -1
src/studio/screens/menu.c
··· 258 258 } 259 259 260 260 if(tic_api_btnp(menu->tic, A, -1, -1) 261 - || tic_api_keyp(tic, tic_key_return, Hold, Period)) 261 + || tic_api_keyp(tic, tic_key_return, Hold, Period)) 262 262 { 263 263 if(option) 264 264 { ··· 285 285 286 286 tic_rect rect = {x + (TIC80_WIDTH - width) / 2 + menu->anim.offset, 287 287 y + TextMargin + ItemHeight * (i - menu->pos) - menu->anim.pos, it->width, TIC_FONT_HEIGHT}; 288 + 289 + if (it->hotkey != tic_key_unknown && tic_api_keyp(tic, it->hotkey, Hold, Period)) 290 + { 291 + // hotkeys not supported on options for simplicity 292 + if(it->option == NULL && it->handler) 293 + onMenuItem(menu, it); 294 + 295 + menu->pos = it - menu->items; // set pos so that close will call this handler 296 + } 288 297 289 298 bool down = false; 290 299 if(animIdle(menu) && checkMousePos(menu->studio, &rect) && it->handler)
+2
src/studio/screens/menu.h
··· 23 23 #pragma once 24 24 25 25 #include "tic80_types.h" 26 + #include "tic.h" 26 27 27 28 typedef struct Menu Menu; 28 29 struct tic_mem; ··· 55 56 const char* help; 56 57 bool back; 57 58 s32 width; 59 + tic_keycode hotkey; 58 60 } MenuItem; 59 61 60 62 void studio_menu_init(Menu* menu, const MenuItem* items, s32 rows, s32 pos, s32 backPos, MenuItemHandler handler, void* data);
+6 -3
src/studio/studio.c
··· 1372 1372 studio->menuMode = studio->mode; 1373 1373 studio->mode = TIC_MENU_MODE; 1374 1374 1375 - static const MenuItem Answers[] = 1375 + static MenuItem Answers[] = 1376 1376 { 1377 1377 {"", NULL}, 1378 - {"NO", confirmNo}, 1379 - {"YES", confirmYes}, 1378 + {"(N)O", confirmNo}, 1379 + {"(Y)ES", confirmYes}, 1380 1380 }; 1381 + 1382 + Answers[1].hotkey = tic_key_n; 1383 + Answers[2].hotkey = tic_key_y; 1381 1384 1382 1385 s32 count = rows + COUNT_OF(Answers); 1383 1386 MenuItem* items = malloc(sizeof items[0] * count);