summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-20 05:54:19 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-20 05:54:19 +1100
commitf7f84b740219da560c03f84b496f96ea4616e907 (patch)
tree53c16321ef4d39470144a5747e028224b2192475 /src
parent826977eb1b72ed67f6f35d7fd735c839e41ae947 (diff)
NCursesUI: Rework menu_show to shrink menu height when needed
Closes #1886
Diffstat (limited to 'src')
-rw-r--r--src/ncurses_ui.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc
index 662ef764..21e7a33a 100644
--- a/src/ncurses_ui.cc
+++ b/src/ncurses_ui.cc
@@ -717,11 +717,7 @@ void NCursesUI::menu_show(ConstArrayView<DisplayLine> items,
m_menu.style = style;
m_menu.anchor = anchor;
- const DisplayCoord maxsize = m_dimensions;
- if (style != MenuStyle::Prompt and m_status_on_top)
- anchor.line += 1;
-
- if (maxsize.column <= 2)
+ if (m_dimensions.column <= 2)
return;
const int item_count = items.size();
@@ -730,7 +726,7 @@ void NCursesUI::menu_show(ConstArrayView<DisplayLine> items,
const auto longest = accumulate(items | transform(&DisplayLine::length),
1_col, [](auto&& lhs, auto&& rhs) { return std::max(lhs, rhs); });
- const ColumnCount last_column = maxsize.column - 1;
+ const ColumnCount last_column = m_dimensions.column - 1;
const bool is_prompt = style == MenuStyle::Prompt;
m_menu.columns = is_prompt ? max((int)(last_column / (longest+1)), 1) : 1;
@@ -744,18 +740,22 @@ void NCursesUI::menu_show(ConstArrayView<DisplayLine> items,
kak_assert(m_menu.items.back().length() <= maxlen);
}
- const LineCount height = min<LineCount>(min(10_line, maxsize.line),
+ const LineCount max_height = std::max(anchor.line, m_dimensions.line - anchor.line - 1);
+ const LineCount height = min<LineCount>(min(10_line, max_height),
div_round_up(item_count, m_menu.columns));
+ if (style != MenuStyle::Prompt and m_status_on_top)
+ anchor.line += 1;
+
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)
+ else if (line + height > m_dimensions.line)
line = anchor.line - height;
- const ColumnCount column = std::max(0_col, std::min(anchor.column, maxsize.column - longest - 1));
+ const ColumnCount column = std::max(0_col, std::min(anchor.column, m_dimensions.column - longest - 1));
- auto width = is_prompt ? maxsize.column : min(longest+1, maxsize.column);
+ auto width = is_prompt ? m_dimensions.column : min(longest+1, m_dimensions.column);
m_menu.create({line, column}, {height, width});
m_menu.selected_item = item_count;
m_menu.top_line = 0;