aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2005-11-20 16:41:21 -0500
committerSam Ravnborg <sam@mars.ravnborg.org>2005-11-20 16:41:21 -0500
commit0e175d05a4e72f85918da3ea4bd9f5d3d78face4 (patch)
treec5cc66d5af52c048c24f9a182bda06135653f9cf /scripts/lxdialog
parentfa7009d5b59b8acd8071f7b3057d36eeeaf08146 (diff)
kconfig: Left aling menu items in menuconfig
Keeping menu lines on a fixed position creates less visual noise when navigating the menus. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/lxdialog')
-rw-r--r--scripts/lxdialog/menubox.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index ebfe6a3c8ccc..89fcf418a07a 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -58,7 +58,8 @@
58 58
59#include "dialog.h" 59#include "dialog.h"
60 60
61static int menu_width, item_x; 61#define ITEM_IDENT 4 /* Indent of menu entries. Fixed for all menus */
62static int menu_width;
62 63
63/* 64/*
64 * Print menu item 65 * Print menu item
@@ -86,13 +87,13 @@ static void print_item(WINDOW * win, const char *item, int choice,
86 wclrtoeol(win); 87 wclrtoeol(win);
87#endif 88#endif
88 wattrset(win, selected ? item_selected_attr : item_attr); 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 if (hotkey) { 91 if (hotkey) {
91 wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); 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 if (selected) { 95 if (selected) {
95 wmove(win, choice, item_x + 1); 96 wmove(win, choice, ITEM_IDENT + 1);
96 wrefresh(win); 97 wrefresh(win);
97 } 98 }
98 free(menu_item); 99 free(menu_item);
@@ -207,19 +208,10 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
207 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, 208 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
208 menubox_border_attr, menubox_attr); 209 menubox_border_attr, menubox_attr);
209 210
210 /* 211 /* Set choice to default item */
211 * Find length of longest item in order to center menu. 212 for (i = 0; i < item_no; i++)
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));
218 if (strcmp(current, items[i * 2]) == 0) 213 if (strcmp(current, items[i * 2]) == 0)
219 choice = i; 214 choice = i;
220 }
221
222 item_x = (menu_width - item_x) / 2;
223 215
224 /* get the scroll info from the temp file */ 216 /* get the scroll info from the temp file */
225 if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { 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,
254 wnoutrefresh(menu); 246 wnoutrefresh(menu);
255 247
256 print_arrows(dialog, item_no, scroll, 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 print_buttons(dialog, height, width, 0); 251 print_buttons(dialog, height, width, 0);
260 wmove(menu, choice, item_x + 1); 252 wmove(menu, choice, ITEM_IDENT + 1);
261 wrefresh(menu); 253 wrefresh(menu);
262 254
263 while (key != ESC) { 255 while (key != ESC) {
@@ -286,7 +278,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
286 key == KEY_UP || key == KEY_DOWN || 278 key == KEY_UP || key == KEY_DOWN ||
287 key == '-' || key == '+' || 279 key == '-' || key == '+' ||
288 key == KEY_PPAGE || key == KEY_NPAGE) { 280 key == KEY_PPAGE || key == KEY_NPAGE) {
289 281 /* Remove highligt of current item */
290 print_item(menu, items[(scroll + choice) * 2 + 1], 282 print_item(menu, items[(scroll + choice) * 2 + 1],
291 choice, FALSE, 283 choice, FALSE,
292 (items[(scroll + choice) * 2][0] != ':')); 284 (items[(scroll + choice) * 2][0] != ':'));
@@ -364,7 +356,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
364 choice, TRUE, (items[(scroll + choice) * 2][0] != ':')); 356 choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
365 357
366 print_arrows(dialog, item_no, scroll, 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 wnoutrefresh(dialog); 361 wnoutrefresh(dialog);
370 wrefresh(menu); 362 wrefresh(menu);