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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/widget"
)
func mouseUp(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition()
// useful to debug everything that is being clicked on
/*
for _, tk := range findByXY(w, h) {
tk.dumpWidget("mouseUp()")
}
*/
me.globalMouseDown = false
me.currentDrag = nil
dropdownUnclicked(w, h)
return nil
}
// this is where you have to figure out what
// widget was underneath so you can active
// the right response for the toolkit user's app
func mouseDown(g *gocui.Gui, v *gocui.View) error {
me.globalMouseDown = true
w, h := g.MousePosition()
me.downW = w
me.downH = h
// if the dropdown is active, never do anything else
if me.dropdown.active {
log.Info("mouseDown() stopping here. dropdwon menu is in effect")
for _, tk := range findByXY(w, h) {
if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) {
log.Info("SENDING CLICK TO Flag (dropdown)")
tk.doWidgetClick(w, h)
me.dropdown.active = false
return nil
}
}
log.Info("never found dropdown at", w, h)
return nil
}
// if the textbox is active, never do anything else
if me.textbox.active {
log.Info("mouseDown() stopping here. textbox widget is open")
for _, tk := range findByXY(w, h) {
if (tk.node.WidgetType == widget.Flag) && (tk == me.textbox.tk) {
me.textbox.active = false
tk.textboxClosed()
return nil
}
}
log.Info("never found textbox at", w, h)
return nil
}
// figre out what window this is
tk := findWindowUnderMouse()
if tk == nil {
log.Info("mouseDown() nothing to click on at", w, h)
return nil
}
tk.makeWindowActive()
// log.Info("SENDING mouseDown() to findWindowUnderMouse()")
if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget
for _, tk := range tk.findByXYreal(w, h) {
// tk.dumpWidget("mouseDown()")
if tk.node.WidgetType == widget.Button {
log.Info("SENDING CLICK TO Button")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Checkbox {
log.Info("SENDING CLICK TO Checkbox")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Dropdown {
log.Info("SENDING CLICK TO Dropdown")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Textbox {
log.Info("SENDING CLICK TO Textbox")
tk.doWidgetClick(w, h)
return nil
}
}
}
if tk.node.WidgetType == widget.Stdout {
tk.dumpWidget("stdout fixme drag()" + tk.labelN)
me.currentDrag = tk
tk.dragW = w - tk.gocuiSize.w0
tk.dragH = h - tk.gocuiSize.h0
// tk.doWidgetClick(w-tk.dragW, w-tk.dragH)
return nil
}
tk.dumpWidget("mouse drag()" + tk.labelN)
me.currentDrag = tk
tk.dragW = w - tk.gocuiSize.w0
tk.dragH = h - tk.gocuiSize.h0
// tk.doWidgetClick(w-tk.dragW, w-tk.dragH)
return nil
// move the msg I guess
// return msgDown(g, v)
// return nil
}
// this needs to go
// event triggers when you push down on a mouse button
func msgDown(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition()
for _, tk := range findByXY(w, h) {
tk.dumpWidget("msgDown()")
}
vx, vy, _, _, err := g.ViewPosition("msg")
if err == nil {
me.stdout.mouseOffsetW = w - vx
me.stdout.mouseOffsetH = h - vy
}
// did the user click in the corner of the stdout window? If so, resize the window.
cornerW := w - vx
cornerH := h - vy
if (me.stdout.w-cornerW < 4) && (me.stdout.h-cornerH < 4) {
log.Info("Resize msg", cornerW, cornerH)
me.stdout.resize = true
} else {
log.Info("not Resize msg", cornerW, cornerH)
me.stdout.resize = false
}
log.Info("setting mousedown to true for msg")
// msgMouseDown = true
return nil
}
|