Hide and show panels
Adapted from Writing Programs with NCURSES, by Eric S. Raymond and Zeyd M. Ben-Halim and NCURSES Programming HOWTO, by Pradeep Padala.
It is possible to remove a panel from the deck temporarily; use hide_panel() for this. It doesn’t destroy the PANEL structure associated with the hidden panel; the panel disappears from the screen at the next update_panels() and doupdate(). Use show_panel() to render it visible again. The predicate function panel_hidden() tests whether or not a panel is hidden: it returns TRUE if the panel is not in the deck and FALSE if it is.
The update_panels() function ignores hidden panels. In ncurses, top_panel() and bottom_panel() also work on a hidden panel, and make it visible at the top or the bottom of the deck. In the System V panel library, show_panel() is intended for making a hidden panel visible and top_panel() for moving a visible panel to the top, so use show_panel() on a hidden panel if your program may be built with that library. Other panel operations are applicable to hidden panels.
The following program hides and shows panels. Press a, b or c to show or hide the first, second or third window.
Example: Panel Hiding and Showing example
#include <stdlib.h>#include <string.h>#include <panel.h>
#define NLINES 10#define NCOLS 40
static void{ int length, x, y; float temp;
if (win == NULL) if (startx != 0) x = startx; if (starty != 0) y = starty; if (width == 0) width = 80;
length = (int) strlen(string); temp = (float) (width - length) / 2; x = startx + (int) temp;}
/* Show the window with a border and a label */static void{ int height, width;
(void) height;
}
/* Put all the windows */static void{ int x, y, i; char label[80];
y = 2; x = 10; for (i = 0; i < n; ++i) { sprintf(label, "Window Number %d", i + 1); win_show(wins[i], label, i + 1); y += 3; x += 7; }}
intmain(void){ int ch;
/* Initialize curses */
/* Initialize all the colors */
init_wins(my_wins, 3);
/* Attach a panel to each window */ /* Order is bottom up */ /* Push 0, order: stdscr-0 */ /* Push 1, order: stdscr-0-1 */ /* Push 2, order: stdscr-0-1-2 */
/* Update the stacking order. The last panel created is on top */
/* Show it on the screen */ "Press 'a', 'b' or 'c' to show or hide " "the first, second or third window");
switch (ch) { case 'a': else break; case 'b': else break; case 'c': else break; } } return EXIT_SUCCESS;}