-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathinterface_focusable.v
More file actions
109 lines (101 loc) · 2.26 KB
/
interface_focusable.v
File metadata and controls
109 lines (101 loc) · 2.26 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
pub interface Focusable {
ui &UI
mut:
id string
hidden bool
is_focused bool
focus()
unfocus()
}
// TODO: documentation
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() {
mut w := f.ui.window
if !w.unlocked_focus() {
return
}
if f.is_focused {
if mut w.ui.dd is DrawDeviceContext {
$if focus ? {
println('${f.id} already has focus at ${w.ui.dd.frame}')
}
}
return
}
Layout(w).unfocus_all()
if f.has_focusable() {
f.is_focused = true
if mut w.ui.dd is DrawDeviceContext {
$if focus ? {
println('${f.id} has focus at ${w.ui.dd.frame}')
}
}
}
// update drawing_children when focus is taken
f.update_parent_drawing_children()
}
// Only one widget can have the focus inside a Window
pub fn (mut f Focusable) force_focus() {
mut w := f.ui.window
if f.is_focused {
if mut w.ui.dd is DrawDeviceContext {
$if focus ? {
println('${f.id} already has focus at ${w.ui.dd.frame}')
}
}
return
}
Layout(w).unfocus_all()
f.is_focused = true
if mut w.ui.dd is DrawDeviceContext {
$if focus ? {
println('${f.id} has focus at ${w.ui.dd.frame}')
}
}
}
// TODO: documentation
pub fn (f Focusable) lock_focus() {
mut w := f.ui.window
$if focus ? {
println('${f.id} lock focus')
}
w.locked_focus = f.id
}
// TODO: documentation
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 = ''
}
}
// TODO: documentation
pub fn (f Focusable) update_parent_drawing_children() {
if f is Widget {
w := f as Widget
mut p := w.parent
if mut p is CanvasLayout {
p.set_drawing_children()
} else if mut p is CanvasLayout {
p.set_drawing_children()
}
}
}