File libs/cursed/Prompt.cpp copied from file libs/cursed/Label.cpp (similarity 82%) (mode: 100644) (index 8fd6496..bf9a9b0) |
16 |
16 |
// You should have received a copy of the GNU General Public License |
// You should have received a copy of the GNU General Public License |
17 |
17 |
// along with libcursed. If not, see <https://www.gnu.org/licenses/>. |
// along with libcursed. If not, see <https://www.gnu.org/licenses/>. |
18 |
18 |
|
|
19 |
|
#include "Label.hpp" |
|
|
19 |
|
#include "Prompt.hpp" |
20 |
20 |
|
|
21 |
21 |
#include <string> |
#include <string> |
22 |
22 |
#include <utility> |
#include <utility> |
23 |
23 |
|
|
24 |
24 |
using namespace cursed; |
using namespace cursed; |
25 |
25 |
|
|
26 |
|
Label::Label(std::wstring initText) : text(std::move(initText)) |
|
|
26 |
|
Prompt::Prompt() : pos(text.size()) |
27 |
27 |
{ } |
{ } |
28 |
28 |
|
|
29 |
29 |
void |
void |
30 |
|
Label::setText(std::wstring newText) |
|
|
30 |
|
Prompt::setText(std::wstring newText, int newPos) |
31 |
31 |
{ |
{ |
32 |
32 |
text = std::move(newText); |
text = std::move(newText); |
|
33 |
|
pos = newPos; |
33 |
34 |
} |
} |
34 |
35 |
|
|
35 |
36 |
void |
void |
36 |
|
Label::draw() |
|
|
37 |
|
Prompt::draw() |
37 |
38 |
{ |
{ |
38 |
39 |
werase(win); |
werase(win); |
39 |
40 |
mvwprintw(win, 0, 0, "%ls", text.c_str()); |
mvwprintw(win, 0, 0, "%ls", text.c_str()); |
|
41 |
|
wmove(win, 0, pos); |
40 |
42 |
wnoutrefresh(win); |
wnoutrefresh(win); |
41 |
43 |
} |
} |
42 |
44 |
|
|
43 |
45 |
int |
int |
44 |
|
Label::desiredHeight() |
|
|
46 |
|
Prompt::desiredHeight() |
45 |
47 |
{ |
{ |
46 |
48 |
return 1; |
return 1; |
47 |
49 |
} |
} |
48 |
50 |
|
|
49 |
51 |
void |
void |
50 |
|
Label::placed(Pos newPos, Size newSize) |
|
|
52 |
|
Prompt::placed(Pos newPos, Size newSize) |
51 |
53 |
{ |
{ |
52 |
54 |
win.place(newPos, newSize); |
win.place(newPos, newSize); |
53 |
55 |
} |
} |
File libs/cursed/Prompt.hpp copied from file libs/cursed/Label.hpp (similarity 68%) (mode: 100644) (index fd87751..326b52d) |
16 |
16 |
// You should have received a copy of the GNU General Public License |
// You should have received a copy of the GNU General Public License |
17 |
17 |
// along with libcursed. If not, see <https://www.gnu.org/licenses/>. |
// along with libcursed. If not, see <https://www.gnu.org/licenses/>. |
18 |
18 |
|
|
19 |
|
#ifndef LIBCURSED__LABEL_HPP__ |
|
20 |
|
#define LIBCURSED__LABEL_HPP__ |
|
|
19 |
|
#ifndef LIBCURSED__PROMPT_HPP__ |
|
20 |
|
#define LIBCURSED__PROMPT_HPP__ |
21 |
21 |
|
|
22 |
22 |
#include <string> |
#include <string> |
23 |
23 |
|
|
|
26 |
26 |
|
|
27 |
27 |
namespace cursed { |
namespace cursed { |
28 |
28 |
|
|
29 |
|
// Static text field. |
|
30 |
|
class Label : public Widget |
|
|
29 |
|
// Prompt for requesting input. |
|
30 |
|
class Prompt : public Widget |
31 |
31 |
{ |
{ |
32 |
32 |
public: |
public: |
33 |
|
// Constructs a label. Can throw `std::runtime_error`. |
|
34 |
|
explicit Label(std::wstring initText = {}); |
|
|
33 |
|
// Constructs a prompt. Can throw `std::runtime_error`. |
|
34 |
|
explicit Prompt(); |
35 |
35 |
|
|
36 |
|
Label(const Label &rhs) = delete; |
|
37 |
|
Label(Label &&rhs) = delete; |
|
38 |
|
Label & operator=(const Label &rhs) = delete; |
|
39 |
|
Label & operator=(Label &&rhs) = delete; |
|
|
36 |
|
Prompt(const Prompt &rhs) = delete; |
|
37 |
|
Prompt(Prompt &&rhs) = delete; |
|
38 |
|
Prompt & operator=(const Prompt &rhs) = delete; |
|
39 |
|
Prompt & operator=(Prompt &&rhs) = delete; |
40 |
40 |
|
|
41 |
41 |
public: |
public: |
42 |
|
// Updates text of the label. |
|
43 |
|
void setText(std::wstring newText); |
|
|
42 |
|
// Updates text and cursor position of the prompt. |
|
43 |
|
void setText(std::wstring newText, int newPos); |
44 |
44 |
|
|
45 |
45 |
// Updates state of this widget to be published on the screen. |
// Updates state of this widget to be published on the screen. |
46 |
46 |
virtual void draw() override; |
virtual void draw() override; |
|
... |
... |
private: |
56 |
56 |
|
|
57 |
57 |
private: |
private: |
58 |
58 |
guts::Window win; // Window object. |
guts::Window win; // Window object. |
59 |
|
std::wstring text; // Text of the label. |
|
|
59 |
|
std::wstring text; // Text of the lprompt. |
|
60 |
|
int pos; // Cursor position. |
60 |
61 |
}; |
}; |
61 |
62 |
|
|
62 |
63 |
} |
} |
63 |
64 |
|
|
64 |
|
#endif // LIBCURSED__LABEL_HPP__ |
|
|
65 |
|
#endif // LIBCURSED__PROMPT_HPP__ |
File libs/cursed/Window.cpp changed (mode: 100644) (index 24a8025..549af5f) |
... |
... |
void |
71 |
71 |
wnoutrefresh(w(win.raw())); |
wnoutrefresh(w(win.raw())); |
72 |
72 |
} |
} |
73 |
73 |
|
|
|
74 |
|
void |
|
75 |
|
(guts::wtimeout)(Window &win, int delay) |
|
76 |
|
{ |
|
77 |
|
wtimeout(w(win.raw()), delay); |
|
78 |
|
} |
|
79 |
|
|
|
80 |
|
int |
|
81 |
|
(guts::wget_wch)(Window &win, std::wint_t *wch) |
|
82 |
|
{ |
|
83 |
|
return wget_wch(w(win.raw()), wch); |
|
84 |
|
} |
|
85 |
|
|
74 |
86 |
void |
void |
75 |
87 |
(guts::wattron)(Window &win, Attribs attrs) |
(guts::wattron)(Window &win, Attribs attrs) |
76 |
88 |
{ |
{ |
File libs/cursed/Window.hpp changed (mode: 100644) (index f781dce..e530a9e) |
19 |
19 |
#ifndef LIBCURSED__WINDOW_HPP__ |
#ifndef LIBCURSED__WINDOW_HPP__ |
20 |
20 |
#define LIBCURSED__WINDOW_HPP__ |
#define LIBCURSED__WINDOW_HPP__ |
21 |
21 |
|
|
|
22 |
|
#include <cwctype> |
|
23 |
|
|
22 |
24 |
namespace cursed { |
namespace cursed { |
23 |
25 |
|
|
24 |
26 |
class Pos; |
class Pos; |
|
... |
... |
void (werase)(Window &win); |
63 |
65 |
// Publishes changes to be displayed on the next screen update. |
// Publishes changes to be displayed on the next screen update. |
64 |
66 |
void (wnoutrefresh)(Window &win); |
void (wnoutrefresh)(Window &win); |
65 |
67 |
|
|
|
68 |
|
// Sets time to wait for input on a window (negative means block). |
|
69 |
|
void (wtimeout)(Window &win, int delay); |
|
70 |
|
// Reads input on a window. |
|
71 |
|
int (wget_wch)(Window &win, std::wint_t *wch); |
|
72 |
|
|
66 |
73 |
// Enables an attribute. |
// Enables an attribute. |
67 |
74 |
void (wattron)(Window &win, Attribs attrs); |
void (wattron)(Window &win, Attribs attrs); |
68 |
75 |
// Disables an attribute. |
// Disables an attribute. |