mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-29 14:44:56 +03:00
added option for vertical menu layout in the ncurses ui
This commit is contained in:
parent
da13b5f814
commit
a1e3fa02e6
@ -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"
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user