-
Notifications
You must be signed in to change notification settings - Fork 0
/
panels-resize.vala
92 lines (73 loc) · 2.01 KB
/
panels-resize.vala
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
90
91
92
using Curses;
using Posix;
public class Demo {
public MainLoop loop;
private IOChannel io_channel;
internal IOSource io;
struct PanelSize { int width; int height; }
public Demo() {
loop = new MainLoop();
io_channel = new IOChannel.unix_new(Posix.STDIN_FILENO);
io = new IOSource(io_channel, IOCondition.IN);
io.attach(loop.get_context());
}
public void start() {
unowned Window stdscr = initscr();
noecho();
stdscr.keypad(true);
}
public void stop() {
endwin();
}
private Window window1;
private Panel panel1;
private PanelSize panel_size;
public void activate() {
panel_size = PanelSize() { width = 20, height = 5 };
this.window1 = new Window(panel_size.height, panel_size.width, 1, 1);
panel1 = new Panel(window1);
this.window1.box(0, 0);
this.window1.mvprintw(1, 1, "I am in window 1");
panel1.userptr = (void *)(&panel_size);
io.set_callback(() => {
var c = getch();
panel_size = *((PanelSize *)panel1.userptr);
switch (c) {
case Key.RIGHT: // right
++panel_size.width;
++panel_size.height;
break;
case Key.LEFT: // left
--panel_size.width;
--panel_size.height;
break;
}
Window *t = new Window(panel_size.height, panel_size.width, 1, 1);
panel1.replace(t);
t->box(0, 0);
window1.mvprintw(1, 1, "new");
window1 = (owned)t; // here happens call to delwin (for previous window1 instance), which must be after Panel.replace call
panel1.userptr = (void *)(&panel_size);
refresh(); // this is important, clears artifacts from removed windows
Panel.update_panels();
doupdate();
return Source.CONTINUE;
});
}
public void run() {
loop.run();
}
public void redraw() {
Panel.update_panels();
doupdate();
}
static int main(string[] args) {
var app = new Demo();
app.start();
app.activate();
app.redraw();
app.run();
app.stop();
return EXIT_SUCCESS;
}
}