Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Selector.hh
Go to the documentation of this file.
1#ifndef __NCPP_SELECTOR_HH
2#define __NCPP_SELECTOR_HH
3
5
6#include "NCAlign.hh"
7#include "Plane.hh"
8#include "Utilities.hh"
9#include "Widget.hh"
10
11namespace ncpp
12{
14 {
15 public:
17
18 public:
19 explicit Selector (Plane *plane, const ncselector_options *opts = nullptr)
20 : Widget (Utilities::get_notcurses_cpp (plane))
21 {
22 if (plane == nullptr)
23 throw invalid_argument ("'plane' must be a valid pointer");
24
25 ensure_valid_plane (plane);
26 common_init (Utilities::to_ncplane (plane), opts);
27 take_plane_ownership (plane);
28 }
29
30 explicit Selector (Plane &plane, const ncselector_options *opts = nullptr)
31 : Widget (Utilities::get_notcurses_cpp (plane))
32 {
33 ensure_valid_plane (plane);
34 common_init (Utilities::to_ncplane (plane), opts);
35 take_plane_ownership (plane);
36 }
37
39 {
40 if (!is_notcurses_stopped ())
41 ncselector_destroy (selector, nullptr);
42 }
43
44 int additem (const ncselector_item *item) const NOEXCEPT_MAYBE
45 {
46 return error_guard<int> (ncselector_additem (selector, item), -1);
47 }
48
49 int delitem (const char *item) const NOEXCEPT_MAYBE
50 {
51 return error_guard<int> (ncselector_delitem (selector, item), -1);
52 }
53
54 const char* previtem () const noexcept
55 {
56 return ncselector_previtem (selector);
57 }
58
59 const char* nextitem () const noexcept
60 {
61 return ncselector_nextitem (selector);
62 }
63
64 const char* get_selected () const noexcept
65 {
66 return ncselector_selected (selector);
67 }
68
69 bool offer_input (const struct ncinput* ni) const noexcept
70 {
71 return ncselector_offer_input (selector, ni);
72 }
73
74 Plane* get_plane () const noexcept;
75
76 private:
77 void common_init (ncplane *plane, const ncselector_options *opts = nullptr)
78 {
79 if (plane == nullptr)
80 throw invalid_argument ("'plane' must be a valid pointer");
81
82 selector = ncselector_create (plane, opts == nullptr ? &default_options : opts);
83 if (selector == nullptr)
84 throw init_error ("Notcurses failed to create a new selector");
85 }
86
87 private:
88 ncselector *selector;
89 };
90}
91#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
const char * previtem() const noexcept
Definition Selector.hh:54
Selector(Plane &plane, const ncselector_options *opts=nullptr)
Definition Selector.hh:30
bool offer_input(const struct ncinput *ni) const noexcept
Definition Selector.hh:69
const char * get_selected() const noexcept
Definition Selector.hh:64
Selector(Plane *plane, const ncselector_options *opts=nullptr)
Definition Selector.hh:19
int additem(const ncselector_item *item) const NOEXCEPT_MAYBE
Definition Selector.hh:44
int delitem(const char *item) const NOEXCEPT_MAYBE
Definition Selector.hh:49
static ncselector_options default_options
Definition Selector.hh:16
Plane * get_plane() const noexcept
const char * nextitem() const noexcept
Definition Selector.hh:59
const struct ncplane_options * opts
Definition notcurses.h:3483
void ncselector_destroy(ncselector *n, char **item)
Definition selector.c:270
const char * ncselector_nextitem(ncselector *n)
Definition selector.c:500
bool ncselector_offer_input(ncselector *n, const ncinput *nc)
Definition selector.c:523
ncselector * ncselector_create(ncplane *n, const ncselector_options *opts)
Definition selector.c:280
int ncselector_delitem(ncselector *n, const char *item)
Definition selector.c:427
int ncselector_additem(ncselector *n, const struct ncselector_item *item)
Definition selector.c:392
const char * ncselector_selected(const ncselector *n)
Definition selector.c:474
const char * ncselector_previtem(ncselector *n)
Definition selector.c:481