Skip to content

Commit

Permalink
multiselector options/items #322
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Mar 9, 2020
1 parent 527ae27 commit b49674f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,27 @@ Selectors:
╰────────────────────────────────────here's the footer───╯
```
Multiselectors:
```
╭────────────────────────────────────────────────────────────────╮
│ this is truly an awfully long example of a MULTISELECTOR title │
╭─────┴─────────────────────────────pick one (you will die regardless)─┤
│ ↑ │
│ ☐ 1 Across the Atlantic Ocean, there was a place called North America│
│ ☐ 2 Discovered by an Italian in the employ of the queen of Spain │
│ ☒ 3 Colonized extensively by the Spanish and the French │
│ ☐ 4 Developed into a rich nation by Dutch-supplied African slaves │
│ ☐ 5 And thus became the largest English-speaking nation on earth │
│ ☐ 6 Namely, the United States of America │
│ ☐ 7 The inhabitants of the United States called themselves Yankees │
│ ☒ 8 For some reason │
│ ☐ 9 And, eventually noticing the rest of the world was there, │
│ ☐ 10 Decided to rule it. │
│ ↓ │
╰─────────────────────────press q to exit (there is sartrev("no exit")─╯
```
Menus:
```
Expand Down
3 changes: 2 additions & 1 deletion include/notcurses/notcurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,8 @@ struct ncmultiselector;
API struct ncmultiselector* ncmultiselector_create(struct ncplane* n, int y, int x,
const multiselector_options* opts);

// FIXME
// Return a reference to the ncmultiselector's underlying ncplane.
API struct ncplane* ncmultiselector_plane(struct ncmultiselector* n);

// Offer the input to the ncmultiselector. If it's relevant, this function
// returns true, and the input ought not be processed further. If it's
Expand Down
25 changes: 25 additions & 0 deletions python/src/notcurses/build_notcurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,31 @@
const char* ncselector_nextitem(struct ncselector* n);
bool ncselector_offer_input(struct ncselector* n, const struct ncinput* nc);
void ncselector_destroy(struct ncselector* n, char** item);
struct mselector_item {
char* option;
char* desc;
bool selected;
};
typedef struct multiselector_options {
char* title; // title may be NULL, inhibiting riser, saving two rows.
char* secondary; // secondary may be NULL
char* footer; // footer may be NULL
struct mselector_item* items; // initial items, descriptions, and statuses
unsigned itemcount; // number of items and descriptions, can't be 0
// maximum number of options to display at once, 0 to use all available space
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
uint64_t bgchannels; // background channels, used only in body
} multiselector_options;
struct ncmultiselector* ncmultiselector_create(struct ncplane* n, int y, int x, const multiselector_options* opts);
struct ncplane* ncmultiselector_plane(struct ncmultiselector* n);
bool ncmultiselector_offer_input(struct ncmultiselector* n, const struct ncinput* nc);
void ncmultiselector_destroy(struct ncmultiselector* n, char** item);
struct ncmenu_item {
char* desc; // utf-8 menu item, NULL for horizontal separator
ncinput shortcut; // shortcut, all should be distinct
Expand Down
4 changes: 4 additions & 0 deletions src/lib/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ void ncselector_destroy(ncselector* n, char** item){
}
}

ncplane* ncmultiselector_plane(ncmultiselector* n){
return n->ncp;
}

// ideal body width given the ncselector's items and secondary/footer
static int
ncmultiselector_body_width(const ncmultiselector* n){
Expand Down

0 comments on commit b49674f

Please sign in to comment.