-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
122 lines (97 loc) · 2.29 KB
/
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
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
package main
import (
"fmt"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"os"
"strconv"
)
var MainMenu *ui.Window
func main() {
if err := ui.Main(menu); err!= nil {
panic(err)
}
}
func stringToInt(str string) int {
i, err := strconv.Atoi(str)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
return i
}
func menu() {
MainMenu = ui.NewWindow("Calculator UI", 300, 500, true)
MainMenu.OnClosing(func (*ui.Window) bool {
ui.Quit()
return true
})
ui.OnShouldQuit(func() bool {
MainMenu.Destroy()
return true
})
tab := ui.NewTab()
MainMenu.SetChild(tab)
MainMenu.SetMargined(true)
tab.Append("Calculator", CalculatorUI())
tab.SetMargined(0, true)
MainMenu.Show()
}
func CalculatorUI() ui.Control {
var anwserEntry *ui.Entry
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
vbox.Append(ui.NewLabel(""), false)
group := ui.NewGroup("")
group.SetMargined(true)
vbox.Append(group, true)
group.SetChild(ui.NewNonWrappingMultilineEntry())
CalForm := ui.NewForm()
CalForm.SetPadded(true)
group.SetChild(CalForm)
entryNum1 := ui.NewEntry()
entryNum1.OnChanged(func(entry *ui.Entry) {
})
CalForm.Append("First Number:", entryNum1, false)
simbol := ui.NewCombobox()
simbol.Append("+")
simbol.Append("-")
simbol.Append("*")
simbol.Append("/")
simbol.OnSelected(func(combobox *ui.Combobox) {
})
CalForm.Append("simbol:", simbol, false) //HAHA , dont ask why simbol...
entryNum2 := ui.NewEntry()
entryNum2.OnChanged(func(entry *ui.Entry) {
})
CalForm.Append("Second Number:", entryNum2, false)
gimmeAnwser := ui.NewButton("gimme anwser >:D")
CalForm.Append("", gimmeAnwser, false)
gimmeAnwser.OnClicked(func(button *ui.Button) {
number1 := entryNum1.Text()
number2 := entryNum2.Text()
var nb1 int = stringToInt(number1)
var nb2 int = stringToInt(number2)
anwser := 0
switch simbol.Selected() {
case 0:
anwser = nb1 + nb2
case 1:
anwser = nb1 - nb2
case 2:
anwser = nb1 * nb2
case 3:
anwser = nb1 / nb2
}
anwser1 := strconv.Itoa(anwser)
fmt.Println(anwser)
anwserEntry.SetText(anwser1)
})
anwserEntry = ui.NewEntry()
anwserEntry.SetReadOnly(true)
CalForm.Append("Anwser:", anwserEntry, false)
return vbox
}