Keeping menu lines on a fixed position creates less visual noise when navigating the menus.
Showing the changes to scripts (1 of 1 file). Show all
Unified · Split
| @@ -58,7 +58,8 @@ · 57 unmodified lines | ||
| 58 | 58 | |
| 59 | 59 | #include "dialog.h" |
| 60 | 60 | |
| 61 | −static int menu_width, item_x; | |
| 61 | +#define ITEM_IDENT 4 /* Indent of menu entries. Fixed for all menus */ | |
| 62 | +static int menu_width; | |
| 62 | 63 | |
| 63 | 64 | /* |
| 64 | 65 | * Print menu item |
| @@ -86,13 +87,13 @@ static void print_item(WINDOW * win, const char *item, int choice, · 21 unmodified lines | ||
| 86 | 87 | wclrtoeol(win); |
| 87 | 88 | #endif |
| 88 | 89 | wattrset(win, selected ? item_selected_attr : item_attr); |
| 89 | − mvwaddstr(win, choice, item_x, menu_item); | |
| 90 | + mvwaddstr(win, choice, ITEM_IDENT, menu_item); | |
| 90 | 91 | if (hotkey) { |
| 91 | 92 | wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); |
| 92 | − mvwaddch(win, choice, item_x + j, menu_item[j]); | |
| 93 | + mvwaddch(win, choice, ITEM_IDENT + j, menu_item[j]); | |
| 93 | 94 | } |
| 94 | 95 | if (selected) { |
| 95 | − wmove(win, choice, item_x + 1); | |
| 96 | + wmove(win, choice, ITEM_IDENT + 1); | |
| 96 | 97 | wrefresh(win); |
| 97 | 98 | } |
| 98 | 99 | free(menu_item); |
| @@ -207,19 +208,10 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 108 unmodified lines | ||
| 207 | 208 | draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, |
| 208 | 209 | menubox_border_attr, menubox_attr); |
| 209 | 210 | |
| 210 | − /* | |
| 211 | − * Find length of longest item in order to center menu. | |
| 212 | − * Set 'choice' to default item. | |
| 213 | − */ | |
| 214 | − item_x = 0; | |
| 215 | − for (i = 0; i < item_no; i++) { | |
| 216 | − item_x = | |
| 217 | − MAX(item_x, MIN(menu_width, strlen(items[i * 2 + 1]) + 2)); | |
| 211 | + /* Set choice to default item */ | |
| 212 | + for (i = 0; i < item_no; i++) | |
| 218 | 213 | if (strcmp(current, items[i * 2]) == 0) |
| 219 | 214 | choice = i; |
| 220 | − } | |
| 221 | − | |
| 222 | − item_x = (menu_width - item_x) / 2; | |
| 223 | 215 | |
| 224 | 216 | /* get the scroll info from the temp file */ |
| 225 | 217 | if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { |
| @@ -254,10 +246,10 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 28 unmodified lines | ||
| 254 | 246 | wnoutrefresh(menu); |
| 255 | 247 | |
| 256 | 248 | print_arrows(dialog, item_no, scroll, |
| 257 | − box_y, box_x + item_x + 1, menu_height); | |
| 249 | + box_y, box_x + ITEM_IDENT + 1, menu_height); | |
| 258 | 250 | |
| 259 | 251 | print_buttons(dialog, height, width, 0); |
| 260 | − wmove(menu, choice, item_x + 1); | |
| 252 | + wmove(menu, choice, ITEM_IDENT + 1); | |
| 261 | 253 | wrefresh(menu); |
| 262 | 254 | |
| 263 | 255 | while (key != ESC) { |
| @@ -286,7 +278,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 22 unmodified lines | ||
| 286 | 278 | key == KEY_UP || key == KEY_DOWN || |
| 287 | 279 | key == '-' || key == '+' || |
| 288 | 280 | key == KEY_PPAGE || key == KEY_NPAGE) { |
| 289 | − | |
| 281 | + /* Remove highligt of current item */ | |
| 290 | 282 | print_item(menu, items[(scroll + choice) * 2 + 1], |
| 291 | 283 | choice, FALSE, |
| 292 | 284 | (items[(scroll + choice) * 2][0] != ':')); |
| @@ -364,7 +356,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 71 unmodified lines | ||
| 364 | 356 | choice, TRUE, (items[(scroll + choice) * 2][0] != ':')); |
| 365 | 357 | |
| 366 | 358 | print_arrows(dialog, item_no, scroll, |
| 367 | − box_y, box_x + item_x + 1, menu_height); | |
| 359 | + box_y, box_x + ITEM_IDENT + 1, menu_height); | |
| 368 | 360 | |
| 369 | 361 | wnoutrefresh(dialog); |
| 370 | 362 | wrefresh(menu); |