2020-02-15 22:04:39 +00:00
|
|
|
#ifndef __NCPP_SELECTOR_HH
|
|
|
|
#define __NCPP_SELECTOR_HH
|
|
|
|
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
#include "NCAlign.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
|
|
|
class Plane;
|
|
|
|
|
|
|
|
class NCPP_API_EXPORT Selector : public Root
|
|
|
|
{
|
|
|
|
public:
|
2020-05-09 00:58:00 +00:00
|
|
|
static ncselector_options default_options;
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
public:
|
2020-05-09 11:51:23 +00:00
|
|
|
explicit Selector (Plane *plane, int y, int x, const ncselector_options *opts = nullptr)
|
|
|
|
: Selector (reinterpret_cast<ncplane*>(plane), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 11:51:23 +00:00
|
|
|
explicit Selector (Plane const* plane, int y, int x, const ncselector_options *opts = nullptr)
|
|
|
|
: Selector (const_cast<Plane*>(plane), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 11:51:23 +00:00
|
|
|
explicit Selector (Plane &plane, int y, int x, const ncselector_options *opts = nullptr)
|
|
|
|
: Selector (reinterpret_cast<ncplane*>(&plane), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 11:51:23 +00:00
|
|
|
explicit Selector (Plane const& plane, int y, int x, const ncselector_options *opts = nullptr)
|
|
|
|
: Selector (const_cast<Plane*>(&plane), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 11:51:23 +00:00
|
|
|
explicit Selector (ncplane *plane, int y, int x, const ncselector_options *opts = nullptr)
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-05-09 11:51:23 +00:00
|
|
|
if (plane == nullptr)
|
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
|
|
|
|
|
|
|
selector = ncselector_create (plane, y, x, opts == nullptr ? &default_options : opts);
|
2020-02-15 22:04:39 +00:00
|
|
|
if (selector == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw init_error ("notcurses failed to create a new selector");
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Selector ()
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
|
|
|
ncselector_destroy (selector, nullptr);
|
|
|
|
}
|
|
|
|
|
2020-05-09 00:58:00 +00:00
|
|
|
int additem (const ncselector_item *item) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard<int> (ncselector_additem (selector, item), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
int delitem (const char *item) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard<int> (ncselector_delitem (selector, item), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* previtem () const noexcept
|
|
|
|
{
|
|
|
|
return ncselector_previtem (selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* nextitem () const noexcept
|
|
|
|
{
|
|
|
|
return ncselector_nextitem (selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_selected () const noexcept
|
|
|
|
{
|
|
|
|
return ncselector_selected (selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool offer_input (const struct ncinput* nc) const noexcept
|
|
|
|
{
|
|
|
|
return ncselector_offer_input (selector, nc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ncselector *selector;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|