diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-12-15 19:10:59 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-12-15 19:11:04 +0100 |
| commit | df14427210b22049f14f1275a5bfcd1e8ee4aa4e (patch) | |
| tree | 414291c5a2c00a0651ea10ed9f79cffe79e4b9a8 /src | |
| parent | fd09e8a2dead9cc2111453d6aaa4b6a4aea548d8 (diff) | |
NCurses: info window tries to avoid the menu one
Diffstat (limited to 'src')
| -rw-r--r-- | src/ncurses.cc | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/ncurses.cc b/src/ncurses.cc index 2ce95417..12da65fa 100644 --- a/src/ncurses.cc +++ b/src/ncurses.cc @@ -148,6 +148,13 @@ static DisplayCoord window_size(WINDOW* win) return size; } +static DisplayCoord window_pos(WINDOW* win) +{ + DisplayCoord pos; + getbegyx(win, (int&)pos.line, (int&)pos.column); + return pos; +} + void NCursesUI::update_dimensions() { m_dimensions = window_size(stdscr); @@ -400,12 +407,32 @@ static DisplayCoord compute_needed_size(const String& str) } static DisplayCoord compute_pos(const DisplayCoord& anchor, - const DisplayCoord& size) + const DisplayCoord& size, + WINDOW* opt_window_to_avoid = nullptr) { DisplayCoord scrsize = window_size(stdscr); DisplayCoord pos = { anchor.line+1, anchor.column }; if (pos.line + size.line >= scrsize.line) pos.line = anchor.line - size.line; + + if (opt_window_to_avoid) + { + DisplayCoord winbeg = window_pos(opt_window_to_avoid); + DisplayCoord winend = winbeg + window_size(opt_window_to_avoid); + + DisplayCoord end = pos + size; + + // check intersection + if (not (end.line < winbeg.line or end.column < winbeg.column or + pos.line > winend.line or pos.column > winend.column)) + { + pos.line = std::min(winbeg.line, anchor.line) - size.line; + // if above does not work, try below + if (pos.line < 0) + pos.line = std::max(winend.line, anchor.line); + } + } + return pos; } @@ -417,7 +444,7 @@ void NCursesUI::info_show(const String& content, const DisplayCoord& anchor, Men if (style == MenuStyle::Prompt) size.column = window_size(stdscr).column - anchor.column; - DisplayCoord pos = compute_pos(anchor, size); + DisplayCoord pos = compute_pos(anchor, size, m_menu_win); m_info_win = newwin((int)size.line, (int)size.column, (int)pos.line, (int)pos.column); |
