Started fleshing out the Spinbox interface. Added Value() and SetValue(); implemented on GTK+. Added min and max to the constructor; implemented on GTK+.
This commit is contained in:
parent
b28781f281
commit
6428b17b7f
|
@ -143,8 +143,7 @@ func NewTextbox() Textbox {
|
||||||
// Spinbox is a Control that provides a text entry field that accepts integers and up and down buttons to increment and decrement those values.
|
// 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.
|
// This control is in its preliminary state.
|
||||||
// TODO everything:
|
// TODO everything:
|
||||||
// - TODO set increment
|
// - TODO set increment? (work on windows)
|
||||||
// - TODO set step
|
|
||||||
// - TODO set page step?
|
// - TODO set page step?
|
||||||
// - TODO wrapping
|
// - TODO wrapping
|
||||||
// - TODO set/get integer value
|
// - TODO set/get integer value
|
||||||
|
@ -152,9 +151,19 @@ func NewTextbox() Textbox {
|
||||||
// - TODO ensuring values entered in text box stay within bounds
|
// - TODO ensuring values entered in text box stay within bounds
|
||||||
type Spinbox interface {
|
type Spinbox interface {
|
||||||
Control
|
Control
|
||||||
|
|
||||||
|
// Value and SetValue get and set the current value of the Spinbox, respectively.
|
||||||
|
// For SetValue, if the new value is outside the current range of the Spinbox, it is set to the nearest extremity.
|
||||||
|
Value() int
|
||||||
|
SetValue(value int)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSpinbox creates a new Spinbox.
|
// NewSpinbox creates a new Spinbox with the given minimum and maximum.
|
||||||
func NewSpinbox() Spinbox {
|
// The initial value will be the minimum value.
|
||||||
return newSpinbox()
|
// NewSpinbox() panics if min > max.
|
||||||
|
func NewSpinbox(min int, max int) Spinbox {
|
||||||
|
if min > max {
|
||||||
|
panic("min > max in NewSpinbox()")
|
||||||
|
}
|
||||||
|
return newSpinbox(min, max)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ type spinbox struct {
|
||||||
spinbutton *C.GtkSpinButton
|
spinbutton *C.GtkSpinButton
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSpinbox() Spinbox {
|
func newSpinbox(min int, max int) Spinbox {
|
||||||
widget := C.gtk_spin_button_new_with_range(0, 100, 1)
|
// 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{
|
s := &spinbox{
|
||||||
controlSingleWidget: newControlSingleWidget(widget),
|
controlSingleWidget: newControlSingleWidget(widget),
|
||||||
spinbutton: (*C.GtkSpinButton)(unsafe.Pointer(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
|
C.gtk_spin_button_set_numeric(s.spinbutton, C.TRUE) // digits only
|
||||||
return s
|
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))
|
||||||
|
}
|
||||||
|
|
15
zz_test.go
15
zz_test.go
|
@ -149,9 +149,18 @@ func (tw *testwin) addfe() {
|
||||||
tw.openbtn, tw.fnlabel)
|
tw.openbtn, tw.fnlabel)
|
||||||
tw.festack.SetStretchy(4)
|
tw.festack.SetStretchy(4)
|
||||||
tw.festack.SetStretchy(6)
|
tw.festack.SetStretchy(6)
|
||||||
tw.festack2 = newVerticalStack(NewSpinbox(), Space(), NewTextbox())
|
sb := NewSpinbox(0, 100)
|
||||||
tw.festack2.SetStretchy(1)
|
cbutton := NewButton("Set to Invalid Low")
|
||||||
tw.festack2.SetStretchy(2)
|
cbutton.OnClicked(func() {
|
||||||
|
sb.SetValue(-500)
|
||||||
|
})
|
||||||
|
dbutton := NewButton("Set to Invalid High")
|
||||||
|
dbutton.OnClicked(func() {
|
||||||
|
sb.SetValue(500)
|
||||||
|
})
|
||||||
|
tw.festack2 = newVerticalStack(sb, cbutton, dbutton, Space(), NewTextbox())
|
||||||
|
tw.festack2.SetStretchy(3)
|
||||||
|
tw.festack2.SetStretchy(4)
|
||||||
tw.festack = newHorizontalStack(tw.festack, tw.festack2)
|
tw.festack = newHorizontalStack(tw.festack, tw.festack2)
|
||||||
tw.festack.SetStretchy(0)
|
tw.festack.SetStretchy(0)
|
||||||
tw.festack.SetStretchy(1)
|
tw.festack.SetStretchy(1)
|
||||||
|
|
Loading…
Reference in New Issue