Use mode-style for selected items, like choose modes. GitHub issue 2166.

This commit is contained in:
nicm
2020-04-15 16:11:23 +00:00
parent c7883d5c87
commit 1e72f5ea43
3 changed files with 20 additions and 14 deletions

View File

@ -409,21 +409,23 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
/* Draw a menu on screen. */
void
screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu,
int choice, const struct grid_cell *choice_gc)
{
struct screen *s = ctx->s;
struct grid_cell gc;
struct grid_cell default_gc;
const struct grid_cell *gc = &default_gc;
u_int cx, cy, i, j;
const char *name;
cx = s->cx;
cy = s->cy;
memcpy(&gc, &grid_default_cell, sizeof gc);
memcpy(&default_gc, &grid_default_cell, sizeof default_gc);
screen_write_box(ctx, menu->width + 4, menu->count + 2);
screen_write_cursormove(ctx, cx + 2, cy, 0);
format_draw(ctx, &gc, menu->width, menu->title, NULL);
format_draw(ctx, &default_gc, menu->width, menu->title, NULL);
for (i = 0; i < menu->count; i++) {
name = menu->items[i].name;
@ -432,20 +434,19 @@ screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
screen_write_hline(ctx, menu->width + 4, 1, 1);
} else {
if (choice >= 0 && i == (u_int)choice && *name != '-')
gc.attr |= GRID_ATTR_REVERSE;
gc = choice_gc;
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
for (j = 0; j < menu->width; j++)
screen_write_putc(ctx, &gc, ' ');
screen_write_putc(ctx, gc, ' ');
screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
if (*name == '-') {
name++;
gc.attr |= GRID_ATTR_DIM;
format_draw(ctx, &gc, menu->width, name, NULL);
gc.attr &= ~GRID_ATTR_DIM;
default_gc.attr |= GRID_ATTR_DIM;
format_draw(ctx, gc, menu->width, name, NULL);
default_gc.attr &= ~GRID_ATTR_DIM;
} else
format_draw(ctx, &gc, menu->width, name, NULL);
if (choice >= 0 && i == (u_int)choice)
gc.attr &= ~GRID_ATTR_REVERSE;
format_draw(ctx, gc, menu->width, name, NULL);
gc = &default_gc;
}
}