-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
47 lines (38 loc) · 988 Bytes
/
main.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
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
)
func main() {
a := app.New()
w := a.NewWindow("Temperature Converter")
valueC := binding.NewFloat()
valueF := celsiusToFarenheit(valueC)
entryC := widget.NewEntryWithData(binding.FloatToString(valueC))
entryC.Wrapping = fyne.TextWrapOff
entryF := widget.NewEntryWithData(binding.FloatToString(valueF))
entryF.Wrapping = fyne.TextWrapOff
w.SetContent(container.NewGridWithColumns(4,
entryC, widget.NewLabel("Celsius ="),
entryF, widget.NewLabel("Fahrenheit")))
w.ShowAndRun()
}
type cToF struct {
binding.Float
}
func (c *cToF) Get() (float64, error) {
cDeg, _ := c.Float.Get()
fDeg := cDeg*(9.0/5.0) + 32
return fDeg, nil
}
func (c *cToF) Set(f float64) error {
cDeg := (f - 32) * (5.0 / 9.0)
_ = c.Float.Set(cDeg)
return nil
}
func celsiusToFarenheit(in binding.Float) binding.Float {
return &cToF{in}
}