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"
|
2020-05-07 19:06:07 +00:00
|
|
|
#include "NotCurses.hh"
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
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 00:58:00 +00:00
|
|
|
explicit Selector (NotCurses *nc, int y, int x, const ncselector_options *opts = nullptr)
|
2020-05-07 19:06:07 +00:00
|
|
|
: Selector (reinterpret_cast<notcurses*>(nc), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 00:58:00 +00:00
|
|
|
explicit Selector (NotCurses const* nc, int y, int x, const ncselector_options *opts = nullptr)
|
2020-05-07 19:06:07 +00:00
|
|
|
: Selector (const_cast<NotCurses*>(nc), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 00:58:00 +00:00
|
|
|
explicit Selector (NotCurses &nc, int y, int x, const ncselector_options *opts = nullptr)
|
2020-05-07 19:06:07 +00:00
|
|
|
: Selector (reinterpret_cast<NotCurses*>(&nc), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 00:58:00 +00:00
|
|
|
explicit Selector (NotCurses const& nc, int y, int x, const ncselector_options *opts = nullptr)
|
2020-05-07 19:06:07 +00:00
|
|
|
: Selector (const_cast<NotCurses*>(&nc), y, x, opts)
|
2020-02-15 22:04:39 +00:00
|
|
|
{}
|
|
|
|
|
2020-05-09 00:58:00 +00:00
|
|
|
explicit Selector (notcurses* nc, int y, int x, const ncselector_options *opts = nullptr)
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-05-07 19:06:07 +00:00
|
|
|
selector = ncselector_create (nc, 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
|