summaryrefslogtreecommitdiff
path: root/spinbox_unix.go
diff options
context:
space:
mode:
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))
+}