-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.js
84 lines (73 loc) · 1.96 KB
/
example.js
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
const libui = require('.');
const {Window, MultilineEntry, Box} = libui;
libui.onShouldQuit(() => {
App.stop();
global.gc();
});
function createWindow() {
let win = Window.create('Test Window', 800, 600, false);
Window.setMargined(win, true);
const logEntry = MultilineEntry.create();
const entry = MultilineEntry.create();
MultilineEntry.setText(entry, 'A test line\n');
MultilineEntry.append(entry, 'A second test line\n');
MultilineEntry.onChanged(entry, () => {
const msg = `Text changed to ${MultilineEntry.getText(entry)}`;
console.log(msg);
MultilineEntry.append(logEntry, msg + '\n');
});
const box = Box.createHorizontal();
Box.setPadded(box, true);
Box.append(box, entry, true);
Box.append(box, logEntry, true);
Window.setChild(win, box);
Window.onContentSizeChanged(win, () => {
const size = Window.getContentSize(win);
console.log(`size changed to ${size.width}x${size.height}`);
});
let step = 0;
Window.onClosing(win, () => {
if (Window.getTitle(win) == 'Test Window') {
let interval = setInterval(() => {
if (step === 0) {
Window.setContentSize(win, 400, 300);
}
if (step === 1) {
Window.setMargined(win, true);
}
if (step === 2) {
Window.setMargined(win, false);
Window.setFullscreen(win, true);
}
if (step === 3) {
Window.setFullscreen(win, false);
Window.setBorderless(win, true);
}
if (step === 4) {
Window.setBorderless(win, false);
}
if (step > 4) {
clearInterval(interval);
}
step++;
console.log({
Margined: Window.getMargined(win),
Fullscreen: Window.getFullscreen(win),
Borderless: Window.getBorderless(win),
});
}, 1000);
Box.deleteAt(box, 1);
return Window.setTitle(win, 'Wait some seconds please...');
}
console.log('closing', Window.getTitle(win));
Window.close(win);
win = null;
App.stop();
});
Window.show(win);
}
createWindow();
libui.startLoop();
setInterval(() => {
global.gc();
}, 10);