NCurses: draw a scroll bar
This commit is contained in:
parent
3f467ba451
commit
07a2c2944f
|
@ -325,10 +325,14 @@ void NCursesUI::draw_menu()
|
||||||
auto menu_fg = get_color_pair({ Color::Blue, Color::Cyan });
|
auto menu_fg = get_color_pair({ Color::Blue, Color::Cyan });
|
||||||
auto menu_bg = get_color_pair({ Color::Cyan, Color::Blue });
|
auto menu_bg = get_color_pair({ Color::Cyan, Color::Blue });
|
||||||
|
|
||||||
|
auto scroll_fg = get_color_pair({ Color::White, Color::White });
|
||||||
|
auto scroll_bg = get_color_pair({ Color::White, Color::Blue });
|
||||||
|
|
||||||
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
||||||
wbkgdset(m_menu_win, COLOR_PAIR(menu_bg));
|
wbkgdset(m_menu_win, COLOR_PAIR(menu_bg));
|
||||||
DisplayCoord menu_size = window_size(m_menu_win);
|
DisplayCoord menu_size = window_size(m_menu_win);
|
||||||
CharCount column_width = menu_size.column / m_menu_columns;
|
CharCount column_width = (menu_size.column - 1) / m_menu_columns;
|
||||||
|
LineCount mark_line = (menu_size.line * m_selected_choice) / (int)m_choices.size();
|
||||||
for (auto line = 0_line; line < menu_size.line; ++line)
|
for (auto line = 0_line; line < menu_size.line; ++line)
|
||||||
{
|
{
|
||||||
wmove(m_menu_win, (int)line, 0);
|
wmove(m_menu_win, (int)line, 0);
|
||||||
|
@ -349,6 +353,10 @@ void NCursesUI::draw_menu()
|
||||||
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
||||||
}
|
}
|
||||||
wclrtoeol(m_menu_win);
|
wclrtoeol(m_menu_win);
|
||||||
|
wmove(m_menu_win, (int)line, (int)menu_size.column - 1);
|
||||||
|
wattron(m_menu_win, COLOR_PAIR(line == mark_line ? scroll_fg : scroll_bg));
|
||||||
|
waddch(m_menu_win, ' ');
|
||||||
|
wattron(m_menu_win, COLOR_PAIR(menu_bg));
|
||||||
}
|
}
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -366,12 +374,12 @@ void NCursesUI::menu_show(const memoryview<String>& choices,
|
||||||
CharCount longest = 0;
|
CharCount longest = 0;
|
||||||
for (auto& choice : choices)
|
for (auto& choice : choices)
|
||||||
{
|
{
|
||||||
m_choices.push_back(choice.substr(0_char, std::min((int)maxsize.column-1, 200)));
|
m_choices.push_back(choice.substr(0_char, std::min((int)maxsize.column-2, 200)));
|
||||||
longest = std::max(longest, m_choices.back().char_length());
|
longest = std::max(longest, m_choices.back().char_length());
|
||||||
}
|
}
|
||||||
longest += 1;
|
longest += 1;
|
||||||
|
|
||||||
m_menu_columns = (style == MenuStyle::Prompt) ? (int)(maxsize.column / longest) : 1;
|
m_menu_columns = (style == MenuStyle::Prompt) ? (int)((maxsize.column -1) / longest) : 1;
|
||||||
int lines = std::min(10, (int)ceilf((float)m_choices.size()/m_menu_columns));
|
int lines = std::min(10, (int)ceilf((float)m_choices.size()/m_menu_columns));
|
||||||
|
|
||||||
DisplayCoord pos = { anchor.line+1, anchor.column };
|
DisplayCoord pos = { anchor.line+1, anchor.column };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user