-
Notifications
You must be signed in to change notification settings - Fork 26
/
giox_helpers.go
92 lines (76 loc) · 1.9 KB
/
giox_helpers.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
package main
import (
"strconv"
l "gioui.org/layout"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"github.com/scartill/giox"
xmat "github.com/scartill/giox/material"
)
func labelCombo(th *material.Theme, label string, combo *giox.Combo) l.FlexChild {
inset := l.Inset{Top: unit.Dp(10), Right: unit.Dp(10)}
return l.Rigid(func(gtx l.Context) l.Dimensions {
return l.Flex{Axis: l.Horizontal}.Layout(gtx,
l.Rigid(func(gtx l.Context) l.Dimensions {
return inset.Layout(gtx, func(gtx l.Context) l.Dimensions {
return material.Label(th, unit.Dp(16), label).Layout(gtx)
})
}),
l.Rigid(func(gtx l.Context) l.Dimensions {
return xmat.Combo(th, combo).Layout(gtx)
}))
})
}
func extractInt(edit *widget.Editor, value *int, onError int) {
parsed, err := strconv.Atoi(edit.Text())
if err == nil {
*value = parsed
} else {
*value = onError
}
}
func extractUInt8(edit *widget.Editor, value *uint8, onError uint8) {
parsed, err := strconv.ParseUint(edit.Text(), 10, 8)
if err == nil {
*value = uint8(parsed)
} else {
*value = onError
}
}
func extractInt8(edit *widget.Editor, value *int8, onError int8) {
parsed, err := strconv.ParseInt(edit.Text(), 10, 8)
if err == nil {
*value = int8(parsed)
} else {
*value = onError
}
}
func extractInt32(edit *widget.Editor, value *int32, onError int32) {
parsed, err := strconv.ParseInt(edit.Text(), 10, 32)
if err == nil {
*value = int32(parsed)
} else {
*value = onError
}
}
func extractFloat(edit *widget.Editor, value *float64, onError float64) {
parsed, err := strconv.ParseFloat(edit.Text(), 64)
if err == nil {
*value = parsed
} else {
*value = onError
}
}
func extractIntCombo(combo *giox.Combo, value *int, onError int) {
if !combo.HasSelected() {
*value = onError
return
}
parsed, err := strconv.Atoi(combo.SelectedText())
if err == nil {
*value = parsed
} else {
*value = onError
}
}