Implemented Tab on Mac OS X. Woo! I'll need to add justification for what I'm doing with the whole recursive call thing; when I get confirmation from the GTK+ camp I will.
This commit is contained in:
parent
41f3ef292f
commit
ee5c6ff846
|
@ -0,0 +1,52 @@
|
||||||
|
// 25 july 2014
|
||||||
|
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// #include "objc_darwin.h"
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
type tab struct {
|
||||||
|
*widgetbase
|
||||||
|
|
||||||
|
containers []*container
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTab() Tab {
|
||||||
|
t := new(tab)
|
||||||
|
id := C.newTab(unsafe.Pointer(t))
|
||||||
|
t.widgetbase = newWidget(id)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) Append(name string, control Control) {
|
||||||
|
// TODO isolate and standardize
|
||||||
|
c := new(container)
|
||||||
|
// don't set beginResize; this container's resize() will be a recursive call
|
||||||
|
t.containers = append(t.containers, c)
|
||||||
|
cname := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
tabview := C.tabAppend(t.id, cname)
|
||||||
|
c.child = control
|
||||||
|
c.child.setParent(tabview)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *tab) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
||||||
|
// set up the recursive calls
|
||||||
|
for _, c := range t.containers {
|
||||||
|
c.d = d
|
||||||
|
}
|
||||||
|
// and prepare the tabbed control itself
|
||||||
|
return t.widgetbase.allocate(x, y, width, height, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export tabResized
|
||||||
|
func tabResized(data unsafe.Pointer, width C.intptr_t, height C.intptr_t) {
|
||||||
|
t := (*tab)(unsafe.Pointer(data))
|
||||||
|
for _, c := range t.containers {
|
||||||
|
c.resize(int(width), int(height))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
// 25 july 2014
|
||||||
|
|
||||||
|
#import "objc_darwin.h"
|
||||||
|
#import "_cgo_export.h"
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
|
#define toNSTabView(x) ((NSTabView *) (x))
|
||||||
|
|
||||||
|
@interface goTabView : NSTabView {
|
||||||
|
@public
|
||||||
|
void *gotab;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation goTabView
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)r
|
||||||
|
{
|
||||||
|
NSRect content;
|
||||||
|
|
||||||
|
[super setFrame:r];
|
||||||
|
content = [self contentRect];
|
||||||
|
tabResized(self->gotab, (intptr_t) content.size.width, (intptr_t) content.size.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
id newTab(void *gotab)
|
||||||
|
{
|
||||||
|
goTabView *t;
|
||||||
|
|
||||||
|
t = [[goTabView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
|
||||||
|
// TODO font
|
||||||
|
t->gotab = gotab;
|
||||||
|
return (id) t;
|
||||||
|
}
|
||||||
|
|
||||||
|
id tabAppend(id t, char *name)
|
||||||
|
{
|
||||||
|
NSTabViewItem *i;
|
||||||
|
|
||||||
|
i = [[NSTabViewItem alloc] initWithIdentifier:nil];
|
||||||
|
[i setLabel:[NSString stringWithUTF8String:name]];
|
||||||
|
[toNSTabView(t) addTabViewItem:i];
|
||||||
|
return (id) [i view];
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build !windows,!darwin
|
||||||
|
|
||||||
// 25 july 2014
|
// 25 july 2014
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
|
@ -96,7 +96,3 @@ func (c *checkbox) Checked() bool {
|
||||||
func (c *checkbox) SetChecked(checked bool) {
|
func (c *checkbox) SetChecked(checked bool) {
|
||||||
C.checkboxSetChecked(c.id, toBOOL(checked))
|
C.checkboxSetChecked(c.id, toBOOL(checked))
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
func newTab() Tab{return newButton("tab")}
|
|
||||||
func(*button)Append(string,Control){}
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
void parent(id control, id parentid)
|
void parent(id control, id parentid)
|
||||||
{
|
{
|
||||||
[[toNSWindow(parentid) contentView] addSubview:toNSView(control)];
|
[toNSView(parentid) addSubview:toNSView(control)];
|
||||||
}
|
}
|
||||||
|
|
||||||
void controlSetHidden(id control, BOOL hidden)
|
void controlSetHidden(id control, BOOL hidden)
|
||||||
|
|
|
@ -28,6 +28,7 @@ extern void windowSetTitle(id, const char *);
|
||||||
extern void windowShow(id);
|
extern void windowShow(id);
|
||||||
extern void windowHide(id);
|
extern void windowHide(id);
|
||||||
extern void windowClose(id);
|
extern void windowClose(id);
|
||||||
|
extern id windowContentView(id);
|
||||||
extern void windowRedraw(id);
|
extern void windowRedraw(id);
|
||||||
|
|
||||||
/* controls_darwin.m */
|
/* controls_darwin.m */
|
||||||
|
@ -44,4 +45,8 @@ extern void checkboxSetChecked(id, BOOL);
|
||||||
/* sizing_darwin.m */
|
/* sizing_darwin.m */
|
||||||
extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
|
extern void moveControl(id, intptr_t, intptr_t, intptr_t, intptr_t);
|
||||||
|
|
||||||
|
/* containers_darwin.m */
|
||||||
|
extern id newTab(void *);
|
||||||
|
extern id tabAppend(id, char *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,7 +35,7 @@ func newWindow(title string, width int, height int, control Control) *window {
|
||||||
w.container.beginResize = w.beginResize
|
w.container.beginResize = w.beginResize
|
||||||
C.windowSetDelegate(id, unsafe.Pointer(w))
|
C.windowSetDelegate(id, unsafe.Pointer(w))
|
||||||
w.child = control
|
w.child = control
|
||||||
w.child.setParent(w.id)
|
w.child.setParent(C.windowContentView(w.id))
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,11 @@ void windowClose(id win)
|
||||||
[toNSWindow(win) close];
|
[toNSWindow(win) close];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id windowContentView(id win)
|
||||||
|
{
|
||||||
|
return (id) [toNSWindow(win) contentView];
|
||||||
|
}
|
||||||
|
|
||||||
// fake a resize event under certain conditions; see each invocation for details
|
// fake a resize event under certain conditions; see each invocation for details
|
||||||
void windowRedraw(id win)
|
void windowRedraw(id win)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue