Implemented Group on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-08-16 00:37:38 -04:00
parent 5a1fc98fc3
commit 1d117b7965
4 changed files with 89 additions and 1 deletions

View File

@ -6,6 +6,8 @@
#define toNSButton(x) ((NSButton *) (x))
#define toNSTextField(x) ((NSTextField *) (x))
#define toNSView(x) ((NSView *) (x))
#define toNSBox(x) ((NSBox *) (x))
@interface goControlDelegate : NSObject {
@public
@ -156,3 +158,28 @@ id newLabel(void)
[l setDrawsBackground:NO];
return finishNewTextField(l, NO);
}
id newGroup(id container)
{
NSBox *group;
group = [[NSBox alloc] initWithFrame:NSZeroRect];
[group setBorderType:NSLineBorder];
[group setBoxType:NSBoxPrimary];
[group setTransparent:NO];
// can't use setSmallControlFont() here because the selector is different
[group setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
[group setTitlePosition:NSAtTop];
[group setContentView:toNSView(container)];
return (id) group;
}
const char *groupText(id group)
{
return [[toNSBox(group) title] UTF8String];
}
void groupSetText(id group, char *text)
{
[toNSBox(group) setTitle:[NSString stringWithUTF8String:text]];
}

View File

@ -28,7 +28,7 @@ void setSmallControlFont(id control)
[toNSControl(control) setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
}
// also good for NSProgressIndicator
// also good for NSBox and NSProgressIndicator
struct xsize controlPreferredSize(id control)
{
NSControl *c;

58
redo/group_darwin.go Normal file
View File

@ -0,0 +1,58 @@
// 16 august 2014
package ui
import (
"unsafe"
)
// #include "objc_darwin.h"
import "C"
type group struct {
_id C.id
*container
}
func newGroup(text string, control Control) Group {
g := new(group)
g.container = newContainer(control)
g._id = C.newGroup(g.container.id)
g.SetText(text)
return g
}
func (g *group) Text() string {
return C.GoString(C.groupText(g._id))
}
func (g *group) SetText(text string) {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
C.groupSetText(g._id, ctext)
}
func (g *group) id() C.id {
return g._id
}
func (g *group) setParent(p *controlParent) {
basesetParent(g, p)
}
func (g *group) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
return baseallocate(g, x, y, width, height, d)
}
func (g *group) preferredSize(d *sizing) (width, height int) {
return basepreferredSize(g, d)
}
func (g *group) commitResize(a *allocation, d *sizing) {
basecommitResize(g, a, d)
}
func (g *group) getAuxResizeInfo(d *sizing) {
basegetAuxResizeInfo(g, d)
}

View File

@ -69,6 +69,9 @@ extern id newPasswordField(void);
extern const char *textFieldText(id);
extern void textFieldSetText(id, char *);
extern id newLabel(void);
extern id newGroup(id);
extern const char *groupText(id);
extern void groupSetText(id, char *);
/* container_darwin.m */
extern id newContainerView(void *);