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:
|
|
|
|
static selector_options default_options;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Selector (Plane *plane, int y, int x, const selector_options *opts = nullptr)
|
|
|
|
: Selector (reinterpret_cast<ncplane*>(plane), y, x, opts)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Selector (Plane const* plane, int y, int x, const selector_options *opts = nullptr)
|
|
|
|
: Selector (const_cast<Plane*>(plane), y, x, opts)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Selector (Plane &plane, int y, int x, const selector_options *opts = nullptr)
|
|
|
|
: Selector (reinterpret_cast<ncplane*>(&plane), y, x, opts)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Selector (Plane const& plane, int y, int x, const selector_options *opts = nullptr)
|
|
|
|
: Selector (const_cast<Plane*>(&plane), y, x, opts)
|
|
|
|
{}
|
|
|
|
|
|
|
|
explicit Selector (ncplane *plane, int y, int x, const selector_options *opts = nullptr)
|
|
|
|
{
|
|
|
|
if (plane == nullptr)
|
2020-02-16 19:25:26 +00:00
|
|
|
throw invalid_argument ("'plane' must be a valid pointer");
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
selector = ncselector_create (plane, y, x, opts == nullptr ? &default_options : opts);
|
|
|
|
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-04-12 21:09:03 +00:00
|
|
|
int additem (const selector_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
|