Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
Reel.hh
Go to the documentation of this file.
1#ifndef __NCPP_REEL_HH
2#define __NCPP_REEL_HH
3
4#include <memory>
6
7#include "Tablet.hh"
8#include "Plane.hh"
9#include "Utilities.hh"
10#include "Widget.hh"
11
12namespace ncpp
13{
15 {
16 public:
18
19 explicit NcReel (Plane &plane, const ncreel_options *popts = nullptr)
20 : Widget (Utilities::get_notcurses_cpp (plane))
21 {
22 ensure_valid_plane (plane);
23 common_init (Utilities::to_ncplane (plane), popts);
24 take_plane_ownership (plane);
25 }
26
27 explicit NcReel (Plane *plane, const ncreel_options *popts = nullptr)
28 : Widget (Utilities::get_notcurses_cpp (plane))
29 {
30 if (plane == nullptr)
31 throw invalid_argument ("'plane' must be a valid pointer");
32
33 ensure_valid_plane (plane);
34 common_init (Utilities::to_ncplane (plane), popts);
35 take_plane_ownership (plane);
36 }
37
39 {
40 if (!is_notcurses_stopped ())
41 ncreel_destroy (reel);
42 }
43
44 operator ncreel* () const noexcept
45 {
46 return reel;
47 }
48
49 operator ncreel const* () const noexcept
50 {
51 return reel;
52 }
53
54 // TODO: add an overload using callback that takes NcTablet instance instead of struct tablet
55 NcTablet* add (NcTablet *after, NcTablet *before, tabletcb cb, void *opaque = nullptr) const
56 {
57 nctablet *t = ncreel_add (reel, get_tablet (after), get_tablet (before), cb, opaque);
58 if (t == nullptr)
59 throw init_error ("Notcurses failed to create a new tablet");
60
61 return NcTablet::map_tablet (t, get_notcurses_cpp ());
62 }
63
64 NcTablet* add (NcTablet &after, NcTablet &before, tabletcb cb, void *opaque = nullptr) const noexcept
65 {
66 return add (&after, &before, cb, opaque);
67 }
68
69 int get_tabletcount () const noexcept
70 {
71 return ncreel_tabletcount (reel);
72 }
73
74 bool del (NcTablet *t) const NOEXCEPT_MAYBE
75 {
76 return error_guard (ncreel_del (reel, get_tablet (t)), -1);
77 }
78
79 bool del (NcTablet &t) const NOEXCEPT_MAYBE
80 {
81 return del (&t);
82 }
83
84 bool redraw () const NOEXCEPT_MAYBE
85 {
86 return error_guard (ncreel_redraw (reel), -1);
87 }
88
89 NcTablet* get_focused () const noexcept
90 {
91 nctablet *t = ncreel_focused (reel);
92 if (t == nullptr)
93 return nullptr;
94
95 return NcTablet::map_tablet (t, get_notcurses_cpp ());
96 }
97
98 NcTablet* next () const noexcept
99 {
100 nctablet *t = ncreel_next (reel);
101 if (t == nullptr)
102 return nullptr;
103
104 return NcTablet::map_tablet (t, get_notcurses_cpp ());
105 }
106
107 NcTablet* prev () const noexcept
108 {
109 nctablet *t = ncreel_prev (reel);
110 if (t == nullptr)
111 return nullptr;
112
113 return NcTablet::map_tablet (t, get_notcurses_cpp ());
114 }
115
116 bool offer_input (const struct ncinput* nci) const NOEXCEPT_MAYBE
117 {
118 return error_guard<bool, bool> (ncreel_offer_input (reel, nci), false);
119 }
120
121 Plane* get_plane () const noexcept;
122
123 private:
124 nctablet* get_tablet (NcTablet *t) const noexcept
125 {
126 if (t == nullptr)
127 return nullptr;
128
129 return t->get_tablet ();
130 }
131
132 void common_init (ncplane *plane, const ncreel_options *popts = nullptr)
133 {
134 reel = ncreel_create (plane, popts == nullptr ? &default_options : popts);
135 if (reel == nullptr)
136 throw init_error ("Notcurses failed to create a new ncreel");
137 }
138
139 private:
140 ncreel *reel = nullptr;
141
142 friend class Plane;
143 };
144}
145#endif
#define NCPP_API_EXPORT
Definition _helpers.hh:9
#define NOEXCEPT_MAYBE
Definition Root.hh:15
NcTablet * add(NcTablet *after, NcTablet *before, tabletcb cb, void *opaque=nullptr) const
Definition Reel.hh:55
bool del(NcTablet *t) const NOEXCEPT_MAYBE
Definition Reel.hh:74
bool del(NcTablet &t) const NOEXCEPT_MAYBE
Definition Reel.hh:79
static ncreel_options default_options
Definition Reel.hh:17
NcReel(Plane &plane, const ncreel_options *popts=nullptr)
Definition Reel.hh:19
bool offer_input(const struct ncinput *nci) const NOEXCEPT_MAYBE
Definition Reel.hh:116
NcReel(Plane *plane, const ncreel_options *popts=nullptr)
Definition Reel.hh:27
bool redraw() const NOEXCEPT_MAYBE
Definition Reel.hh:84
int get_tabletcount() const noexcept
Definition Reel.hh:69
NcTablet * add(NcTablet &after, NcTablet &before, tabletcb cb, void *opaque=nullptr) const noexcept
Definition Reel.hh:64
NcTablet * get_focused() const noexcept
Definition Reel.hh:89
Plane * get_plane() const noexcept
NcTablet * prev() const noexcept
Definition Reel.hh:107
NcTablet * next() const noexcept
Definition Reel.hh:98
int(* tabletcb)(struct nctablet *t, bool drawfromtop)
Definition notcurses.h:3728
nctablet * ncreel_focused(ncreel *nr)
Definition reel.c:901
int ncreel_del(ncreel *nr, struct nctablet *t)
Definition reel.c:285
bool ncreel_offer_input(ncreel *n, const ncinput *nc)
Definition reel.c:925
void ncreel_destroy(ncreel *nreel)
Definition reel.c:880
int ncreel_redraw(ncreel *nr)
Definition reel.c:677
nctablet * ncreel_prev(ncreel *nr)
Definition reel.c:915
ncreel * ncreel_create(ncplane *n, const ncreel_options *ropts)
Definition reel.c:807
nctablet * ncreel_next(ncreel *nr)
Definition reel.c:905
int ncreel_tabletcount(const ncreel *nreel)
Definition reel.c:897
nctablet * ncreel_add(ncreel *nr, nctablet *after, nctablet *before, tabletcb cbfxn, void *opaque)
Definition reel.c:838