Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
MultiSelector.hh
Go to the documentation of this file.
1#ifndef __NCPP_MULTI_SELECTOR_HH
2#define __NCPP_MULTI_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 MultiSelector (Plane *plane, const ncmultiselector_options *opts = nullptr)
20 : Widget (Utilities::get_notcurses_cpp (plane))
21 {
22 ensure_valid_plane (plane);
23 common_init (Utilities::to_ncplane (plane), opts);
24 take_plane_ownership (plane);
25 }
26
27 explicit MultiSelector (Plane &plane, const ncmultiselector_options *opts = nullptr)
28 : Widget (Utilities::get_notcurses_cpp (plane))
29 {
30 ensure_valid_plane (plane);
31 common_init (Utilities::to_ncplane (plane), opts);
32 take_plane_ownership (plane);
33 }
34
36 {
37 if (!is_notcurses_stopped ())
38 ncmultiselector_destroy (multiselector);
39 }
40
41 bool offer_input (const struct ncinput *ni) const noexcept
42 {
43 return ncmultiselector_offer_input (multiselector, ni);
44 }
45
46 int get_selected (bool *selected, unsigned count) const NOEXCEPT_MAYBE
47 {
48 return error_guard<int> (ncmultiselector_selected (multiselector, selected, count), -1);
49 }
50
51 Plane* get_plane () const noexcept;
52
53 private:
54 void common_init (ncplane *plane, const ncmultiselector_options *opts)
55 {
56 if (plane == nullptr)
57 throw invalid_argument ("'plane' must be a valid pointer");
58
59 multiselector = ncmultiselector_create (plane, opts == nullptr ? &default_options : opts);
60 if (multiselector == nullptr)
61 throw init_error ("Notcurses failed to create a new multiselector");
62 }
63
64 private:
65 ncmultiselector *multiselector;
66 };
67}
68#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
MultiSelector(Plane &plane, const ncmultiselector_options *opts=nullptr)
bool offer_input(const struct ncinput *ni) const noexcept
int get_selected(bool *selected, unsigned count) const NOEXCEPT_MAYBE
MultiSelector(Plane *plane, const ncmultiselector_options *opts=nullptr)
static ncmultiselector_options default_options
Plane * get_plane() const noexcept
const struct ncplane_options * opts
Definition notcurses.h:3483
void ncmultiselector_destroy(ncmultiselector *n)
Definition selector.c:985
int ncmultiselector_selected(ncmultiselector *n, bool *selected, unsigned count)
Definition selector.c:1002
ncmultiselector * ncmultiselector_create(ncplane *n, const ncmultiselector_options *opts)
Definition selector.c:885
bool ncmultiselector_offer_input(ncmultiselector *n, const ncinput *nc)
Definition selector.c:785