2020-02-15 22:04:39 +00:00
|
|
|
#ifndef __NCPP_MENU_HH
|
|
|
|
#define __NCPP_MENU_HH
|
|
|
|
|
2020-02-18 17:36:16 +00:00
|
|
|
#include <notcurses/notcurses.h>
|
2020-02-15 22:04:39 +00:00
|
|
|
|
|
|
|
#include "Root.hh"
|
|
|
|
|
|
|
|
namespace ncpp
|
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
class NotCurses;
|
2020-02-15 22:04:39 +00:00
|
|
|
class Plane;
|
|
|
|
|
|
|
|
class NCPP_API_EXPORT Menu : public Root
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static ncmenu_options default_options;
|
|
|
|
|
|
|
|
public:
|
2020-05-24 12:41:18 +00:00
|
|
|
explicit Menu (const ncmenu_options *opts = nullptr, NotCurses *ncinst = nullptr)
|
|
|
|
: Root (ncinst)
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
menu = ncmenu_create (notcurses_stdplane (get_notcurses ()), opts == nullptr ? &default_options : opts);
|
2020-02-15 22:04:39 +00:00
|
|
|
if (menu == nullptr)
|
2020-05-20 04:15:38 +00:00
|
|
|
throw init_error ("Notcurses failed to create a new menu");
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~Menu ()
|
|
|
|
{
|
|
|
|
if (!is_notcurses_stopped ())
|
|
|
|
ncmenu_destroy (menu);
|
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool unroll (int sectionidx) const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_unroll (menu, sectionidx), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool rollup () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_rollup (menu), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool nextsection () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_nextsection (menu), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool prevsection () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_prevsection (menu), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool nextitem () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_nextitem (menu), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 21:09:03 +00:00
|
|
|
bool previtem () const NOEXCEPT_MAYBE
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-04-12 21:09:03 +00:00
|
|
|
return error_guard (ncmenu_previtem (menu), -1);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* get_selected (ncinput *ni = nullptr) const noexcept
|
|
|
|
{
|
|
|
|
return ncmenu_selected (menu, ni);
|
|
|
|
}
|
|
|
|
|
2020-05-24 12:41:18 +00:00
|
|
|
bool offer_input (const struct ncinput* ni) const noexcept
|
2020-02-15 22:04:39 +00:00
|
|
|
{
|
2020-05-24 12:41:18 +00:00
|
|
|
return ncmenu_offer_input (menu, ni);
|
2020-02-15 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Plane* get_plane () const noexcept;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ncmenu *menu;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|