-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactions.go
114 lines (89 loc) · 1.91 KB
/
actions.go
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
package main
import (
"math/rand"
"slices"
"strconv"
"strings"
"gioui.org/layout"
"gioui.org/widget"
)
func deleteInSlice[S any](slice []S, idx int) []S {
if idx < 0 || idx >= len(slice) {
return slice
}
s := slice[:idx]
if idx != len(slice)-1 {
s = append(s, slice[idx+1:]...)
}
return s
}
func orderClicked() {
amount, err := strconv.Atoi(strings.TrimSpace(amountInput.Text()))
if err != nil {
amount = 0
}
if bidaskGroup.Value == "bid" {
amount = -amount
}
processOrder(orderAsset, orderPrice, amount)
amountInput.SetText("")
assetInput.SetText("")
orderAllowed = false
}
func tickerClicked() {
name := strings.TrimSpace(tickerInput.Text())
if name != "" {
myTickers = append(myTickers, ticker{
name: name,
button: widget.Clickable{},
value: 1000,
})
}
tickerInput.SetText("")
}
func chatClicked() {
prompt := strings.TrimSpace(chatInput.Text())
if chatLog.Len() > 0 {
chatLog.WriteString("\n")
}
chatLog.WriteString(prompt)
chatLog.WriteString("\n")
chatLog.WriteString(responses[rand.Intn(3)])
chatInput.SetText("")
}
var responses = []string{
"Every step you do is getting you closer to the goal",
"No pain no gain, you know?",
"You can't do it if you're not good enough",
}
func deleteClicked() {
idx := slices.IndexFunc(myTickers, func(t ticker) bool {
return t.name == orderAsset
})
if idx != -1 {
myTickers = deleteInSlice(myTickers, idx)
}
orderAsset = ""
orderAllowed = false
}
func cancelClicked() {
amountInput.SetText("")
assetInput.SetText("")
orderAsset = ""
orderAllowed = false
}
func processMyTickersButtons(gtx layout.Context) {
for i := range myTickers {
if myTickers[i].button.Clicked(gtx) {
idx := slices.IndexFunc(myTickers, func(t ticker) bool {
return t.name == myTickers[i].name
})
if idx != -1 {
orderAllowed = true
orderAsset = myTickers[i].name
orderPrice = myTickers[i].value
}
break
}
}
}