diff options
| author | Pietro Gagliardi <[email protected]> | 2018-08-11 21:29:20 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2018-08-11 21:29:20 -0400 |
| commit | 68ffb808678159b8810c8ed093c0458316d3f8f2 (patch) | |
| tree | 5bda3855b4b6cafc1f39bdbc66204a44493896e3 /spinbox.go | |
| parent | 5ab5777d4cbfe6490760ef4e618bd5fe80a20bea (diff) | |
More control migration.
Diffstat (limited to 'spinbox.go')
| -rw-r--r-- | spinbox.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spinbox.go b/spinbox.go new file mode 100644 index 0000000..a34c3e9 --- /dev/null +++ b/spinbox.go @@ -0,0 +1,56 @@ +// 12 december 2015 + +package ui + +import ( + "unsafe" +) + +// #include "ui.h" +// extern void doSpinboxOnChanged(uiSpinbox *, void *); +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.uiSpinboxOnChanged(s.s, C.doSpinboxOnChanged, nil) + + 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.intmax_t(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 doSpinboxOnChanged +func doSpinboxOnChanged(ss *C.uiSpinbox, data unsafe.Pointer) { + s := ControlFromLibui(uintptr(unsafe.Pointer(ss))).(*Spinbox) + if s.onChanged != nil { + s.onChanged(s) + } +} |
