-
Notifications
You must be signed in to change notification settings - Fork 17
/
slider.go
63 lines (49 loc) · 1.38 KB
/
slider.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
package gocoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
// #import "slider.h"
import "C"
type Slider struct {
sliderPtr C.SliderPtr
callback func()
}
var sliders []*Slider
type SliderType int32
const (
SliderTypeCircular SliderType = 1
SliderTypeLinear SliderType = 0
)
//export onSliderValueChanged
func onSliderValueChanged(id C.int) {
sliderID := int(id)
if sliderID < len(sliders) && sliders[sliderID].callback != nil {
sliders[sliderID].callback()
}
}
func NewSlider(x int, y int, width int, height int) *Slider {
sliderID := len(sliders)
sliderPtr := C.Slider_New(C.int(sliderID), C.int(x), C.int(y), C.int(width), C.int(height))
slider := &Slider{
sliderPtr: sliderPtr,
}
sliders = append(sliders, slider)
return slider
}
func (slider *Slider) SetMaximumValue(val float64) {
C.Slider_SetMaximumValue(slider.sliderPtr, C.double(val))
}
func (slider *Slider) SetMinimumValue(val float64) {
C.Slider_SetMinimumValue(slider.sliderPtr, C.double(val))
}
func (slider *Slider) SetValue(val float64) {
C.Slider_SetValue(slider.sliderPtr, C.double(val))
}
func (slider *Slider) Value() float64 {
return float64(C.Slider_Value(slider.sliderPtr))
}
func (slider *Slider) SetSliderType(sliderType SliderType) {
C.Slider_SetSliderType(slider.sliderPtr, C.int(sliderType))
}
func (slider *Slider) OnSliderValueChanged(fn func()) {
slider.callback = fn
}