From 649b52b6ef273c2ea5a4cf881835a7fd61bd4df1 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 28 Oct 2014 11:01:02 -0400 Subject: [PATCH] Set up the absolute basic Spinbox and implemented it on GTK+. This is easy as it's one control on GTK+; now we have to do it on Windows and Mac OS X. And on those platforms, those are two separate controls (a standard edit control and an up-down/NSSpinner). --- basicctrls.go | 18 ++++++++++++++++++ spinbox_unix.go | 30 ++++++++++++++++++++++++++++++ zz_test.go | 4 ++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 spinbox_unix.go 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)