summaryrefslogtreecommitdiff
path: root/spinbox_unix.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-30 12:16:42 -0400
committerPietro Gagliardi <[email protected]>2014-10-30 12:17:09 -0400
commit6428b17b7f92abbb84ef61361dd9ee2a3ebcae9f (patch)
tree19398ed7987ae93a162c3300a40b2fa416d75832 /spinbox_unix.go
parentb28781f281a7a65a89e4d7c830c773f6382fb6fb (diff)
Started fleshing out the Spinbox interface. Added Value() and SetValue(); implemented on GTK+. Added min and max to the constructor; implemented on GTK+.
Diffstat (limited to 'spinbox_unix.go')
-rw-r--r--spinbox_unix.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/spinbox_unix.go b/spinbox_unix.go
index 33ac2f3..b6b2ec3 100644
--- a/spinbox_unix.go
+++ b/spinbox_unix.go
@@ -18,8 +18,9 @@ type spinbox struct {
spinbutton *C.GtkSpinButton
}
-func newSpinbox() Spinbox {
- widget := C.gtk_spin_button_new_with_range(0, 100, 1)
+func newSpinbox(min int, max int) Spinbox {
+ // gtk_spin_button_new_with_range() initially sets its value to the minimum value
+ widget := C.gtk_spin_button_new_with_range(C.gdouble(min), C.gdouble(max), 1)
s := &spinbox{
controlSingleWidget: newControlSingleWidget(widget),
spinbutton: (*C.GtkSpinButton)(unsafe.Pointer(widget)),
@@ -28,3 +29,20 @@ func newSpinbox() Spinbox {
C.gtk_spin_button_set_numeric(s.spinbutton, C.TRUE) // digits only
return s
}
+
+func (s *spinbox) Value() int {
+ return int(C.gtk_spin_button_get_value(s.spinbutton))
+}
+
+func (s *spinbox) SetValue(value int) {
+ var min, max C.gdouble
+
+ C.gtk_spin_button_get_range(s.spinbutton, &min, &max)
+ if value < int(min) {
+ value = int(min)
+ }
+ if value > int(max) {
+ value = int(max)
+ }
+ C.gtk_spin_button_set_value(s.spinbutton, C.gdouble(value))
+}