1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#ifndef __NCPP_MULTI_SELECTOR_HH
#define __NCPP_MULTI_SELECTOR_HH
#include <notcurses/notcurses.h>
#include "NCAlign.hh"
#include "Plane.hh"
#include "Utilities.hh"
#include "Widget.hh"
namespace ncpp
{
class NCPP_API_EXPORT MultiSelector : public Widget
{
public:
static ncmultiselector_options default_options;
public:
explicit MultiSelector (Plane *plane, const ncmultiselector_options *opts = nullptr)
: Widget (Utilities::get_notcurses_cpp (plane))
{
ensure_valid_plane (plane);
common_init (Utilities::to_ncplane (plane), opts);
take_plane_ownership (plane);
}
explicit MultiSelector (Plane &plane, const ncmultiselector_options *opts = nullptr)
: Widget (Utilities::get_notcurses_cpp (plane))
{
ensure_valid_plane (plane);
common_init (Utilities::to_ncplane (plane), opts);
take_plane_ownership (plane);
}
~MultiSelector ()
{
if (!is_notcurses_stopped ())
ncmultiselector_destroy (multiselector);
}
bool offer_input (const struct ncinput *ni) const noexcept
{
return ncmultiselector_offer_input (multiselector, ni);
}
int get_selected (bool *selected, unsigned count) const NOEXCEPT_MAYBE
{
return error_guard<int> (ncmultiselector_selected (multiselector, selected, count), -1);
}
Plane* get_plane () const noexcept;
private:
void common_init (ncplane *plane, const ncmultiselector_options *opts)
{
if (plane == nullptr)
throw invalid_argument ("'plane' must be a valid pointer");
multiselector = ncmultiselector_create (plane, opts == nullptr ? &default_options : opts);
if (multiselector == nullptr)
throw init_error ("Notcurses failed to create a new multiselector");
}
private:
ncmultiselector *multiselector;
};
}
#endif
|