简体   繁体   中英

How to implement a scroll or list box in NCurses/PdCurses? ( C )

I am in the midst of creating a text user interface app for a school project. I really need help on how to implement a scroll box or list box in NCurses/PDCurses(in C).

As far as I researched, scrollok makes it possible. I have tried it to my project but to no avail.

The scroll box is used for showing list of names vertically and when user presses "N", it scrolls next part and when the user presses "P" it scrolls to previous part.

Thanks!

scrollok doesn't magically create a scroll box, it just allows the window to be scrolled up. You do not even need scrollok for your purpose. Just

  • maintain an index i to the topmost name which is to be displayed (initially 0)
  • print height h names from index i to min( i+h-1 , i max ) to the window, starting at the topmost line
  • when user presses "N", if i+hi max then set i to i+h , clear window box, go to print
  • when user presses "P", if i > 0 then set i to ih , clear window box, go to print

Have you seen CDK ( Curses Development Kit ) it has source code so you can inspect or just use it. There is also information on ncurses site on this toolkit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM