2018-08-11 20:29:20 -05:00
|
|
|
// 12 december 2015
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2018-08-26 12:43:05 -05:00
|
|
|
// #include "pkgui.h"
|
2018-08-11 20:29:20 -05:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
// Slider is a Control that represents a horizontal bar that represents
|
|
|
|
// a range of integers. The user can drag a pointer on the bar to
|
|
|
|
// select an integer.
|
|
|
|
type Slider struct {
|
|
|
|
ControlBase
|
|
|
|
s *C.uiSlider
|
|
|
|
onChanged func(*Slider)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSlider creates a new Slider. If min >= max, they are swapped.
|
|
|
|
func NewSlider(min int, max int) *Slider {
|
|
|
|
s := new(Slider)
|
|
|
|
|
|
|
|
s.s = C.uiNewSlider(C.int(min), C.int(max))
|
|
|
|
|
2018-08-26 12:43:05 -05:00
|
|
|
C.pkguiSliderOnChanged(s.s)
|
2018-08-11 20:29:20 -05:00
|
|
|
|
|
|
|
s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns the Slider's current value.
|
|
|
|
func (s *Slider) Value() int {
|
|
|
|
return int(C.uiSliderValue(s.s))
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue sets the Slider's current value to value.
|
|
|
|
func (s *Slider) SetValue(value int) {
|
2018-08-11 22:21:30 -05:00
|
|
|
C.uiSliderSetValue(s.s, C.int(value))
|
2018-08-11 20:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnChanged registers f to be run when the user changes the value
|
|
|
|
// of the Slider. Only one function can be registered at a time.
|
|
|
|
func (s *Slider) OnChanged(f func(*Slider)) {
|
|
|
|
s.onChanged = f
|
|
|
|
}
|
|
|
|
|
2018-08-26 12:43:05 -05:00
|
|
|
//export pkguiDoSliderOnChanged
|
|
|
|
func pkguiDoSliderOnChanged(ss *C.uiSlider, data unsafe.Pointer) {
|
2018-08-11 20:29:20 -05:00
|
|
|
s := ControlFromLibui(uintptr(unsafe.Pointer(ss))).(*Slider)
|
|
|
|
if s.onChanged != nil {
|
|
|
|
s.onChanged(s)
|
|
|
|
}
|
|
|
|
}
|