summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basicctrls.go18
-rw-r--r--spinbox_unix.go30
-rw-r--r--zz_test.go4
3 files changed, 50 insertions, 2 deletions
diff --git a/basicctrls.go b/basicctrls.go
index 82550b6..8c97860 100644
--- a/basicctrls.go
+++ b/basicctrls.go
@@ -139,3 +139,21 @@ type Textbox interface {
func NewTextbox() Textbox {
return newTextbox()
}
+
+// Spinbox is a Control that provides a text entry field that accepts integers and up and down buttons to increment and decrement those values.
+// This control is in its preliminary state.
+// TODO everything:
+// - TODO set increment
+// - TODO set step
+// - TODO set page step?
+// - TODO wrapping
+// - TODO set/get integer value
+// - TODO negative values
+type Spinbox interface {
+ Control
+}
+
+// NewSpinbox creates a new Spinbox.
+func NewSpinbox() Spinbox {
+ return newSpinbox()
+}
diff --git a/spinbox_unix.go b/spinbox_unix.go
new file mode 100644
index 0000000..33ac2f3
--- /dev/null
+++ b/spinbox_unix.go
@@ -0,0 +1,30 @@
+// +build !windows,!darwin
+
+// 28 october 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "gtk_unix.h"
+import "C"
+
+// TODO preferred width may be too wide
+
+type spinbox struct {
+ *controlSingleWidget
+ spinbutton *C.GtkSpinButton
+}
+
+func newSpinbox() Spinbox {
+ widget := C.gtk_spin_button_new_with_range(0, 100, 1)
+ s := &spinbox{
+ controlSingleWidget: newControlSingleWidget(widget),
+ spinbutton: (*C.GtkSpinButton)(unsafe.Pointer(widget)),
+ }
+ C.gtk_spin_button_set_digits(s.spinbutton, 0) // integers
+ C.gtk_spin_button_set_numeric(s.spinbutton, C.TRUE) // digits only
+ return s
+}
diff --git a/zz_test.go b/zz_test.go
index 2634d3a..c7f864a 100644
--- a/zz_test.go
+++ b/zz_test.go
@@ -149,9 +149,9 @@ func (tw *testwin) addfe() {
tw.openbtn, tw.fnlabel)
tw.festack.SetStretchy(4)
tw.festack.SetStretchy(6)
- tw.festack2 = newVerticalStack(Space(), NewTextbox())
- tw.festack2.SetStretchy(0)
+ tw.festack2 = newVerticalStack(NewSpinbox(), Space(), NewTextbox())
tw.festack2.SetStretchy(1)
+ tw.festack2.SetStretchy(2)
tw.festack = newHorizontalStack(tw.festack, tw.festack2)
tw.festack.SetStretchy(0)
tw.festack.SetStretchy(1)