2014-10-28 17:25:05 -05:00
|
|
|
// 28 october 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
2014-10-29 11:12:00 -05:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-10-28 17:25:05 -05:00
|
|
|
// #include "objc_darwin.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
// interface builder notes
|
|
|
|
// - the tops of the alignment rects should be identical
|
|
|
|
// - spinner properties: auto repeat
|
|
|
|
// - http://stackoverflow.com/questions/702829/integrate-nsstepper-with-nstextfield we'll need to bind the int value :S
|
|
|
|
// - TODO experiment with a dummy project
|
2014-10-28 19:29:37 -05:00
|
|
|
// - http://juliuspaintings.co.uk/cgi-bin/paint_css/animatedPaint/059-NSStepper-NSTextField.pl
|
|
|
|
// - http://www.youtube.com/watch?v=ZZSHU-O7HVo
|
|
|
|
// - http://andrehoffmann.wordpress.com/tag/nsstepper/ ?
|
2014-10-28 17:25:05 -05:00
|
|
|
// TODO
|
|
|
|
// - proper spacing between edit and spinner: Interface Builder isn't clear; NSDatePicker doesn't spill the beans
|
2014-10-29 11:12:00 -05:00
|
|
|
|
|
|
|
type spinbox struct {
|
2014-10-31 18:57:48 -05:00
|
|
|
id C.id
|
|
|
|
changed *event
|
2014-10-29 11:12:00 -05:00
|
|
|
}
|
|
|
|
|
2014-10-30 13:35:31 -05:00
|
|
|
func newSpinbox(min int, max int) Spinbox {
|
2014-10-29 11:12:00 -05:00
|
|
|
s := new(spinbox)
|
2014-10-30 13:35:31 -05:00
|
|
|
s.id = C.newSpinbox(unsafe.Pointer(s), C.intmax_t(min), C.intmax_t(max))
|
2014-10-31 18:57:48 -05:00
|
|
|
s.changed = newEvent()
|
2014-10-29 11:12:00 -05:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2014-10-30 13:35:31 -05:00
|
|
|
func (s *spinbox) Value() int {
|
|
|
|
return int(C.spinboxValue(s.id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) SetValue(value int) {
|
|
|
|
C.spinboxSetValue(s.id, C.intmax_t(value))
|
|
|
|
}
|
|
|
|
|
2014-10-31 18:57:48 -05:00
|
|
|
func (s *spinbox) OnChanged(e func()) {
|
|
|
|
s.changed.set(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export spinboxChanged
|
|
|
|
func spinboxChanged(data unsafe.Pointer) {
|
|
|
|
s := (*spinbox)(data)
|
|
|
|
s.changed.fire()
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:34:41 -05:00
|
|
|
func (s *spinbox) textfield() C.id {
|
|
|
|
return C.spinboxTextField(s.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) stepper() C.id {
|
|
|
|
return C.spinboxStepper(s.id)
|
|
|
|
}
|
|
|
|
|
2014-10-29 11:12:00 -05:00
|
|
|
func (s *spinbox) setParent(p *controlParent) {
|
2014-10-29 19:34:41 -05:00
|
|
|
C.parent(s.textfield(), p.id)
|
|
|
|
C.parent(s.stepper(), p.id)
|
2014-10-29 11:12:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) preferredSize(d *sizing) (width, height int) {
|
|
|
|
// TODO
|
|
|
|
return 20, 20
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) resize(x int, y int, width int, height int, d *sizing) {
|
|
|
|
// TODO
|
2014-10-29 19:34:41 -05:00
|
|
|
C.moveControl(s.textfield(), C.intptr_t(x), C.intptr_t(y), C.intptr_t(width - 20), C.intptr_t(height))
|
|
|
|
C.moveControl(s.stepper(), C.intptr_t(x + width - 15), C.intptr_t(y), C.intptr_t(15), C.intptr_t(height))
|
2014-10-29 11:12:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) nTabStops() int {
|
|
|
|
// TODO does the stepper count?
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) containerShow() {
|
|
|
|
// only provided for the Windows backend
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *spinbox) containerHide() {
|
|
|
|
// only provided for the Windows backend
|
|
|
|
}
|