Any idea how to make a button using TUI in C?

927 views Asked by At

I'm working on a console-based C project and I want it to have some buttons.

  • How can I add some?
  • How can I manage focus?

I'm using windows.h for making TUI.

1

There are 1 answers

0
Edwin Buck On

Basically use the panels library (add on to ncurses) and make a second window, with a border, that contains your "button text". Remember to specify the z order such that the second window floats over the first, preferably over a non-text containing portion of the first.

Then bind the key navigation, and mouse enter / exit routines of other windows direct focus to the "next" desired window and to toggle that window's color (to indicate highlighting). Finally supply the window with a key handler to capture enter / space / whatever as a button click (which can then call whatever function you bind to it).

While there might be a better way to do this with the menu function, offhand I didn't discover (in my admittedly quick search) a way to hook the menu display of the "menu window" to an action other than displaying the menu window.