summaryrefslogtreecommitdiff
path: root/spinbox.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2018-08-26 13:43:05 -0400
committerPietro Gagliardi <[email protected]>2018-08-26 13:43:05 -0400
commit7b7ae9d7ce2aa6f99677fde7b8a0c21c7024e3e9 (patch)
tree17813999d509a6dd0d1636f415622876c0d6ff93 /spinbox.go
parent1095719d84a6ac5f90eefe8e23913f3e09ad692d (diff)
More control migration. Everything beyond this point is nontrivial.
Diffstat (limited to 'spinbox.go')
-rw-r--r--spinbox.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/spinbox.go b/spinbox.go
new file mode 100644
index 0000000..a7161f3
--- /dev/null
+++ b/spinbox.go
@@ -0,0 +1,55 @@
+// 12 december 2015
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "pkgui.h"
+import "C"
+
+// Spinbox is a Control that represents a space where the user can
+// enter integers. The space also comes with buttons to add or
+// subtract 1 from the integer.
+type Spinbox struct {
+ ControlBase
+ s *C.uiSpinbox
+ onChanged func(*Spinbox)
+}
+
+// NewSpinbox creates a new Spinbox. If min >= max, they are swapped.
+func NewSpinbox(min int, max int) *Spinbox {
+ s := new(Spinbox)
+
+ s.s = C.uiNewSpinbox(C.int(min), C.int(max))
+
+ C.pkguiSpinboxOnChanged(s.s)
+
+ s.ControlBase = NewControlBase(s, uintptr(unsafe.Pointer(s.s)))
+ return s
+}
+
+// Value returns the Spinbox's current value.
+func (s *Spinbox) Value() int {
+ return int(C.uiSpinboxValue(s.s))
+}
+
+// SetValue sets the Spinbox's current value to value.
+func (s *Spinbox) SetValue(value int) {
+ C.uiSpinboxSetValue(s.s, C.int(value))
+}
+
+// OnChanged registers f to be run when the user changes the value
+// of the Spinbox. Only one function can be registered at a time.
+func (s *Spinbox) OnChanged(f func(*Spinbox)) {
+ s.onChanged = f
+}
+
+//export pkguiDoSpinboxOnChanged
+func pkguiDoSpinboxOnChanged(ss *C.uiSpinbox, data unsafe.Pointer) {
+ s := ControlFromLibui(uintptr(unsafe.Pointer(ss))).(*Spinbox)
+ if s.onChanged != nil {
+ s.onChanged(s)
+ }
+}