2020-01-30 13:55:01 +00:00
|
|
|
% notcurses_selector(3)
|
|
|
|
% nick black <nickblack@linux.com>
|
2020-11-27 21:49:56 +00:00
|
|
|
% v2.0.8
|
2020-01-30 13:55:01 +00:00
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
|
|
|
notcurses_selector - high level widget for selecting from a set
|
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
2020-04-19 22:46:32 +00:00
|
|
|
**#include <notcurses/notcurses.h>**
|
2020-01-30 13:55:01 +00:00
|
|
|
|
|
|
|
```c
|
2020-04-27 23:11:00 +00:00
|
|
|
struct ncinput;
|
|
|
|
struct ncplane;
|
|
|
|
struct notcurses;
|
|
|
|
struct ncselector;
|
2020-02-11 01:22:23 +00:00
|
|
|
|
2020-05-09 00:56:39 +00:00
|
|
|
struct ncselector_item {
|
2020-01-31 22:44:30 +00:00
|
|
|
char* option;
|
|
|
|
char* desc;
|
|
|
|
};
|
|
|
|
|
2020-05-09 00:56:39 +00:00
|
|
|
typedef struct ncselector_options {
|
2020-01-31 22:44:30 +00:00
|
|
|
char* title; // title may be NULL, inhibiting riser
|
|
|
|
char* secondary; // secondary may be NULL
|
|
|
|
char* footer; // footer may be NULL
|
2020-05-09 00:56:39 +00:00
|
|
|
struct ncselector_item* items; // initial items and descriptions
|
2020-01-31 22:44:30 +00:00
|
|
|
// default item (selected at start)
|
|
|
|
unsigned defidx;
|
|
|
|
// maximum number of options to display at once
|
|
|
|
unsigned maxdisplay;
|
|
|
|
// exhaustive styling options
|
|
|
|
uint64_t opchannels; // option channels
|
|
|
|
uint64_t descchannels; // description channels
|
|
|
|
uint64_t titlechannels;// title channels
|
|
|
|
uint64_t footchannels; // secondary and footer channels
|
|
|
|
uint64_t boxchannels; // border channels
|
2020-11-06 23:15:57 +00:00
|
|
|
uint64_t flags; // bitfield over NCSELECTOR_OPTION_*
|
2020-05-09 00:56:39 +00:00
|
|
|
} ncselector_options;
|
2020-01-30 13:55:01 +00:00
|
|
|
```
|
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**struct ncselector* ncselector_create(struct ncplane* ***n***, const ncselector_options* ***opts***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncselector_additem(struct ncselector* ***n***, const struct ncselector_item* ***item***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**int ncselector_delitem(struct ncselector* ***n***, const char* ***item***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**const char* ncselector_selected(const struct ncselector* ***n***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**struct ncplane* ncselector_plane(struct ncselector* ***n***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**const char* ncselector_previtem(struct ncselector* ***n***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**const char* ncselector_nextitem(struct ncselector* ***n***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**bool ncselector_offer_input(struct ncselector* ***n***, const struct ncinput* ***nc***);**
|
2020-02-11 01:22:23 +00:00
|
|
|
|
2020-11-06 21:49:35 +00:00
|
|
|
**void ncselector_destroy(struct ncselector* ***n***, char\*\* ***item***);**
|
2020-01-31 22:44:30 +00:00
|
|
|
|
2020-01-30 13:55:01 +00:00
|
|
|
# DESCRIPTION
|
|
|
|
|
|
|
|
# NOTES
|
|
|
|
|
2020-09-13 10:46:06 +00:00
|
|
|
The **ncplane** **n** provided to **ncselector_create** must not be **NULL**.
|
|
|
|
It will be freely resized by the new **ncselector**. **ncselector_selected**
|
2020-08-16 09:54:58 +00:00
|
|
|
returns the currently-selected option. **ncselector_additem** and
|
|
|
|
**ncselector_delitem** allow items to be added and deleted on the fly
|
|
|
|
(a static set of items can all be provided in the **ncselector_create**
|
2020-09-13 10:46:06 +00:00
|
|
|
call). The backing plane will be resized as necessary for item changes.
|
|
|
|
|
|
|
|
**ncselector_nextitem** and **ncselector_previtem** select the next (down) or
|
|
|
|
previous (up) option, scrolling if necessary. It is safe to call these
|
|
|
|
functions even if no options are present.
|
2020-08-16 09:54:58 +00:00
|
|
|
|
|
|
|
**ncselector_plane** will return the **ncplane** on which the widget is
|
|
|
|
drawn.
|
|
|
|
|
|
|
|
While the **ncselector** can be driven entirely by client code, input can
|
|
|
|
be run through **ncselector_offer_input** to take advantage of common
|
|
|
|
controls. It will handle the up and down arrows, along with PageUp and
|
|
|
|
PageDown. If the mouse is enabled, the mouse scrollwheel and mouse clicks
|
|
|
|
on the scroll arrows will be handled.
|
2020-05-09 11:51:23 +00:00
|
|
|
|
2020-09-13 10:46:06 +00:00
|
|
|
**ncselector_destroy** destroys the backing **ncplane**, as does
|
|
|
|
**ncselector_create** in the event of any error.
|
|
|
|
|
2020-01-30 13:55:01 +00:00
|
|
|
# RETURN VALUES
|
|
|
|
|
2020-09-13 10:46:06 +00:00
|
|
|
**ncselector_create** returns **NULL** on an error, in which case the passed
|
|
|
|
**ncplane** is destroyed.
|
|
|
|
|
|
|
|
**ncselector_selected** returns a reference to the **option** part of the
|
|
|
|
selected **ncselector_item**. If there are no items, it returns **NULL**.
|
|
|
|
|
|
|
|
**ncselector_previtem** and **ncselector_nextitem** return references to the
|
|
|
|
**option** part of the newly-selected **ncselector_item**. If there are no
|
|
|
|
items, they return **NULL**.
|
|
|
|
|
2020-01-30 13:55:01 +00:00
|
|
|
# SEE ALSO
|
|
|
|
|
2020-02-11 01:22:23 +00:00
|
|
|
**notcurses(3)**,
|
|
|
|
**notcurses_input(3)**,
|
2020-03-09 19:17:41 +00:00
|
|
|
**notcurses_multiselector(3)**
|
2020-05-09 00:56:39 +00:00
|
|
|
**notcurses_plane(3)**
|