Misc tweaks / bug fixes

- readd "power off" to the main menu
- fix bug where stdout overflows into menu text
- remove +++++Go Back+++++ from main menu as there is nothing to go back to (detects menu depth)

Change-Id: Icb84ac86e55712412d07add0ab76955d7902f07c
This commit is contained in:
CEnnis91 2012-01-14 23:51:58 -05:00 committed by Koushik Dutta
parent de338e56b3
commit 4f78176329
5 changed files with 32 additions and 12 deletions

View File

@ -36,8 +36,9 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
if (!get_allow_toggle_display() && ui_menu_level > 0) {
return GO_BACK;
}
break;
case KEY_LEFTBRACE:
case KEY_ENTER:
@ -53,10 +54,13 @@ int device_handle_key(int key_code, int visible) {
if (ui_get_showing_back_button()) {
return SELECT_ITEM;
}
if (!get_allow_toggle_display())
if (!get_allow_toggle_display() && ui_menu_level > 0) {
return GO_BACK;
}
case KEY_BACK:
return GO_BACK;
if (ui_menu_level > 0) {
return GO_BACK;
}
}
}

View File

@ -29,6 +29,7 @@ char* MENU_ITEMS[] = { "reboot system now",
"backup and restore",
"mounts and storage",
"advanced",
"power off",
NULL };
void device_ui_init(UIParameters* ui_parameters) {

View File

@ -434,7 +434,8 @@ get_menu_selection(char** headers, char** items, int menu_only,
// throw away keys pressed previously, so user doesn't
// accidentally trigger menu items.
ui_clear_key_queue();
++ui_menu_level;
int item_count = ui_start_menu(headers, items, initial_selection);
int selected = initial_selection;
int chosen_item = -1;
@ -475,7 +476,8 @@ get_menu_selection(char** headers, char** items, int menu_only,
case SELECT_ITEM:
chosen_item = selected;
if (ui_get_showing_back_button()) {
if (chosen_item == item_count) {
if (chosen_item == item_count-1) {
--ui_menu_level;
chosen_item = GO_BACK;
}
}
@ -483,6 +485,7 @@ get_menu_selection(char** headers, char** items, int menu_only,
case NO_ACTION:
break;
case GO_BACK:
--ui_menu_level;
chosen_item = GO_BACK;
break;
}
@ -693,7 +696,8 @@ prompt_and_wait() {
for (;;) {
finish_recovery(NULL);
ui_reset_progress();
ui_menu_level = -1;
allow_display_toggle = 1;
int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0);
allow_display_toggle = 0;

View File

@ -90,6 +90,9 @@ extern char* MENU_HEADERS[];
// Text of menu items.
extern char* MENU_ITEMS[];
// Loosely track the depth of the current menu
int ui_menu_level;
int
get_menu_selection(char** headers, char** items, int menu_only, int initial_selection);

20
ui.c
View File

@ -237,6 +237,7 @@ static void draw_screen_locked(void)
int i = 0;
int j = 0;
int offset = 0; // offset of separating bar under menus
int row = 0; // current row that we are drawing on
if (show_menu) {
gr_color(MENU_TEXT_COLOR);
@ -266,8 +267,12 @@ static void draw_screen_locked(void)
}
row++;
}
gr_fill(0, row*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
gr_fb_width(), row*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
if (menu_items <= MAX_ROWS)
offset = 1;
gr_fill(0, (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2-1,
gr_fb_width(), (row-offset)*CHAR_HEIGHT+CHAR_HEIGHT/2+1);
}
gr_color(NORMAL_TEXT_COLOR);
@ -652,10 +657,13 @@ int ui_start_menu(char** headers, char** items, int initial_selection) {
menu[i][text_cols-1] = '\0';
}
if (gShowBackButton) {
if (gShowBackButton && ui_menu_level > 0) {
strcpy(menu[i], " - +++++Go Back+++++");
++i;
}
strcpy(menu[i], " ");
++i;
menu_items = i - menu_top;
show_menu = 1;
@ -663,7 +671,7 @@ int ui_start_menu(char** headers, char** items, int initial_selection) {
update_screen_locked();
}
pthread_mutex_unlock(&gUpdateMutex);
if (gShowBackButton) {
if (gShowBackButton && ui_menu_level > 0) {
return menu_items - 1;
}
return menu_items;
@ -676,8 +684,8 @@ int ui_menu_select(int sel) {
old_sel = menu_sel;
menu_sel = sel;
if (menu_sel < 0) menu_sel = menu_items + menu_sel;
if (menu_sel >= menu_items) menu_sel = menu_sel - menu_items;
if (menu_sel < 0) menu_sel = menu_items-1 + menu_sel;
if (menu_sel >= menu_items-1) menu_sel = menu_sel - menu_items+1;
if (menu_sel < menu_show_start && menu_show_start > 0) {