-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwidget.go
201 lines (179 loc) · 6.44 KB
/
mainwidget.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package main
import (
"image/color"
"strings"
"gioui.org/font"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"gioui.org/x/component"
)
var (
amountInput = widget.Editor{SingleLine: true, Submit: true}
assetInput = widget.Editor{SingleLine: true, Submit: true}
tickerInput = widget.Editor{SingleLine: true, Submit: true}
chatInput = widget.Editor{SingleLine: true, Submit: true}
chatLog = new(strings.Builder)
orderButton = new(widget.Clickable)
deleteButton = new(widget.Clickable)
cancelButton = new(widget.Clickable)
tickerButton = new(widget.Clickable)
geminiButton = new(widget.Clickable)
bidaskGroup = new(widget.Enum)
orderAllowed = false
adviseEditor widget.Editor
list = &widget.List{
List: layout.List{
Axis: layout.Vertical,
},
}
greenColor = color.NRGBA{A: 0xff, R: 0x92, G: 0xdf, B: 0x70}
redColor = color.NRGBA{A: 0xff, R: 0xf9, G: 0x8d, B: 0x7f}
grayColor = color.NRGBA{A: 0xff, R: 0xcb, G: 0xcd, B: 0xcf}
blackColor = color.NRGBA{A: 0xff, R: 0x00, G: 0x00, B: 0x00}
bgColor = color.NRGBA{R: 0x43, G: 0x54, B: 0x6A, A: 0xff}
in = layout.UniformInset(unit.Dp(8))
border = widget.Border{Color: color.NRGBA{A: 0xff}, CornerRadius: unit.Dp(8), Width: unit.Dp(2)}
orderAsset string
orderPrice int
assetsGrid component.GridState
tickersGrid component.GridState
cellSize = unit.Dp(70)
)
const (
gridX = 4
gridY = 6
)
func drawTopScreen(gtx layout.Context, th *material.Theme) layout.Dimensions {
if orderButton.Clicked(gtx) {
orderClicked()
}
if tickerButton.Clicked(gtx) {
tickerClicked()
}
if deleteButton.Clicked(gtx) {
deleteClicked()
}
if cancelButton.Clicked(gtx) {
cancelClicked()
}
if geminiButton.Clicked(gtx) {
chatClicked()
}
processMyTickersButtons(gtx)
widgets := []layout.Widget{
func(gtx layout.Context) layout.Dimensions {
return layout.Flex{
Axis: layout.Vertical,
Alignment: layout.Middle,
Spacing: layout.SpaceAround}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
if !orderAllowed {
gtx = gtx.Disabled()
}
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return material.Button(th, orderButton, "make order").Layout(gtx)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return material.Button(th, deleteButton, "delete ticker").Layout(gtx)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return material.Button(th, cancelButton, "cancel").Layout(gtx)
})
}),
)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Spacing: layout.SpaceAround, Alignment: layout.Middle}.
Layout(gtx,
layout.Flexed(10, material.RadioButton(th, bidaskGroup, "bid", "bid").Layout),
layout.Flexed(10, material.RadioButton(th, bidaskGroup, "ask", "ask").Layout),
layout.Flexed(10, func(gtx layout.Context) layout.Dimensions {
l := material.Label(th, 18, orderAsset)
l.Alignment = text.Alignment(layout.Middle)
return l.Layout(gtx)
}),
layout.Flexed(10, func(gtx layout.Context) layout.Dimensions {
e := material.Editor(th, &amountInput, "amount")
e.Font.Style = font.Italic
border := widget.Border{Color: color.NRGBA{A: 0xff}, CornerRadius: unit.Dp(8), Width: unit.Dp(2)}
return border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.UniformInset(unit.Dp(8)).Layout(gtx, e.Layout)
})
}),
)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return material.Button(th, tickerButton, "add ticker").Layout(gtx)
})
}),
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return in.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Flex{Alignment: layout.Alignment(layout.SpaceEvenly)}.
Layout(gtx,
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
e := material.Editor(th, &tickerInput, "ticker")
e.Font.Style = font.Italic
border := widget.Border{Color: color.NRGBA{A: 0xff}, CornerRadius: unit.Dp(8), Width: unit.Dp(2)}
return border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.UniformInset(unit.Dp(8)).Layout(gtx, e.Layout)
})
}),
)
})
}),
)
})
}),
)
},
func(gtx layout.Context) layout.Dimensions {
return material.Label(th, 24, "your watch list").Layout(gtx)
},
func(gtx layout.Context) layout.Dimensions {
return layout.Center.Layout(gtx, makeGrid(th))
},
func(gtx layout.Context) layout.Dimensions {
return material.Label(th, 24, "your assets").Layout(gtx)
},
assetsTable(th),
func(gtx layout.Context) layout.Dimensions {
return layout.Spacer{Height: unit.Dp(10)}.Layout(gtx)
},
func(gtx layout.Context) layout.Dimensions {
e := material.Editor(th, &chatInput, "write something")
e.Font.Style = font.Italic
border := widget.Border{Color: color.NRGBA{A: 0xff}, CornerRadius: unit.Dp(8), Width: unit.Dp(2)}
return border.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.UniformInset(unit.Dp(8)).Layout(gtx, e.Layout)
})
},
func(gtx layout.Context) layout.Dimensions {
return layout.Center.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return material.Button(th, geminiButton, "ask Gemini for advice").Layout(gtx)
})
},
chatLogger(th),
}
return material.List(th, list).Layout(gtx, len(widgets),
func(gtx layout.Context, i int) layout.Dimensions {
return layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i])
},
)
}