-
Notifications
You must be signed in to change notification settings - Fork 1
/
window.v
65 lines (59 loc) · 1.48 KB
/
window.v
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
module vtui
import term
// import time
// Window is in charge of drawing the UI (and managing the layout).
struct Window {
box_characters map[string]string
mut:
child Widget
}
pub struct WindowConfig {
}
pub fn new_window(w WindowConfig, child Widget) Window {
// mut widget_list := []Widget{}
// widget_list << child
mut box_style := map[string]string{}
// '─' is 'ew' bc the ends of the line connect to the east and west sides
// The naming order is always n, s, e, then w
if true { // TODO: ask if terminal can handle these characters (or launch param)
box_style['ns'] = '│'
box_style['ew'] = '─'
box_style['ne'] = '└'
box_style['nw'] = '┘'
box_style['se'] = '┌'
box_style['sw'] = '┐'
box_style['nse'] = '├'
box_style['nsw'] = '┤'
} else {
box_style['ns'] = '|'
box_style['ew'] = '-'
box_style['ne'] = '+'
box_style['nw'] = '+'
box_style['se'] = '+'
box_style['sw'] = '+'
box_style['nse'] = '|'
box_style['nsw'] = '|'
}
return Window{
// title: w.title
child: child
box_characters: box_style
}
}
pub fn (win Window) draw(width int, height int, x_off int, y_off int) {
// println('inside win.draw')
// println(win)
// println(win.child)
rendered_child := win.child.render(width, height)
term.clear()
for w in 0 .. width {
for h in 0 .. height {
term.set_cursor_position(x: w + 1 + x_off, y: h + 1 + y_off)
print(rendered_child[h][w])
// print('F')
}
}
}
fn (win Window) to_string() string {
return 'Window[......]'
}