Added the initial implementaiton of Spinbox on Mac OS X. It doesn't quite work yet.
This commit is contained in:
parent
765ccf00a3
commit
6d58f434b7
|
@ -53,6 +53,7 @@ func containerResized(data unsafe.Pointer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are based on measurements from Interface Builder.
|
// These are based on measurements from Interface Builder.
|
||||||
|
// TODO reverify these against /layout rects/, not /frame rects/
|
||||||
const (
|
const (
|
||||||
macXMargin = 20
|
macXMargin = 20
|
||||||
macYMargin = 20
|
macYMargin = 20
|
||||||
|
|
|
@ -151,4 +151,8 @@ extern void openFile(id, void *);
|
||||||
extern id newWarningPopover(char *);
|
extern id newWarningPopover(char *);
|
||||||
extern void warningPopoverShow(id, id);
|
extern void warningPopoverShow(id, id);
|
||||||
|
|
||||||
|
/* spinbox_darwin.m */
|
||||||
|
extern id newSpinboxStepper(void);
|
||||||
|
extern id spinboxSetup(id, id, void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// #include "objc_darwin.h"
|
// #include "objc_darwin.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -15,3 +19,46 @@ import "C"
|
||||||
// - http://andrehoffmann.wordpress.com/tag/nsstepper/ ?
|
// - http://andrehoffmann.wordpress.com/tag/nsstepper/ ?
|
||||||
// TODO
|
// TODO
|
||||||
// - proper spacing between edit and spinner: Interface Builder isn't clear; NSDatePicker doesn't spill the beans
|
// - proper spacing between edit and spinner: Interface Builder isn't clear; NSDatePicker doesn't spill the beans
|
||||||
|
|
||||||
|
type spinbox struct {
|
||||||
|
textfield C.id
|
||||||
|
stepper C.id
|
||||||
|
objcspinbox C.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSpinbox() Spinbox {
|
||||||
|
s := new(spinbox)
|
||||||
|
s.textfield = C.newTextField()
|
||||||
|
s.stepper = C.newSpinboxStepper()
|
||||||
|
s.objcspinbox = C.spinboxSetup(s.textfield, s.stepper, unsafe.Pointer(s))
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *spinbox) setParent(p *controlParent) {
|
||||||
|
C.parent(s.textfield, p.id)
|
||||||
|
C.parent(s.stepper, p.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
// 29 october 2014
|
||||||
|
|
||||||
|
#include "objc_darwin.h"
|
||||||
|
#include "_cgo_export.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
@interface goSpinbox : NSObject {
|
||||||
|
@public
|
||||||
|
void *gospinbox;
|
||||||
|
}
|
||||||
|
@property NSInteger integerValue;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation goSpinbox
|
||||||
|
@synthesize integerValue;
|
||||||
|
@end
|
||||||
|
|
||||||
|
id newSpinboxStepper(void)
|
||||||
|
{
|
||||||
|
NSStepper *s;
|
||||||
|
|
||||||
|
s = [[NSStepper alloc] initWithFrame:NSZeroRect];
|
||||||
|
[s setMinValue:0];
|
||||||
|
[s setMaxValue:100];
|
||||||
|
[s setIncrement:1];
|
||||||
|
[s setAutorepeat:YES]; // hold mouse button to step repeatedly
|
||||||
|
return (id) s;
|
||||||
|
}
|
||||||
|
|
||||||
|
id spinboxSetup(id textfield, id stepper, void *gospinbox)
|
||||||
|
{
|
||||||
|
goSpinbox *g;
|
||||||
|
|
||||||
|
g = [goSpinbox new];
|
||||||
|
g->gospinbox = gospinbox;
|
||||||
|
// TODO set any options?
|
||||||
|
[textfield bind:@"integerValue" toObject:g withKeyPath:@"integerValue" options:nil];
|
||||||
|
[stepper bind:@"integerValue" toObject:g withKeyPath:@"integerValue" options:nil];
|
||||||
|
return (id) g;
|
||||||
|
}
|
Loading…
Reference in New Issue