From 67d0ca0764e5ab9a0d0e5baa5bf062d0ac5c8596 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 3 Mar 2014 18:15:31 +0800 Subject: [PATCH] ui/ncurses: Ensure that the selected menu item is visible When adding new items to the petitboot menu, we need to ensure that the scroll position of the menu includes the currently-selected item. This change adds a call to set_top_row, calculated from the selected item index, and the number of rows in the menu. Signed-off-by: Jeremy Kerr --- ui/ncurses/nc-cui.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 650e903..fd90419 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -390,13 +390,14 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, struct cui *cui = cui_from_arg(arg); struct cui_opt_data *cod; unsigned int insert_pt; + int result, rows, cols; struct pmenu_item *i; ITEM *selected; - int result; pb_debug("%s: %p %s\n", __func__, opt, opt->id); selected = current_item(cui->main->ncm); + menu_format(cui->main->ncm, &rows, &cols); if (cui->current == &cui->main->scr) nc_scr_unpost(cui->current); @@ -449,10 +450,20 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt, item_count(cui->main->ncm) + 1); } - /* FIXME: need to make item visible somehow */ - menu_driver(cui->main->ncm, REQ_SCR_UPAGE); - menu_driver(cui->main->ncm, REQ_SCR_DPAGE); - set_current_item(cui->main->ncm, selected); + if (!item_visible(selected)) { + int idx, top; + + top = top_row(cui->main->ncm); + idx = item_index(selected); + + /* If our index is above the current top row, align + * us to the new top. Otherwise, align us to the new + * bottom */ + top = top < idx ? idx - rows : idx; + + set_top_row(cui->main->ncm, top); + set_current_item(cui->main->ncm, selected); + } if (cui->current == &cui->main->scr) nc_scr_post(cui->current); -- 2.39.2