I create 3 windows on top of the standard screen, with screen-width columns and one row height with:
WINDOW* pWindow = newwin(0, COLS - 1, windowNr, 0); // windowNr 0 - 2
Which renders normally as consequitive windows:
----------------------------0 Window----------------------------
----------------------------1 Window----------------------------
----------------------------2 Window----------------------------
My problem is under the last created window I want a pad which I create with:
WINDOW* pPad = newpad(LINES - 3, COLS - 1); // 3 because of the three pWindows
But pad
is rendered above all pWindows
:
----------------------------0 Pad----------------------------
----------------------------0 Pad----------------------------
----------------------------0 Pad----------------------------
How can I position the pad below the last window that the output is:
----------------------------0 Window----------------------------
----------------------------1 Window----------------------------
----------------------------2 Window----------------------------
------------------------------0 Pad-----------------------------
------------------------------0 Pad-----------------------------
------------------------------0 Pad-----------------------------
The newpad
has unfortunately no (y,x) cooridnates as newwin
has. To simply fill the pad with debug content I do:
werase(pPad); // Clear window, https://invisible-island.net/ncurses/man/curs_clear.3x.html
wmove(pPad, 0, 0); // Moves cursor in pad to y,x
for(int c = 0; c < 40; c++){
string s = to_string(c) + ".\n";
wprintw(pPad, s.c_str());
}
prefresh(pPad, 0, 0, 0, 0, maxRows, maxCols);
I also put different values in prefresh
, its viewport scrolling or rather refreshing works perfectly as described in the documentation.
I keep the pad
content in memory and render only one single window as:
----------------------------0 Window----------------------------
----------------------------1 Window----------------------------
----------------------------2 Window----------------------------
----------------------------3 Window----------------------------
----------------------------3 Window----------------------------
----------------------------3 Window----------------------------
This enables mimicing a pad, since in 3 Window
only the viewpoint of my data is rendered as lines. Scrolling can be simulated by changeing the range or index in my data structure and rerender only one 3 Window
line if a line got selected and the whole window if scroll in- or decreases the memory viewport index. This way a pad is simulaed and I avoid the different ncurses calls as prefresh, pnoutrefresh, pechochar
etc. and can use only window, wrefresh
, calls. As an example, a scroll down would change:
----------------------------3 Window-index 0--------------------
----------------------------3 Window-index 1--------------------
----------------------------3 Window-index 2--------------------
to
----------------------------3 Window-index 1--------------------
----------------------------3 Window-index 2--------------------
----------------------------3 Window-index 3--------------------
and so on and so forth. In the ncurses API, windows seam to have more features, I can use all of them too instead of having possible future constraints by using pads
now.
I'm sure, the author of ncurses had his reasons, but I only would have made an API of ncurses with one window type with a flag to enable pad functionality. Pads seam unneccessarly cumbersome and reduced to me.