-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.v
95 lines (76 loc) · 1.6 KB
/
menu.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
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
93
94
95
// Copyright (c) 2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license
// that can be found in the LICENSE file.
module ui
import gx
const (
menu_height = 30
menu_color=gx.rgb(240, 240, 240)
menu_border_color=gx.rgb(223,223,223)
)
pub struct Menu {
mut:
text string
parent ILayouter
x int
y int
ui &UI
items []MenuItem
visible bool
}
pub struct MenuConfig {
text string
items []MenuItem
}
pub type MenuFn fn()
pub struct MenuItem {
text string
action MenuFn
}
fn (m mut Menu)init(parent ILayouter) {
ui := parent.get_ui()
m.ui = ui
}
pub fn menu(c MenuConfig) &Menu {
return &Menu {
text: c.text
items: c.items
}
}
fn (b mut Menu) set_pos(x, y int) {
b.x = x
b.y = y
}
fn (b mut Menu) size() (int, int) {
return 0, 0
}
fn (b mut Menu) propose_size(w, h int) (int, int) {
//b.width = w
//b.height = h
return 0,0
}
fn (m mut Menu) draw() {
if !m.visible {
return
}
gg := m.ui.gg
gg.draw_rect(m.x, m.y, 150, m.items.len * menu_height, menu_color)
gg.draw_empty_rect(m.x, m.y, 150, m.items.len * menu_height, menu_border_color)
for i, item in m.items {
m.ui.ft.draw_text_def(m.x + 10, m.y + i * menu_height +10, item.text)
}
}
pub fn (m mut Menu) add_item(text string, action MenuFn) {
m.items << MenuItem{text:text, action: action}
}
fn (t &Menu) focus() {}
fn (t &Menu) is_focused() bool {
return false
}
fn (t &Menu) unfocus() {}
fn (t &Menu) point_inside(x, y f64) bool {
return false // x >= t.x && x <= t.x + t.width && y >= t.y && y <= t.y + t.height
}
pub fn (l mut Menu) set_text(s string) {
l.text = s
}