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).

This commit is contained in:
Pietro Gagliardi 2014-10-28 11:01:02 -04:00
parent 61cd7f5b0a
commit 649b52b6ef
3 changed files with 50 additions and 2 deletions

View File

@ -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()
}

30
spinbox_unix.go Normal file
View File

@ -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
}

View File

@ -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)