summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Frank <justinpfrank@protonmail.com>2018-07-20 10:30:47 -0700
committerJustin Frank <justinpfrank@protonmail.com>2018-10-15 14:07:39 -0700
commita1e3fa02e6d4bf635b4c1ec946ee4fdfe5a3c150 (patch)
treea23e0e20333a0d4b7c5a949b4c7c921446dccc9f /src
parentda13b5f8143a3809bb938c020b957e1c5ff8dae7 (diff)
added option for vertical menu layout in the ncurses ui
Diffstat (limited to 'src')
-rw-r--r--src/main.cc1
-rw-r--r--src/ncurses_ui.cc61
-rw-r--r--src/ncurses_ui.hh2
3 files changed, 50 insertions, 14 deletions
diff --git a/src/main.cc b/src/main.cc
index 6fda5da6..e8e5564f 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -396,6 +396,7 @@ void register_options()
"The ncurses ui supports the following options:\n"
" <key>: <value>:\n"
" ncurses_assistant clippy|cat|dilbert|none|off\n"
+ " ncurses_menu_layout horizontal|vertical\n"
" ncurses_status_on_top bool\n"
" ncurses_set_title bool\n"
" ncurses_enable_mouse bool\n"
diff --git a/src/ncurses_ui.cc b/src/ncurses_ui.cc
index e830c012..bf4517aa 100644
--- a/src/ncurses_ui.cc
+++ b/src/ncurses_ui.cc
@@ -741,16 +741,31 @@ void NCursesUI::draw_menu()
const LineCount mark_height = min(div_round_up(sq(win_height), menu_lines),
win_height);
const LineCount top_line = m_menu.first_item / m_menu.columns;
- const LineCount mark_line = (win_height - mark_height) * top_line / max(1_line, menu_lines - win_height);
+
+ const int menu_cols = div_round_up(item_count, (int)m_menu.size.line);
+ const int first_col = m_menu.first_item / (int)m_menu.size.line;
+
+ const LineCount mark_line = m_menu_vertical ? (win_height - mark_height) * first_col / max(1, menu_cols - m_menu.columns) :
+ (win_height - mark_height) * top_line / max(1_line, menu_lines - win_height);
+
for (auto line = 0_line; line < win_height; ++line)
{
wmove(m_menu.win, (int)line, 0);
for (int col = 0; col < m_menu.columns; ++col)
{
- const int item_idx = (int)(top_line + line) * m_menu.columns
- + col;
- if (item_idx >= item_count)
- break;
+ int item_idx;
+ if (m_menu_vertical)
+ {
+ item_idx = (first_col + col) * (int)m_menu.size.line + (int)line;
+ if (item_idx >= item_count)
+ continue;
+ }
+ else
+ {
+ item_idx = (int)(top_line + line) * m_menu.columns + col;
+ if (item_idx >= item_count)
+ break;
+ }
const DisplayLine& item = m_menu.items[item_idx];
draw_line(m_menu.win, item, 0, column_width,
@@ -883,15 +898,28 @@ void NCursesUI::menu_select(int selected)
else
{
m_menu.selected_item = selected;
- const LineCount win_height = m_menu.size.line;
- const LineCount top_line = m_menu.first_item / m_menu.columns;
- const LineCount menu_lines = div_round_up(item_count, m_menu.columns);
- const LineCount selected_line = m_menu.selected_item / m_menu.columns;
- kak_assert(menu_lines >= win_height);
- if (selected_line < top_line)
- m_menu.first_item = (int)selected_line * m_menu.columns;
- if (selected_line >= top_line + win_height)
- m_menu.first_item = (int)min(selected_line, menu_lines - win_height) * m_menu.columns;
+ if (m_menu_vertical)
+ {
+ const int menu_cols = div_round_up(item_count, (int)m_menu.size.line);
+ const int first_col = m_menu.first_item / (int)m_menu.size.line;
+ const int selected_col = m_menu.selected_item / (int)m_menu.size.line;
+ if (selected_col < first_col)
+ m_menu.first_item = selected_col * (int)m_menu.size.line;
+ if (selected_col >= first_col + m_menu.columns)
+ m_menu.first_item = min(selected_col, menu_cols - m_menu.columns) * (int)m_menu.size.line;
+ }
+ else
+ {
+ const LineCount menu_lines = div_round_up(item_count, m_menu.columns);
+ const LineCount win_height = m_menu.size.line;
+ const LineCount top_line = m_menu.first_item / m_menu.columns;
+ const LineCount selected_line = m_menu.selected_item / m_menu.columns;
+ kak_assert(menu_lines >= win_height);
+ if (selected_line < top_line)
+ m_menu.first_item = (int)selected_line * m_menu.columns;
+ if (selected_line >= top_line + win_height)
+ m_menu.first_item = (int)min(selected_line, menu_lines - win_height) * m_menu.columns;
+ }
}
draw_menu();
}
@@ -1229,6 +1257,11 @@ void NCursesUI::set_ui_options(const Options& options)
m_wheel_down_button = wheel_down_it != options.end() ?
str_to_int_ifp(wheel_down_it->value).value_or(5) : 5;
}
+
+ {
+ auto it = options.find("ncurses_menu_layout"_sv);
+ m_menu_vertical = it != options.end() and it->value == "vertical";
+ }
}
}
diff --git a/src/ncurses_ui.hh b/src/ncurses_ui.hh
index 69eee61c..76b70c5b 100644
--- a/src/ncurses_ui.hh
+++ b/src/ncurses_ui.hh
@@ -147,6 +147,8 @@ private:
bool m_set_title = true;
bool m_change_colors = true;
+ bool m_menu_vertical = false;
+
bool m_dirty = false;
bool m_resize_pending = false;