2020-03-14 23:35:54 +00:00
|
|
|
#ifndef __NCPP_MULTI_SELECTOR_HH
|
|
|
|
#define __NCPP_MULTI_SELECTOR_HH
|
|
|
|
|
|
|
|
#include <notcurses/notcurses.h>
|
|
|
|
|
|
|
|
#include "NCAlign.hh"
|
2020-05-24 12:41:18 +00:00
|
|
|
#include "Plane.hh"
|
2020-05-22 20:11:59 +00:00
|
|
|
#include "Utilities.hh"
|
2020-09-30 21:42:42 +00:00
|
|
|
#include "Widget.hh"
|
2020-03-14 23:35:54 +00:00
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-09-30 21:42:42 +00:00
|
|
|
class NCPP_API_EXPORT MultiSelector : public Widget
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-09 00:58:00 +00:00
|
|
|
static ncmultiselector_options default_options;
|
2020-03-14 23:35:54 +00:00
|
|
|
|
|
|
|
public:
|
2020-09-13 11:51:49 +00:00
|
|
|
explicit MultiSelector (Plane *plane, const ncmultiselector_options *opts = nullptr)
|
2020-09-30 21:42:42 +00:00
|
|
|
: Widget (Utilities::get_notcurses_cpp (plane))
|
2020-05-24 12:41:18 +00:00
|
|
|
{
|
2020-09-30 21:42:42 +00:00
|
|
|
ensure_valid_plane (plane);
|
2020-09-13 11:51:49 +00:00
|
|
|
common_init (Utilities::to_ncplane (plane), opts);
|
2020-09-30 21:42:42 +00:00
|
|
|
take_plane_ownership (plane);
|
2020-05-24 12:41:18 +00:00
|
|
|
}
|
2020-03-14 23:35:54 +00:00
|
|
|
|
2020-09-13 11:51:49 +00:00
|
|
|
explicit MultiSelector (Plane &plane, const ncmultiselector_options *opts = nullptr)
|
2020-09-30 21:42:42 +00:00
|
|
|
: Widget (Utilities::get_notcurses_cpp (plane))
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-09-30 21:42:42 +00:00
|
|
|
ensure_valid_plane (plane);
|
2020-09-13 11:51:49 +00:00
|
|
|
common_init (Utilities::to_ncplane (plane), opts);
|
2020-09-30 21:42:42 +00:00
|
|
|
take_plane_ownership (plane);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~MultiSelector ()
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
2020-07-29 01:39:24 +00:00
|
|
|
ncmultiselector_destroy (multiselector);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
bool offer_input (const struct ncinput *ni) const noexcept
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
return ncmultiselector_offer_input (multiselector, ni);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
int get_selected (bool *selected, unsigned count) const NOEXCEPT_MAYBE
|
2020-03-14 23:35:54 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard<int> (ncmultiselector_selected (multiselector, selected, count), -1);
|
2020-03-14 23:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
private:
|
2020-09-13 11:51:49 +00:00
|
|
|
void common_init (ncplane *plane, const ncmultiselector_options *opts)
|
2020-05-24 12:41:18 +00:00
|
|
|
{
|
|
|
|
if (plane == nullptr)
|
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
|
2020-09-13 11:51:49 +00:00
|
|
|
multiselector = ncmultiselector_create (plane, opts == nullptr ? &default_options : opts);
|
2020-05-24 12:41:18 +00:00
|
|
|
if (multiselector == nullptr)
|
|
|
|
throw init_error ("Notcurses failed to create a new multiselector");
|
|
|
|
}
|
|
|
|
|
2020-03-14 23:35:54 +00:00
|
|
|
private:
|
|
|
|
ncmultiselector *multiselector;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|