-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface_focusable.v
More file actions
83 lines (76 loc) · 1.62 KB
/
interface_focusable.v
File metadata and controls
83 lines (76 loc) · 1.62 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
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
module ui
// Contains all the methods related to focus management
// that is to say:
// * Focusable interface and its methods
// * methods for Window
// * methods for Layout interface
interface Focusable {
ui &UI
mut:
id string
hidden bool
is_focused bool
focus()
unfocus()
}
pub fn (f Focusable) has_focusable() bool {
mut focusable := true
if f is TextBox {
focusable = !f.read_only
}
$if focus ? {
println('${f.id}.has_focusable(): $focusable && ${!f.hidden} && $f.ui.window.unlocked_focus() (locked_focus=<$f.ui.window.locked_focus>)')
}
return focusable && !f.hidden && f.ui.window.unlocked_focus()
}
// Only one widget can have the focus inside a Window
pub fn (mut f Focusable) set_focus() {
w := f.ui.window
if !w.unlocked_focus() {
return
}
if f.is_focused {
$if focus ? {
println('$f.id already has focus at $w.ui.gg.frame')
}
return
}
Layout(w).unfocus_all()
if f.has_focusable() {
f.is_focused = true
$if focus ? {
println('$f.id has focus at $w.ui.gg.frame')
}
}
}
// Only one widget can have the focus inside a Window
pub fn (mut f Focusable) force_focus() {
w := f.ui.window
if f.is_focused {
$if focus ? {
println('$f.id already has focus at $w.ui.gg.frame')
}
return
}
Layout(w).unfocus_all()
f.is_focused = true
$if focus2 ? {
println('$f.id has focus at $w.ui.gg.frame')
}
}
pub fn (f Focusable) lock_focus() {
mut w := f.ui.window
$if focus ? {
println('$f.id lock focus')
}
w.locked_focus = f.id
}
pub fn (f Focusable) unlock_focus() {
mut w := f.ui.window
if w.locked_focus == f.id {
$if focus ? {
println('$f.id unlock focus')
}
w.locked_focus = ''
}
}