-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlist.cpp
More file actions
54 lines (48 loc) · 1.27 KB
/
list.cpp
File metadata and controls
54 lines (48 loc) · 1.27 KB
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
#include "../single_include/tui/tui.hpp"
int main() {
// Construct window
tui::Window window;
window.set_title("List Example");
tui::List l;
l.title = "List";
l.rows = {
"[0] This",
"[1] is",
"[2] a",
"[3] list.",
"[4] This line is longer than the other rows.",
"[5] You can control lists!",
"[6] Hello, World!",
"[8] Foo",
"[9] Bar",
"[10] Last element"
};
l.text_style.foreground = tui::YELLOW;
l.set_dimensions(0, 0, 25, 8);
bool quit = false;
tui::Event event;
while(!quit) {
if(window.poll_event(event)) {
if(event.type == tui::KEYDOWN) {
switch(event.key) {
case 'q':
quit = true;
break;
case 'j':
l.scroll_down(window);
break;
case 'k':
l.scroll_up(window);
break;
}
}
}
// Add list widget to the window
// in the while loop to update
// the list for any changes.
window.add(l);
window.render();
}
window.close();
return 0;
}