From 13ac0e367d61c7127b1467d70011999e94944f4b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 22 Feb 2018 22:04:04 +1100 Subject: [PATCH] NCursesUI: Rework menu placement to fix missing menu on small window --- src/ncurses_ui.cc | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc index be8cbd1b..55dbdba2 100644 --- a/src/ncurses_ui.cc +++ b/src/ncurses_ui.cc @@ -717,13 +717,14 @@ void NCursesUI::menu_show(ConstArrayView items, m_menu.style = style; m_menu.anchor = anchor; - if (style == MenuStyle::Prompt) - anchor = DisplayCoord{m_status_on_top ? 0_line : m_dimensions.line, 0}; - else if (m_status_on_top) - anchor.line += 1; - DisplayCoord maxsize = m_dimensions; - maxsize.column -= anchor.column; + if (style != MenuStyle::Prompt) + { + if (m_status_on_top) + anchor.line += 1; + maxsize.column -= anchor.column; + } + if (maxsize.column <= 2) return; @@ -748,16 +749,20 @@ void NCursesUI::menu_show(ConstArrayView items, kak_assert(m_menu.items.back().length() <= maxlen); } - int height = min(10, div_round_up(item_count, m_menu.columns)); + const LineCount height = min(min(10_line, maxsize.line), + div_round_up(item_count, m_menu.columns)); - int line = (int)anchor.line + 1; - if (line + height >= (int)maxsize.line) - line = (int)anchor.line - height; - m_menu.selected_item = item_count; - m_menu.top_line = 0; + LineCount line = anchor.line + 1; + if (is_prompt) + line = m_status_on_top ? 1_line : m_dimensions.line - height; + else if (line + height >= maxsize.line) + line = anchor.line - height; auto width = is_prompt ? maxsize.column : min(longest+1, maxsize.column); m_menu.create({line, anchor.column}, {height, width}); + m_menu.selected_item = item_count; + m_menu.top_line = 0; + draw_menu(); if (m_info)