From 6428b17b7f92abbb84ef61361dd9ee2a3ebcae9f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 30 Oct 2014 12:16:42 -0400 Subject: Started fleshing out the Spinbox interface. Added Value() and SetValue(); implemented on GTK+. Added min and max to the constructor; implemented on GTK+. --- spinbox_unix.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'spinbox_unix.go') 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)) +} -- cgit v1.2.3