mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-02 09:40:15 +00:00
demo: handle menu navigation
This commit is contained in:
parent
2dde1d4af7
commit
92cb0b9abf
@ -156,6 +156,9 @@ int hud_completion_notify(const demoresult* result);
|
||||
const demoresult* demoresult_lookup(int idx);
|
||||
/*----------------------------------HUD----------------------------------*/
|
||||
|
||||
// returns true if the input was handled by the menu/HUD
|
||||
bool menu_or_hud_key(const struct ncinput *ni);
|
||||
|
||||
static inline int
|
||||
pulser(struct notcurses* nc, struct ncplane* ncp __attribute__ ((unused)), void* curry){
|
||||
struct timespec* start = curry;
|
||||
|
@ -26,6 +26,9 @@ typedef struct elem {
|
||||
struct elem* next;
|
||||
} elem;
|
||||
|
||||
static bool menu_unrolled;
|
||||
static struct ncmenu* menu;
|
||||
|
||||
static struct elem* elems;
|
||||
static struct elem* running;
|
||||
// which line we're writing the next entry to. once this becomes -1, we stop decrementing
|
||||
@ -57,6 +60,44 @@ hud_grabbed_bg(struct ncplane* n){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// returns true if the input was handled by the menu/HUD
|
||||
bool menu_or_hud_key(const struct ncinput *ni){
|
||||
if(!menu){
|
||||
return false;
|
||||
}
|
||||
if((ni->id == 'o' || ni->id == 'O') && ni->alt && !ni->ctrl){
|
||||
if(ncmenu_unroll(menu, 0) == 0){
|
||||
menu_unrolled = true;
|
||||
}
|
||||
return true;
|
||||
}else if(ni->id == NCKEY_UP){
|
||||
if(!menu_unrolled){
|
||||
return false;
|
||||
}
|
||||
ncmenu_previtem(menu);
|
||||
return true;
|
||||
}else if(ni->id == NCKEY_DOWN){
|
||||
if(!menu_unrolled){
|
||||
return false;
|
||||
}
|
||||
ncmenu_nextitem(menu);
|
||||
return true;
|
||||
}else if(ni->id == NCKEY_LEFT){
|
||||
if(!menu_unrolled){
|
||||
return false;
|
||||
}
|
||||
ncmenu_prevsection(menu);
|
||||
return true;
|
||||
}else if(ni->id == NCKEY_RIGHT){
|
||||
if(!menu_unrolled){
|
||||
return false;
|
||||
}
|
||||
ncmenu_nextsection(menu);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ncmenu* menu_create(struct notcurses* nc){
|
||||
struct ncmenu_item demo_items[] = {
|
||||
{ .desc = "Toggle HUD", .shortcut = { .id = 'H', .ctrl = true, }, },
|
||||
@ -89,7 +130,8 @@ struct ncmenu* menu_create(struct notcurses* nc){
|
||||
.headerchannels = headerchannels,
|
||||
.sectionchannels = sectionchannels,
|
||||
};
|
||||
return ncmenu_create(nc, &mopts);
|
||||
menu = ncmenu_create(nc, &mopts);
|
||||
return menu;
|
||||
}
|
||||
|
||||
struct ncplane* hud_create(struct notcurses* nc){
|
||||
|
@ -95,13 +95,7 @@ ultramegaok_demo(void* vnc){
|
||||
handle_mouse(&ni);
|
||||
}else{
|
||||
// if this was about the menu or HUD, pass to them, and continue
|
||||
if(ni.id == NCKEY_UP){
|
||||
continue;
|
||||
}else if(ni.id == NCKEY_DOWN){
|
||||
continue;
|
||||
}else if(ni.id == NCKEY_LEFT){
|
||||
continue;
|
||||
}else if(ni.id == NCKEY_RIGHT){
|
||||
if(menu_or_hud_key(&ni)){
|
||||
continue;
|
||||
}
|
||||
if(ni.id == 'q'){
|
||||
|
@ -461,14 +461,14 @@ int witherworm_demo(struct notcurses* nc){
|
||||
int y, x, maxy, maxx;
|
||||
ncplane_dim_yx(n, &maxy, &maxx);
|
||||
int rgb = start;
|
||||
if(ncplane_cursor_move_yx(n, 0, 0)){
|
||||
return -1;
|
||||
}
|
||||
int bytes_out = 0;
|
||||
int egcs_out = 0;
|
||||
int cols_out = 0;
|
||||
y = 0;
|
||||
y = 1;
|
||||
x = 0;
|
||||
if(ncplane_cursor_move_yx(n, y, x)){
|
||||
return -1;
|
||||
}
|
||||
ncplane_set_bg_rgb(n, 20, 20, 20);
|
||||
do{ // we fill up the screen, however large, bouncing around our strtable
|
||||
s = strs + random() % ((sizeof(strs) / sizeof(*strs)) - 1);
|
||||
|
Loading…
Reference in New Issue
Block a user