-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprice-text.go
More file actions
42 lines (34 loc) · 1.18 KB
/
price-text.go
File metadata and controls
42 lines (34 loc) · 1.18 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
package main
import (
"fmt"
"image/color"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
)
func (app *Config) GetPriceText() (*canvas.Text, *canvas.Text, *canvas.Text) {
var g Gold
var open, current, change *canvas.Text
g.Client = app.HTTPClient
gold, err := g.GetPrices()
if err != nil {
gray := color.NRGBA{R: 155, G: 155, B: 155, A: 255}
open = canvas.NewText("Open: Unreachable", gray)
current = canvas.NewText("Current: Unreachable", gray)
change = canvas.NewText("Change: Unreachable", gray)
} else {
displayColor := color.NRGBA{R: 0, G: 180, B: 0, A: 255}
if gold.Price < gold.PreviousClose {
displayColor = color.NRGBA{R: 180, G: 0, B: 0, A: 255}
}
openText := fmt.Sprintf("Open: $%.4f %s", gold.PreviousClose, currency)
currentText := fmt.Sprintf("Current: $%.4f %s", gold.Price, currency)
changeText := fmt.Sprintf("Change: $%.4f %s", gold.Change, currency)
open = canvas.NewText(openText, nil)
current = canvas.NewText(currentText, displayColor)
change = canvas.NewText(changeText, displayColor)
}
open.Alignment = fyne.TextAlignLeading
current.Alignment = fyne.TextAlignCenter
change.Alignment = fyne.TextAlignTrailing
return open, current, change
}