File: Menu.hh

package info (click to toggle)
notcurses 3.0.17%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,780 kB
  • sloc: ansic: 50,375; cpp: 17,808; python: 1,123; sh: 230; makefile: 35
file content (89 lines) | stat: -rw-r--r-- 1,928 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef __NCPP_MENU_HH
#define __NCPP_MENU_HH

#include <notcurses/notcurses.h>

#include "Root.hh"

namespace ncpp
{
	class NotCurses;
	class Plane;

	class NCPP_API_EXPORT Menu : public Root
	{
	public:
		static ncmenu_options default_options;

	public:
		explicit Menu (const ncmenu_options *opts = nullptr, NotCurses *ncinst = nullptr)
			: Root (ncinst)
		{
			menu = ncmenu_create (notcurses_stdplane (get_notcurses ()), opts == nullptr ? &default_options : opts);
			if (menu == nullptr)
				throw init_error ("Notcurses failed to create a new menu");
		}

		~Menu ()
		{
			if (!is_notcurses_stopped ())
				ncmenu_destroy (menu);
		}

		bool unroll (int sectionidx) const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_unroll (menu, sectionidx), -1);
		}

		bool rollup () const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_rollup (menu), -1);
		}

		bool nextsection () const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_nextsection (menu), -1);
		}

		bool prevsection () const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_prevsection (menu), -1);
		}

		bool nextitem () const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_nextitem (menu), -1);
		}

		bool previtem () const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_previtem (menu), -1);
		}

		bool item_set_status (const char* section, const char* item, bool status) const NOEXCEPT_MAYBE
		{
			return error_guard (ncmenu_item_set_status (menu, section, item, status), -1);
		}

		const char* get_selected (ncinput *ni = nullptr) const noexcept
		{
			return ncmenu_selected (menu, ni);
		}

		const char* get_mouse_selected (const struct ncinput* click, struct ncinput* ni) const noexcept
		{
			return ncmenu_mouse_selected (menu, click, ni);
		}

		bool offer_input (const struct ncinput* ni) const noexcept
		{
			return ncmenu_offer_input (menu, ni);
		}

		Plane* get_plane () const noexcept;

	private:
		ncmenu *menu;
	};
}
#endif