@@ -7,8 +7,11 @@ NumberInput create a number input and return its value.
7
7
### Interface
8
8
9
9
``` go
10
- func Number (s *tgframe .State , c *tgframe .Container , label string ) int
11
- func NumberWithConf(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf) int
10
+ func NumberFloat64 (s *tgframe .State , c *tgframe .Container , label string ) *float64
11
+ func NumberWithConfFloat64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[float64]) *float64
12
+
13
+ func NumberInt64(s *tgframe.State, c *tgframe.Container, label string) *int64
14
+ func NumberWithConfInt64(s *tgframe.State, c *tgframe.Container, label string, conf *NumberConf[int64]) *int64
12
15
```
13
16
14
17
### Parameters
@@ -19,18 +22,18 @@ func NumberWithConf(s *tgframe.State, c *tgframe.Container, label string, conf *
19
22
20
23
```go
21
24
// NumberConf is the configuration for a number component.
22
- type NumberConf struct {
25
+ type NumberConf[T float64 | int64] struct {
23
26
// Default is the default value of the number component.
24
- Default *float64
27
+ Default *T
25
28
26
29
// Min is the minimum value of the number component.
27
- Min *float64
30
+ Min *T
28
31
29
32
// Max is the maximum value of the number component.
30
- Max *float64
33
+ Max *T
31
34
32
35
// Step is the step of the number component.
33
- Step *float64
36
+ Step *T
34
37
35
38
// Color is the color of the number component.
36
39
Color tcutil.Color
@@ -45,17 +48,22 @@ type NumberConf struct {
45
48
ID string
46
49
}
47
50
48
- func (c *NumberConf ) SetMin (min float64 ) *NumberConf {
51
+ func (c *NumberConf [T ]) SetDefault (default T ) *NumberConf [T ] {
52
+ c.Default = &default
53
+ return c
54
+ }
55
+
56
+ func (c *NumberConf [T ]) SetMin (min T ) *NumberConf [T ] {
49
57
c.Min = &min
50
58
return c
51
59
}
52
60
53
- func (c *NumberConf ) SetMax (max float64 ) *NumberConf {
61
+ func (c *NumberConf [ T ] ) SetMax (max T ) *NumberConf [ T ] {
54
62
c.Max = &max
55
63
return c
56
64
}
57
65
58
- func (c *NumberConf ) SetStep (step float64 ) *NumberConf {
66
+ func (c *NumberConf [ T ] ) SetStep (step T ) *NumberConf [ T ] {
59
67
c.Step = &step
60
68
return c
61
69
}
@@ -64,8 +72,8 @@ func (c *NumberConf) SetStep(step float64) *NumberConf {
64
72
## Example
65
73
66
74
``` go
67
- numberValue := tgcomp.NumberWithConf (numberCompCol, p.State , " Number" ,
68
- (&tgcomp.NumberConf {
75
+ numberValue := tgcomp.NumberWithConfFloat64 (numberCompCol, p.State , " Number" ,
76
+ (&tgcomp.NumberConf [ float64 ] {
69
77
Placeholder : " input the value here" ,
70
78
Color : tcutil.ColorSuccess ,
71
79
}).SetMin (10 ).SetMax (20 ).SetStep (2 ))
0 commit comments